akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
using namespace std;

const int MAX_H = 11;
const int MAX_W = 21;

map<string, int> M;
vector<string> V;
int H, W;
char G[MAX_H][MAX_W];

bool compare(const string &a, const string &b) {
  if(a.size() != b.size()) return a.size() > b.size();
  return a < b;
}

string solve() {
  V.clear();
  M.clear();
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      for(int dx = -1; dx <= 1; ++dx) {
	for(int dy = -1; dy <= 1; ++dy) {
	  if(dx == 0 && dy == 0) continue;
	  int x = j;
	  int y = i;
	  string s = "";
	  do {
	    s += G[y][x];
	    if(s.size() >= 2 && ++M[s] == 2) {
	      V.push_back(s);
	    }
	    x = (x+dx+W)%W;
	    y = (y+dy+H)%H;
	  } while(!(x == j && y == i));
	}
      }
    }
  }
  if(V.size() == 0) return "0";
  sort(V.begin(), V.end(), compare);
  return V[0];
}

int main() {
  while(cin >> H >> W && (H | W)) {
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
	cin >> G[i][j];
      }
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 28000
N = int(input())
#N,K,M= map(int,input().split())
#A =list(map(int,input().split()))
#L = [list(map(str,input().split())) for i in range(N)]
keta = len(str(N))
answer = 0

k = 1
for i in range(1,N+1):
    k = 1
    if i % 10 == 0:
        continue
    #桁が１桁
    if str(i)[0] == str(i)[-1]:
        answer += 1
    #桁が２桁
    if int(str(i)[-1]+str(i)[0]) <= N:
        answer += 1
    k =3
    #桁が３桁から与えられたNの桁以下の時
    if k <= keta:
        flag = 10
        while k < keta:
            answer += flag
            k += 1
            flag *= 10
        #k と keta が同じとき
        if str(i)[-1] < str(N)[0]:
            answer += flag
        elif str(i)[-1] == str(N)[0]:
            #print(i)
            kake = ''
            for j in range(1,keta-1):
                kake += str(N)[j]
            #print(kake)
            if str(i)[0] <= str(N)[-1]:
                answer += (int(kake)+1)
            else:
                answer += max((int(kake)),0)
print(answer)


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

#define NDEBUG
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;


const int f753 = (1 << 7) | (1 << 5) | (1 << 3);

inline bool check(int x) {
    int f = 0;
    while (x) {
        int d = x % 10;
        f |= (1 << d);
        x /= 10;
    }
    return (f & f753) == f753;
}

int solve(int N) {
    vi base {0};

    int ans = 0;
    for (int k=1; k<=9; ++k) {
        vi b2;
        for (int x : base) {
            for (int d=3; d<=7; d+=2) {
                int y = 10*x + d;
                if (y <= N) {
                    if (check(y)) ++ans;
                    b2.pb(y);
                }
            }
        }
        base = b2;
    }
    return ans;
}

int main() {
    int N; cin >> N;
    cout << solve(N) << endl;
    return 0;
}


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

using namespace std;

int main() {

	int X;
	cin >> X;

	int thousand = X / 1000;

	int fiveH = (X - 1000 * thousand) / 500;

	int hundread = (X - 1000 * thousand - 500 * fiveH) / 100;

	int fifty = (X - 1000 * thousand - 500 * fiveH - 100 * hundread) / 50;

	int ten = (X - 1000 * thousand - 500 * fiveH - 100 * hundread - 50 * fifty) / 10;

	int five = (X - 1000 * thousand - 500 * fiveH - 100 * hundread - 50 * fifty - 10 * ten) / 5;

	cout << 1000 * (fiveH + 2 * thousand) + 5 * (five + hundread * 20 + fifty * 10 + ten * 2) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string.h>
using namespace std;

#define HUNDRED 100
#define THOUSAND 10000
#define TENTHOUSAND 10000
#define HUNDREDTHOUSAND 100000
#define ALPHABET 26

//int kaibun(int number);
int calc_area(int x, int y, int a, vector<vector<int>> &xy, int w, int h);

int main() {
	int w, h, n;
	vector<vector<int>> xy(HUNDRED + 1, vector<int>(HUNDRED + 1, 0));
	vector<int> a;
	vector<int> x_point;
	vector<int> y_point;
	int temp1, temp2, temp3;
	int total_area = 0;

	cin >> w >> h >> n;

	for (int i = 0; i < n; i++) {
		cin >> temp1 >> temp2 >> temp3;
		x_point.push_back(temp1);
		y_point.push_back(temp2);
		a.push_back(temp3);
	}

	for (int j = 0; j < n; j++) {
		total_area = calc_area(x_point[j], y_point[j], a[j], xy, w, h);
	}

	cout << w * h - total_area;

}

int calc_area(int x, int y, int a, vector<vector<int>> &xy, int w, int h) {
	int total_area = 0;

	switch (a) {
	case 1:
		for (int i = 1; i <= x; i++) {
			for (int j = 1; j <= h; j++) {
				xy[i][j] = 1;
			}
		}
		break;
	case 2:
		for (int i = x + 1; i <= w; i++) {
			for (int j = 1; j <= h; j++) {
				xy[i][j] = 1;
			}
		}
		break;
	case 3:
		for (int i = 1; i <= w; i++) {
			for (int j = 1; j <= y; j++) {
				xy[i][j] = 1;
			}
		}
		break;
	case 4:
		for (int i = 1; i <= w; i++) {
			for (int j = y + 1; j <= h; j++) {
				xy[i][j] = 1;
			}
		}
		break;
	}

	for (int k = 1; k <= w; k++) {
		for (int l = 1; l <= h; l++) {
			if (xy[k][l] == 1) {
				total_area++;
			}
		}
	}

	return total_area;
}


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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


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

	char l = s[0];
	int i;
	for (i = 1; i < s.size(); i++) {
		if (l!=s[i]) {
			break;
		}
	}
	int ret = s.size()-i;

	for (int j = i; j < s.size(); j++) {
		if (s[j]==s[j-1]) {
			ret--;
		}
	}
	cout << ret << "\n";

}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
"""
http://abc062.contest.atcoder.jp/tasks/arc074_a

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


def main(args):
    H, W = map(int, input().split())

    p1 = -1
    p2 = -1
    p3 = -1
    min_diff = H * W

    for i in range(1, (H//2)+1):
        p1 = i * W              #  横に割る
        reH = H - i
        # 残りを横に割った場合
        p2 = ceil(reH / 2) * W
        p3 = (H * W) - p1 - p2
        diff = max(p1, p2, p3) - min(p1, p2, p3)
        if diff < min_diff:
            min_diff = diff

        # 残りを縦に割った場合
        p2 = ceil(W / 2) * reH
        p3 = (H * W) - p1 - p2
        diff = max(p1, p2, p3) - min(p1, p2, p3)
        if diff < min_diff:
            min_diff = diff

    # HとWを入れ替えて同じ計算
    temp = H
    H = W
    W = temp
    for i in range(1, (H//2)+1):
        p1 = i * W              #  横に割る
        reH = H - i
        # 残りを横に割った場合
        p2 = ceil(reH / 2) * W
        p3 = (H * W) - p1 - p2
        diff = max(p1, p2, p3) - min(p1, p2, p3)
        if diff < min_diff:
            min_diff = diff

        # 残りを縦に割った場合
        p2 = ceil(W / 2) * reH
        p3 = (H * W) - p1 - p2
        diff = max(p1, p2, p3) - min(p1, p2, p3)
        if diff < min_diff:
            min_diff = diff

    print(min_diff)

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

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

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

    //I don't care about anybody, and fuck ratings! I'll go to google!
    priority_queue<ll> q;
    int n, m; cin>>n>>m;
    ll x, ans = 0;
    for(int i = 0; i<n; i++){
        cin>>x;
        q.push(x);
    }

    for(int i = 0; i<m; i++){
        x = q.top();
        q.pop();
        q.push(x/2);
    }

    while(!q.empty()){
        ans += q.top();
        q.pop();
    }
    cout<<ans<<"\n";
    return 0; 
}


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

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){

	i64 n, m;
	cin >> n >> m;
	vector<vector<pair<i64,i64>>> edges(n);
	for(i64 i = 0; i < m; ++i){
		i64 a, b, c;
		cin >> a >> b >> c;
		edges[--a].emplace_back(--b, c);
		edges[b].emplace_back(a, c);
	}
	vector<i64> v(n, INF);
	vector<i64> col(n, -1);

	i64 fl = INF;
	// flagが0なら加算、1なら減算
	function<void(i64,i64,bool)> f = [&](i64 pos, i64 val, bool flag){
		for(auto& ed : edges[pos]){
			i64 x = ed.first;
			i64 p = ed.second - val;
			if(col[x] != -1){
				// 二部グラフである形を保つなら
				if(col[x] == !flag){
					if(v[x] != p)
						fl = -INF;
				}else{
					// p + x == v[x] - x
					if(col[x]){
						i64 d = v[x] - p;
						fl = (d % 2 ? -INF : d / 2);
					}
					// v[x] + x = p - x
					else{
						i64 d = p - v[x];
						fl = (d % 2 ? -INF : d / 2);
					}
				}
			}
			else{
				col[x] = !flag;
				v[x] = p;
				f(x, p, !flag);
			}
		}
	};

	col[0] = 0;
	v[0] = 0;
	f(0, 0, 0);

	if(fl == -INF){
		cout << 0 << endl;
		return 0;
	}
	// 問題なく進んだ場合
	else if(fl == INF){
		i64 mi = INF, ma = INF;
		for(i64 i = 0; i < n; ++i){
			if(col[i]){
				ma = min(ma, v[i]);
			}else{
				mi = min(mi, v[i]);
			}
		}
		mi *= -1;
		cout << max(i64(0), ma - mi - 1) << endl;
	}
	// 非二部グラフな場合
	else{
		vector<i64> va(n, -INF);
		function<void(i64,i64,bool)> g = [&](i64 pos, i64 val, bool flag){
			for(auto& ed : edges[pos]){
				if(va[ed.first] == -INF){
					va[ed.first] = ed.second - val;
					g(ed.first, va[ed.first], !flag);
				}
			}
		};
		va[0] = fl;
		g(0, fl, 0);
		bool flag = *min_element(va.begin(), va.end()) > 0;
		for(int i = 0; i < n; ++i)
			for(auto& ed : edges[i])
				flag &= (va[i] + va[ed.first] == ed.second);

		cout << flag << endl;
	}
}


Measured memory_bytes: 18816
# encoding: utf-8
ab = [list(map(int, input().split())) for i in range(3)]

tab = [0] * 4
for ai, bi in ab:
    tab[ai - 1] += 1
    tab[bi - 1] += 1

if 0 in tab: print('NO')
elif 3 in tab: print('NO')
else: print('YES')

Measured memory_bytes: 3060
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

const long long mod = 1e9+7;
int prim[10005];

void PrimNumberScreen(){
	for(int i = 2; i < 1000; i++){
		if(prim[i]==false)
		for(int j = 2; i*j < 10000; j++){
			prim[i*j] = true;
		}
	}
}

void DecomposeMessFactor(int vist[],int n){
	int x = n;
	for(int i = 2; i <= n; i++){
		if(prim[x]==false){
			vist[x]++;
			break;
		}
		if(prim[i]==false&&x%i==0){
			while(x%i==0){
				x/=i;
				vist[i]++;
			}
		}
	}
}

void Init(int vist[],int N){
	for(int i = 0; i <= N; i++){
		vist[i] = 1;
	}
}
int main()
{
	int N,vist[1001];
	PrimNumberScreen();
	scanf("%d",&N);
	Init(vist,N);
	for(int i = 4; i <= N; i++){
		if(prim[i]==true){
			vist[i] = 0;
			DecomposeMessFactor(vist,i);
		}
	}
	long long ans = 1;
	for(int i = 2; i <= N; i++){
		if(vist[i]!=0){
			ans = ans*(vist[i]+1)%mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
	#include<string.h>
	int min(int a, int b);
	using namespace std;
	int main() {

		//A
		/*string str;
		cin >> str;

		if ((str == "AAA") || (str == "BBB")) {
			cout << "No";
		}else{
			cout << "Yes";
		}*/

		//B
		/*long long int n, a, b;
		cin >> n;
		cin >> a;
		cin >> b;

		cout << (long long int)(n / (a + b))* a + min(n % (a + b), a);
		*/

		//C
		int a, b;
		cin >> a;
		cin >> b;
		int i;
		for (i = 1; i <= 10000; i++) {
			if (((int)(i * 0.08) == a) && ((int)(i * 0.1) == b)) {
				cout << i;
				return 0;
			}
		}
		cout << -1;

	}

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

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

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

    ll cnt = 0;

    ll n; cin >> n;
    string s; cin >> s;

    int c[3] = {};
    rep(cand, 1000){
        c[0] = cand / 100;
        c[1] = (cand / 10) % 10;
        c[2] = cand % 10;
        // cout << c1 << c2 << c3 << endl;

        // cout << (int)'1' << endl;

        ll index = 0;
        rep(i, n){
            if(c[index] == (s[i] - 48)){
                index++;
                if(index == 3){
                    cnt++;
                    break;
                }
            }
        } 
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>

using namespace std;

int main(){
  int i, j, n, k, _s, b, check;
  vector<int> s;

  while(1){
    cin >> n >> k;
    if(n == 0 && k == 0) break;

    for(i=0; i<k; ++i){
      cin >> _s;
      s.push_back(_s);
    }

    check = 0;
    for(i=0; i<n; ++i){
      for(j=0; j<k; ++j){
	cin >> b;
	if(check == 0){
	  s[j] -= b;
	  if(s[j] < 0) check = 1;
	}
      }
    }

    if(check == 0)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;

    s.clear();
  }

  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <ctime>
using namespace std;

void solve()
{
    int N; cin>>N;
    vector<int> a(N);
    for (int i=0;i<N;++i) cin>>a[i];

    vector<int> b(N,0);
    int ans=0;
    for (int i=N-1;i>=0;--i){
        int sum=0;
        for(int j=i+1;j<=N;j+=i+1){
            if(b[j-1]==1) ++sum;
        }
        if(a[i]!=(sum%2)) b[i]=1,++ans;
    }

    cout<<ans<<endl;
    for(int i=0;i<N;++i){
        if(b[i]==1) cout<<i+1<<" ";
    }
    cout<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    // int ti = clock();
    // input();
    solve();
    // printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 4756
def solve(string):
    n, q, *abpx = map(int, string.split())
    t, c, d, check = [[] for i in range(n + 1)], [0] * (n + 1), [1], [1] * (n + 1)
    for a, b in zip(*[iter(abpx[:2 * n - 2])] * 2):
        t[a].append(b)
        t[b].append(a)
    for p, x in zip(*[iter(abpx[2 * n - 2:])] * 2):
        c[p] += x
    while len(d) > 0:
        curr = d.pop()
        check[curr] = 0
        next_ = [i for i in t[curr] if check[i]]
        for n_ in next_:
            c[n_] += c[curr]
        d.extend(next_)
    return " ".join([str(_c) for _c in c[1:]])


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n + m - 1)])))


Measured memory_bytes: 99892
#include<stdio.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

void run (void) {
  i32 n, k;
  scanf ("%" SCNi32 "%" SCNi32, &n, &k);
  i64 l = 0;
  i64 r = 1000000000000000000LL + 1;
  while (r - l > 1) {
    i64 m = (l + r) / 2;
    for (i32 i = 0; i < n && m >= 0; ++i) {
      m--;
      m -= m / k;
    }
    if (m < 0) {
      l = (l + r) / 2;
    } else {
      r = (l + r) / 2;
    }
  }
  printf ("%" PRIi64 "\n", l);
}

int main (void) {
  run();
  return 0;
}


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

const ll inf = 1e9+7;
ll N, K;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin >> N >> K;
    COMinit();
    for (ll i = 1; i <= K; i++) cout << ((COM(N-K+1, i)%MOD) *(COM(K-1, i-1)%MOD))%MOD << endl; 
    return 0;
}

Measured memory_bytes: 12160
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt();
        int[] x = new int[n];
        for(int i = 0;i<n;i++){
            x[i] = sc.nextInt();
        }
        int ans = 0;
        for(int i = 0;i<n;i++){
            if(x[i]<=Math.abs(k-x[i])){
                ans += 2*x[i];
            } else {
                ans += 2*Math.abs(k-x[i]);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
#include<stdio.h>
int main(void){
  char alf[30]={"abcdefghijklmnopqrstuvwxyz"},moji;
  scanf("%c",&moji);
  for(int i=0;i<30;i++){
    if(alf[i]==moji){
      printf("%c",alf[i+1]);
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, k, mnm=0;
    cin>>n>>k;
    int arr[k];
    for(int i=0; i<k; i++)
        cin>>arr[i];
    sort(arr, arr+k);
    mnm  = arr[k-1]-arr[0];
    for(int i=1; i<k; i++)
        mnm = min(mnm, n-arr[i]+arr[i-1]);
    cout<<mnm;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define forr(i,a,n) for(ll i=a;i<n;i++)
#define ford(i,a,n) for(ll i=n-1;i>=a;i--)
#define all(v) v.begin(),v.end()
#define testc  ll ts;\
               cin>>ts;\
               while(ts--)
#define arn ll n;\
            cin>>n;\
            ll a[n];\
            forr(i,0,n)cin>>a[i];\
               
#define arr(a,n) ll a[n];\
                 forr(i,0,n)cin>>a[i];\
 
#define sss <<" "<<
#define nnn <<"\n"
#define nl cout<<"\n";
#define prtitr(v) for(auto itr=v.begin(); itr!=v.end() ; itr++)cout<<*itr<<" ";
#define fitr(v) for(auto itr=v.begin(); itr!=v.end() ; itr++)
using namespace std;
ll M=1e9+7;
ll cdiv(ll a,ll b){
    return (a%b==0)?a/b:a/b+1;
}
ll myMod(ll a, ll b){
    ll r = a % b;
    return r < 0 ? r + b : r;
}
ll ModPow(ll a,ll b,ll M)
{
    if(M==1)return 0;
    a%=M;
    ll ans=1,t=1;
    while(t>0&&t<=b)
    {
        if(t&b)
        {
            ans*=a;
            ans%=M;
        }
        t<<=1;
        a*=a;
        a%=M;
    }
    return ans;
}


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    cin>>s>>t;
    if(s==t){
        cout<<0;
        return 0;
    }
    ll ans=0;
    forr(i,0,s.size()-t.size()+1){
        ll ctr=0;
        forr(j,0,t.size()){
            if(s[i+j]==t[j])ctr++;
        }
        ans=max(ans,ctr);
    }
    cout<<t.size()-ans;
    return 0;
} 

Measured memory_bytes: 3644
N = int(input())
A = list(map(int,input().split()))

dp= [[0,0] for _ in range(N+1)]
dp[0] = [0, -float("inf")]
#print(type(dp[0][0]))

for i in range(N):
  dp[i+1][0] = max(dp[i][0]+A[i], dp[i][1]-A[i])
  dp[i+1][1] = max(dp[i][0]-A[i], dp[i][1]+A[i])

print(dp[N][0])


Measured memory_bytes: 25604
N = int(input())
A = list(map(int, input().split()))
money = 1000
stock = 0
tmp = [0]*(N-1)

for i in range(N-1):
    if A[i] == A[i+1]:
        tmp[i] = 0
    else:
        if A[i] < A[i+1]:
            tmp[i] = 1
        else:
            tmp[i] = -1

for i in range(N-1):
    if tmp[i] == 1:
        money += A[i]*stock
        stock = 0
        stock += money//A[i]
        money -= A[i]*stock
    if tmp[i] == -1:
        money += A[i]*stock
        stock = 0
    if tmp[i] == 0:
        continue
    # print('day',i+1,':',money,',',stock)


print(money + stock*A[N-1])


Measured memory_bytes: 9228
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

const double EPS = 1e-8;

int main(){
	int H, W;
	string f[600];
	while(cin >> H >> W){
		for(int i=H-1;i>=0;i--) cin >> f[i];

		vector< pair<double, int> > vd;
		// ????????°??????????????????????????????.
		// ??????(j/i)?????§??????????????¨??????????????°????¢????????????£?????????
		for(int i=1;i<=H;i++){
			for(int j=0;j<=W;j++){
				int cnt = 0;
				for(int k=0;k<4;k++){
					int ni = i-k%2, nj = j-k/2;
					if(0<=ni&&ni<H&&0<=nj&&nj<W&&f[ni][nj]=='#') cnt++;
				}
				if(cnt%2 == 1){
					if(0<=i-1&&i-1<H&&0<=j&&j<W&&f[i-1][j]==(cnt==1?'#':'.'))
						vd.push_back(make_pair((double)j/i,  1));
					if(0<=i&&i<H&&0<=j-1&&j-1<W&&f[i][j-1]==(cnt==1?'#':'.'))
						vd.push_back(make_pair((double)j/i, -1));
				}
			}
		}
		sort(vd.begin(), vd.end());

		int res = 1, cur = 1;
		// ???????????§?????????????????????????????°????¢????????????????
		for(int i=0;i<vd.size(); ){
			int idx = i;
			while(idx < vd.size() && abs(vd[i].first-vd[idx].first) < EPS)
				cur += vd[idx++].second;
			i = idx;
			res = max(cur, res);
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1) 

const ll INF = 10010001010;
const int inf = 2000000000;


typedef tuple<string, int, int> TUP;

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

int main()
{
    int P,Q,R;
    cin >> P >> Q >> R;
    cout << min({P+Q,Q+R,P+R}) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back

using namespace std;

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

const int MAXN = 2e5 + 10;

int a, b;

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

	cin >> a >> b;
	
	if(a <= 5) cout << 0 << endl;
	else if(a >= 13) cout << b << endl;
	else cout << b/2 << endl;
}


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

int main(){

   string s;
   cin>>s;
   int c=0;
   for(int i=0;i<s.size()/2;i++)
   {
       if(s[i]==s[s.size()-i-1])
       continue;
       else
       c++;
   }
   cout<<c;
    
}

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

int main() {
	ll n;
	cin >> n;
	
	if(n&1) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	ll temp = n/2;

	while(temp > 0) {
		ans += temp/5;
		temp = temp/5;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 110
int main(){
    int n;
    int A[MAX];

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    for(int i=n-1;i>0;i--){
        printf("%d ", A[i]);
    }
    printf("%d\n",A[0]);
return 0;
}


Measured memory_bytes: 3216
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
//#include <tuple>
//#include <array>
//#include <random>
//#include <windows.h>
//#pragma comment(lib, "winmm.lib")

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

Measured memory_bytes: 384
n,k=map(int,input().split())
ans=0
lis=[0 for i in range(n)]
for i in range(k):
  d=int(input())
  ll=list(map(int,input().split()))
  #print(ll)
  for j in ll:
    lis[j-1]+=1
#print(lis)
for i in lis:
  if i==0:
    ans+=1
    
print(ans)

Measured memory_bytes: 9188
import fractions
A,B,C,D = map(int,input().split())
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

underA = (A-1) // C + (A-1) // D - (A-1) // int(lcm(C,D))
underB = B // C + B // D - B // lcm(C,D)
N = underB - underA
print(B-A+1-N)


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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" << " = " << a[i] << endl;
#define fastio ios_base::sync_with_stdio(false); \
			cin.tie(0);							 \
			cout.tie(0);
#define PI 3.141592654

using namespace std;

using ll = long long;
const int MOD = 998244353;
const ll INF = 1e18 + 9;

ll powmod(ll base, ll exp, const ll MOD) { ll ans = 1; while (exp) { if (exp & 1)	ans = (ans * base) % MOD; base = (base * base) % MOD; exp >>= 1; } return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
void add(ll& x, ll v) { x = (x + v) % MOD; if (x < 0) x += MOD; }
//ll f[500005];
//ll kCn(ll k, ll n) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }


void test_case() {
	
}


int main() {
	fastio;
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif // !ONLINE_JUDGE
	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	bitset<1000007> bs;
	bitset<1000007> ans;
	for (int i = 0; i < n; ++i) {
		if (bs[a[i]]) {
			ans[a[i]] = true;
			continue;
		}
		bs.set(a[i]);
		for (int j = 2* a[i]; j < 1000007; j += a[i]) {
			ans.set(j);
		}
	}

	int res = 0;
	for (int i = 0; i < n; ++i)
		res += (ans[a[i]] == false);

	cout << res;
	return 0;
}


Measured memory_bytes: 5048
import java.util.Scanner;

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

		int k = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());

		for (int i = 0; i < k * 2 - 1; i++) {
			System.out.print(i==0 ? "":" ");
			System.out.print(x - (k - 1) + i);
		}
	}
}


Measured memory_bytes: 22996
import java.util.*;
import java.io.*;
public class Main  {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
	 		StringTokenizer st = new StringTokenizer(bf.readLine());
	 		int n = Integer.parseInt(st.nextToken());
	 		int k = Integer.parseInt(st.nextToken());
	 		int count = 0;
 		while(n>0){
 			n/=k;
 			count++;
 		}
 		out.println(count);
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25380
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N, Y;

int dp[20000];

int main() {
    cin >> N >> Y;
    Y /= 1000;
    for (int j = 0; j <= N; ++j) {
        for (int k = 0; j+k <= N; ++k) {
            int l = N - j - k;
            if (j + 5 * k + 10 * l == Y) {
                cout << l << " " << k << " " << j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX 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 pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
//#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define ins insert
#define aer(v) (v).erase((v).begin(),(v).end()) 

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

main(){
	int a,b,c;cin>>a>>b>>c;
	if(a==b&&a==c)dump("Yes");
	else dump("No");
}






Measured memory_bytes: 256
import Data.Bits (xor, (.&.))
import qualified Data.ByteString.Char8 as BS
import Control.Monad (replicateM)

data Tree = Node Int Bool Int Tree Tree
          | Empty Int
          deriving (Show)

coloredChildren :: Tree -> Int
coloredChildren (Empty _) = 0
coloredChildren (Node _ _ n _ _) = n

goDown :: Int -> BS.ByteString -> Tree -> Tree
goDown h s (Empty _)
  | BS.length s == 0 || BS.head s == '\n' = Node h True 1 (Empty (h+1)) (Empty (h+1))
  | BS.head s == '0' = Node h False 1 (goDown (h+1) (BS.tail s) (Empty (h+1))) (Empty (h+1))
  | otherwise = Node h False 1 (Empty (h+1)) (goDown (h+1) (BS.tail s) (Empty (h+1)))
goDown h s t@(Node _ c d l r)
  | BS.length s == 0 || BS.head s == '\n' = Node h True (d+1) l r
  | BS.head s == '0' = let l' = goDown (h+1) (BS.tail s) l
                       in Node h c (coloredChildren l' + coloredChildren r + if c then 1 else 0) l' r
  | BS.head s == '1' = let r' = goDown (h+1) (BS.tail s) r
                       in Node h c (coloredChildren l + coloredChildren r' + if c then 1 else 0) l r'

grundy :: Int -> Tree -> Int
grundy he (Empty h)
  | h > he = 0
  | otherwise = let x = he - h + 1 in x .&. (-x)
grundy _ (Node _ True _ _ _) = 0 -- 根が使われている場合
grundy he (Node h _ _ l@(Node _ _ 0 _ _) r@(Node _ _ 0 _ _)) = let x = he - h + 1 in x .&. (-x)
grundy he (Node _ _ _ l r) = grundy he l `xor` grundy he r

main = do
  [n, l] <- fmap (map read . words) getLine
  ss <- replicateM n BS.getLine
  let t = foldr (goDown 0) (Empty 0) ss
      g = grundy l t
  putStrLn $ if g /= 0 then "Alice" else "Bob"


Measured memory_bytes: 13692
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String str = sc.next();
    String[] s = str.split("");
    int x = 0;
    int max = 0;
    String I = "I";
    String D = "D";
    for(int i = 0;i < n;i++){
      if(s[i].equals(I)){
        x = x+1;
        /*if(max <= x){
          max = x;
        }*/
      }
      else if(s[i].equals(D)){
        x = x-1;
        /*if(max <= x){
          max = x;
        }*/
      }
      if(max <= x){
        max = x;
      }
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>

#define lint long long

using namespace std;

lint N;

lint dfs(lint x, lint y,lint num) {
	num = num * 10 + y;
	if (num > N) return 0;
	
	lint tnum = num;
	lint tmp = num;
	lint s3 = 0, s5 = 0, s7 = 0;
	while (1) {
		if (tmp <= 0) break;
		tmp = tmp / 10 * 10;
		lint tmp_num = tnum - tmp;
		if (tmp_num == 3) s3++;
		else if (tmp_num == 5) s5++;
		else if (tmp_num == 7) s7++;
		tmp /= 10;
		tnum /= 10;
	}

	if (s3 > 0 && s5 > 0 && s7 > 0) {
		return dfs(++x, 3, num) + dfs(++x, 5, num) + dfs(++x, 7, num)+1;
	}
	else {
		return dfs(++x, 3, num) + dfs(++x, 5, num) + dfs(++x, 7, num);
	}
}

int main() {
	cin >> N;
	lint count = dfs(0, 3, 0) + dfs(0, 5, 0) + dfs(0, 7, 0);
	cout << count << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Text.RegularExpressions;
using static MyIO;


public class B
{
	public static void Main()
	{
		int N = GetInt();
		int numEven = 0;
		for(int i = 0; i < N; i++)
			if(GetInt() % 2 == 0)
				numEven++;
		Console.WriteLine(Math.Pow(3, N) - (1 << numEven));
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


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

using namespace std;

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

  // input 1
  int n, m;
  cin >> n >> m;
  vector<vector<int>> ms(m);
  // input 2
  for (int i = 0; i < m; ++i) {
    int x;
    cin >> x;
    for (int j = 0; j < x; ++j) {
      int y;
      cin >> y;
      ms[i].push_back(y - 1);
    }
  }
  // input 3
  vector<int> p(m);
  for (int i = 0; i < m; ++i) {
    cin >> p[i];
  }

  int ans = 0;
  for (int i = 0; i < (1 << n); ++i) {
    bool ok = true;
    for (int j = 0; j < m; ++j) {
      int x = 0;
      for (int k : ms[j]) {
        if ((i >> k) & 1) {
          x ^= 1;
        }
      }
      if (x != p[j]) {
        ok = false;
      }
    }
    if (ok) {
      ++ans;
    }
  }
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	int n; cin>>n;
	vi ts(n);
	repi(i,1,n) cin>>ts[i];
	
	vector<vvi> dp(2,vvi(n+1,vi(2,INFTY))); // [i][j][k]:[0,i)に0がj個あり，最後にkを使った場合のコスト
	dp[0][0][0]=0;
	rep(i,n-1) rep(j,n){
			dp[i+1&1][j+1][0]=min(dp[i&1][j][0],dp[i&1][j][1]+ts[i]);
			dp[i+1&1][j][1]=min(dp[i&1][j][0]+ts[i],dp[i&1][j][1]);
			dp[i&1][j][0]=dp[i&1][j][1]=INFTY;
	}
	cout<<dp[n-1&1][n/2][1]<<endl;
	
	return 0;
}

Measured memory_bytes: 2604
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.end()
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;

const int mod = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;

signed main(){
    int n , m;
    cin >> n >> m;
    vector < vector < bool > > q(n , vector < bool > (m));



    queue < pair < int , pair < int , int > > > p;
    char ch;
    for(int i = 0 ; i < n ; ++i){
        for(int j = 0 ; j < m ; ++j){
            cin >> ch;
            if(ch == '#'){
                q[i][j] = 1;
                p.push({0 , {i , j}});
            }
        }
    }
    int ans = 0;
    vector < pair < int , int > > step = {
        {1 , 0},
        {-1 , 0},
        {0 , 1},
        {0 , -1}
    };
    while(!p.empty()){
        pair < int , int > head;
        pair < int , pair < int , int > > obj;
        obj = p.front() , p.pop();
        head = obj.se;
        ans = obj.fi;
        for(auto &i : step){
            if(head.fi + i.fi >= 0 && head.fi + i.fi < n && head.se + i.se >= 0 && head.se + i.se < m && !q[head.fi + i.fi][head.se+i.se]){
                q[head.fi+i.fi][head.se+i.se] = 1;
                p.push({obj.fi+1 , {head.fi + i.fi , head.se + i.se}});
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 12560
#include<iostream>
#include<string.h>
using namespace std;
int main(){
  int n;
  string a;
  cin>>n;
  cin>>a;
  if(a.size()<=n){
  	cout<<a<<"\n";
  }
  else{
  	cout<<a.substr(0,n)<<"..."<<"\n";
  }
return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <vector>

using namespace std;


int main(void){
	long long int n, k;

	cin >> n >> k;

	vector<long long int> num(100001, 0);

	int a, b;
	for (int i = 0; i < n; i++){
		cin >> a >> b;

		num[a] += b;
	}

	long long int sum = 0;
	for (int i = 1; i <= 100001; i++){
		sum += num[i];
		if (k <= sum){
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 1024
from operator import itemgetter

N = int(input())
job = [list(map(int, input().split())) for i in range(N)]

job.sort(key = itemgetter(1))

time = 0
flag = 0
for i in range(N):
    time += job[i][0]
    if time > job[i][1]:
        flag = 1    
    
if flag == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 53732
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char now[1<<16], *S, *T;
  if(S == T) {T = (S = now) + fread(now, 1, 1<<16, stdin); if(S == T) return EOF;}
  return *S++;
}
inline int read() {
  int x;
  cin>>x;
  return x;
}
struct Query {int l, r, id;}q[500010];
int a[500010], pos[1000010], las[500010], BIT[500010], ans[500010];
int n, m;
inline bool cmp(Query A, Query B) {return A.r < B.r;}
inline void add(int x, int v) {for(; x <= n; x+= x & -x) BIT[x]+= v;}
inline int query(int x) {int ret = 0; for(; x; x-= x & -x) ret+= BIT[x]; return ret;}
int main() {
  ios::sync_with_stdio(false);
  n = read(); m = read();
  for(int i = 1; i <= n; ++i) a[i] = read();
  for(int i = 1; i <= n; ++i) las[i] = pos[a[i]], pos[a[i]] = i;

  for(int i = 1; i <= m; ++i) {q[i].l = read(); q[i].r = read(); q[i].id = i;}
  sort(q+1, q+m+1, cmp); int cur = 0;
  for(int i = 1; i <= m; ++i) {
    while(cur < q[i].r) {
      ++cur;
      add(cur, 1); if(las[cur]) add(las[cur], -1);
    }
    ans[q[i].id] = query(q[i].r) - query(q[i].l - 1);
  }
  for(int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
  return 0;
}


Measured memory_bytes: 19380
#include<iostream>
#include<cmath>
using namespace std;
int main(){

  int e,min;
  int y,x;
  
  while(1){
    cin >>e;
    if(e == 0)break;

    min =1e9;
    for(int i=0 ; i*i*i <= e ; i++){
      y=sqrt(e-i*i*i);
      x=e-y*y-i*i*i;
      if(x+y+i < min)min=x+y+i;
    }
    
    cout <<min<<endl;
    
  }
    
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<ll> a(n+1),b(n);
	rep(i,n+1) cin>>a[i];
	rep(i,n) cin>>b[i];
	ll ans=0;
	rep(i,n){
		if(a[i]<=b[i]){
			ans+=a[i];
			b[i]-=a[i];
			ans+=min(b[i],a[i+1]);
			a[i+1]=max(0ll,a[i+1]-b[i]);
		}else{
			ans+=b[i];
		}
	}
	cout<<ans<<endl;
}

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

int main() {
    int N; long long L; cin >> N >> L;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    int pl = -1;
    for (int i = 0; i+1 < N; ++i) if (A[i] + A[i+1] >= L) pl = i;

    if (pl == -1) { cout << "Impossible" << endl; return 0; }

    cout << "Possible" << endl;
    for (int i = 0; i < pl; ++i) cout << i+1 << endl;
    for (int i = N-2; i > pl; --i) cout << i+1 << endl;
    cout << pl+1 << endl;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<ll>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define el printf("\n")
#define pb push_back
#define f first
#define s second
#define arrondi(a) (long long)floor(a+0.5);
#define NIL -1
ll N=500005;
ll MAX=9223372036854775807;
ll MOD=1000000007;
long double PI =4*atan(1);

int main()
{
    int n; cin >> n ;
    ll a,b; vector<ll> A(n,0);vector <pair<ll,ll> >ans;
    for (int i=0;i<n;i++)
    {
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    ll rep1=A[0],rep2=A[n-1];
    for (int i=1;i<n-1;i++)
    {
        if (A[i]<0)
        {
            ans.pb(make_pair(rep2,A[i]));
            rep2-=A[i];
        }
        else
        {
            ans.pb(make_pair(rep1,A[i]));
            rep1-=A[i];
        }
    }
    ans.pb(make_pair(rep2,rep1));
    cout << rep2-rep1 << "\n";
    for (int i=0;i<ans.size();i++)
    {
        cout << ans[i].f << " " << ans[i].s << "\n";
    }
    return 0;
}


Measured memory_bytes: 4336
#include <cstdio>
#include <cmath>

#define PI 3.1415926535898
#define ANGLE (PI/180.0)
int main(){
	int step,dir;
	double x=0.0, y=0.0, angle=0.0;
	
	while(1){
		scanf("%d,%d", &step, &dir);
		if(step==0 && dir==0) break;
		x += (double)(step) * sin( angle*ANGLE );
		y += (double)(step) * cos( angle*ANGLE );
		angle += (double)dir;
	}
	printf("%d\n%d\n", (int)x, (int)y);
}

Measured memory_bytes: 0
import Data.Bool
import Data.Char
main=mapM_ print.solve=<<readLn
solve k=take k$map fst$iterate f (1,1)
f(i,d)=(a,bool d(d*10)$d*s b<b)where(a,b)=(i+d,i+d*2)
s=sum.map digitToInt.show

Measured memory_bytes: 4644
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <utility>

using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  int it,len;
  char s[LEN + 5];
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(it == LEN) fwrite(s,1,LEN,stdout), it = 0;
    s[it++] = c;
  }
  void flush(){
    fwrite(s,1,it,stdout);
  }
}buff,bufo;
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get()) res = res * 10 + (c - '0');
  return sig * res;
}
inline void putint(int x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[15];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline void putll(ll x,char suf){
  if(!x) bufo.put('0');
  else{
    if(x < 0) bufo.put('-'), x = -x;
    int k = 0; char s[25];
    while(x){
      s[++k] = x % 10 + '0';
      x /= 10;
    }
    for(;k;k--) bufo.put(s[k]);
  }
  bufo.put(suf);
}
inline char get_char(){
  char c;
  for(c = buff.get();c == ' ' || c == '\n';c = buff.get());
  return c;
}
bool cp(int x){
  if(x == 1) return false;
  for(int i = 2;i * i <= x;i++){
    if(x % i == 0) return false;
  }
  return true;
}
int main(){
  int x = getint();
  for(;!cp(x);x++);
  putint(x,'\n');
  bufo.flush();
  return 0;
}


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

int main(){
    int n; cin>>n;
    int bin = 1;
    while(n > 1){
        n /= 2;
        bin *= 2;
    }
    cout << bin << endl;
}

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

int main(){
  long long N;
  cin >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  map<long long, long long> M;
  for(int i=0;i<N;i++) M[A[i]]++;
  
  long long base = 0;
  for(int i=1;i<=N;i++){
    if(M[i]!=0){
      base += M[i]*(M[i]-1)/2;
    }
  }
  
  for(int k=0;k<N;k++){
    long long ans = base;
    if(M[A[k]]>=2){
      ans += (M[A[k]]-1)*(M[A[k]]-2)/2;
      ans -= M[A[k]]*(M[A[k]]-1)/2;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 16640