akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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

	int K, N;
	cin >> K >> N;

	int A[200000];
	rep(i, N) cin >> A[i];


	int saidai = K + A[0] - A[N - 1];
	rep(i, N - 1) chmax(saidai, A[i + 1] - A[i]);

	co(K - saidai);

	Would you please return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

import sys
from scipy.sparse.csgraph import floyd_warshall

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M, L = MAP()
G = list2d(N, N, INF)
for i in range(M):
    a, b, c = MAP()
    a -= 1
    b -= 1
    G[a][b] = c
    G[b][a] = c

res = floyd_warshall(G)

G2 = list2d(N, N, INF)
for i in range(N):
    for j in range(i, N):
        # 最短距離がL以下の2点なら燃料1回で行ける
        if res[i][j] <= L:
            G2[i][j] = 1
            G2[j][i] = 1

# 燃料使用回数をコストとした最短経路
res2 = floyd_warshall(G2)

for i in range(INT()):
    a, b = MAP()
    a -= 1
    b -= 1
    ans = res2[a][b]
    if ans != INF:
        print(ans-1)
    else:
        print(-1)


Measured memory_bytes: 19704
import sys
import collections

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

X = rl()
X.sort()
bool = any(x%2==0 for x in X)
print(0 if bool else X[0] * X[1])


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			int r = sc.nextInt();
			if(n == 0 && r == 0) {
				break;
			}
			int[] a = new int[n];
			for(int i=0; i<n; i++) {
				a[i] = n - i;
			}
			for(int i=0; i<r; i++) {
				int p = sc.nextInt();
				int c = sc.nextInt();
				int[] b = new int[p];

				for(int j=0; j<p-1; j++) {
					b[j] = a[j];
				}
				for(int j=0; j<c; j++) {
					a[j] = a[p+j-1];
				}
				for(int j=0; j<p-1; j++) {
					a[j+c] = b[j];
				}
			}
			System.out.println(a[0]);
		}
		sc.close();
	}
}

Measured memory_bytes: 30200
import math
D, G = list(map(int, input().split()))
p, c, s = [0]*D, [0]*D, [0]*D

for i in range(D):
    p[i], c[i] = list(map(int, input().split()))
    s[i] = 100*(i+1)

slv = [[0], [1]]
for i in range(D-1):
    slv = list(map(lambda x: x+[0], slv)) + list(map(lambda x: x+[1], slv))
memo = []
ans = 10**10 # 比較対象
for si in slv:
    score, cnt = 0, 0
    for i, toku in enumerate(si):
        if toku ==1:
            cnt += p[i]
            score += c[i] + p[i]*100*(i+1)
    if score >= G and cnt <= ans:
        ans = cnt
    memo.append((score, cnt, si))

leqG = []
for m in memo:
    if m[0] < G:
        leqG.append(m)

ans_cand = 10**10
for l in leqG:
    for i, t in enumerate(l[2][::-1]):
        index = len(l[2])-i-1
        if t == 0:
            if l[0]+p[index]*(index+1)*100 >= G:
                ans_tmp = l[1] + min(math.ceil((G-l[0])/((index+1)*100)), p[index])
                ans_cand = min(ans_cand, ans_tmp)
            break
print(min(ans, ans_cand))

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

using namespace std;

const int N_MAX = 200005;

int n;
int lg, ans;

int h[N_MAX];

int main() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
    }
    lg = 1;
    ans = 1;
    for (int i = 2; i <= n; ++i) {
        if (h[i] <= h[i - 1]) {
            ++lg;
        } else {
            lg = 1;
        }
        ans = max(ans, lg);
    }
    cout << ans - 1;
    return 0;
}


Measured memory_bytes: 640
n = int(input())
a = list(map(int,input().split()))
b = []
t = 0

for i in a:
  if i%2 ==0:
    b.append(i)
    
for i in b:
  if i%3 == 0 or i%5 == 0:
    t += 1
    
if t== len(b):
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 3060
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

const int max_size = 10000 + 334;

inline void chmax(string &s1, string s2){
  if (s1 == "!") s1 = s2;
  else if (s1.size() < s2.size()) s1 = s2;
  else if (s1.size() == s2.size()){
    if (s1 < s2) s1 = s2;
  }
}

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

  int n, m; cin >> n >> m;
  vector<int> v(m); rep(i, m) cin >> v[i];
  int match[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};

  string dp[max_size];
  fill(dp, dp + max_size, "!");
  dp[0] = "";

  for (int i = 0; i <= n; ++i){
    if (dp[i] == "!") continue;
    for (auto x : v){
      chmax(dp[i + match[x - 1]], dp[i] + (char) ('0' + x));
    }
  }

  print(dp[n]);

  return 0;
}


Measured memory_bytes: 44928
import bisect

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()

ans = 0
C = len(c)

# Bを中心に考える
for i in b:
    ans += (bisect.bisect_right(a,i-1))*(C-bisect.bisect_left(c,i+1))

print(ans)

Measured memory_bytes: 29580
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

bool check(vector<pi> comp, vector<pi> target){
  if(comp.size()!=target.size())return false;
  for(int z=0;z<2;z++){
    for(int i=0;i<4;i++){
      bool ok=true;
      int x=target[0].first-comp[0].first;
      int y=target[0].second-comp[0].second;
      for(int j=0;j<(int)comp.size();j++){
	if(comp[j].first+x!=target[j].first||comp[j].second+y!=target[j].second){
	  ok=false;
	}
	int tmp=-target[j].first;
	target[j].first=target[j].second;
	target[j].second=tmp;
      }
      if(ok)return true;
    }
    reverse(all(target));
  }
  return false;
}

void solve(int n){
  int m;
  cin>>m;
  vector<pi> comp(m);
  rep(i,m){
    cin>>comp[i].first>>comp[i].second;
  }
  
  rep(i,n){
    cin>>m;
    vector<pi> diff(m);
    rep(j,m){
      cin>>diff[j].first>>diff[j].second;
    }
    if(check(comp,diff))cout<<i+1<<endl;
  }
  
}

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    solve(n);
    cout<<"+++++"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3100
function main(arg) {
    let [x,k,d]= arg.split(" ").map(Number)

    let dir = x > 0 ? 1 : -1
    let t = parseInt(x*dir/d)
    let a = x - t*d*dir
    k = k - t
    //console.log(`parseInt(x/d)=${t} , x=${x}, k=${k}`)
    if(t > k) {
        //console.log(1)
        console.log(Math.abs(x-(k+t)*d*dir))
    } else {
        //console.log(`k=${k}, t=${t}, d=${d}, a=${a}`)
        console.log(k%2 ? Math.abs(a-d*dir) : Math.abs(a))
    }
    
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(void) {
    int N;
    cin >> N;
    vector<ll> a(N);
    int cnt;
    ll fac, memofac;
    int memocnt;
    int sum = 0;
    for (int i=0; i<N; i++) cin >> a[i];
    for (int i=0; i<N; i++) {
        cnt = 0;
        while(a[i] % 2 == 0) {
            memocnt = 1;
            fac = 2;
            while(true) {
                memofac = fac;
                fac = fac * fac;
                if(a[i] % fac != 0) break;
                memocnt *= 2;
            }
            a[i] /= memofac;
            cnt += memocnt;
        }
        sum += cnt;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
  
  
namespace io{
    const int L = (1 << 20) + 1;
     
    char buf[L], *S , *T, c;
      
    char getchar() {
        if(S == T) {
            T = (S = buf) + fread(buf, 1, L, stdin);
            return (S == T ? EOF : *S++);
        }
        return *S++;
    }
     
    int inp() {
        int x = 0, f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    ll inp_ll() {
        ll x = 0; int f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    char B[25], *outs=B+20, *outr=B+20;
    template<class T>
    inline void print(register T a,register char x=0){
        if(x) *--outs = x, x = 0;
         
        if(!a)*--outs = '0';
        else
            while(a)
                *--outs = (a % 10) + 48, a /= 10;
         
        if(x)
            *--outs = x;
         
        fwrite(outs, outr - outs , 1, stdout);
        outs = outr;
    }
};
  
using io :: print;
using io :: inp;
using io :: inp_ll;
const int maxN = 510;
const int maxM = 20;
int H,W;
int a[maxN][maxN];
int ansx[maxN * maxN];
int ansy[maxN * maxN];

int main()
{
	scanf("%d %d",&H,&W);
	for(int i=1;i<=H;i++)
	{
		for(int j = 1;j<=W;j++)
			scanf("%d",&a[i][j]);
	}
	int p = 0;
	for(int i=1;i<= H;i++)
	{
		for(int j = 1;j<= W;j++)
		{
			if(i==H && j == W) continue;
			if(a[i][j] % 2 == 1)
			{
				++p;
				ansx[p] = i;
				ansy[p] = j;
				if(j==W)
				{
					a[i+1][j] ++;
				}
				else
				{
					a[i][j+1]++;
				}
			}
			
		}
	}
	printf("%d\n",p);
	for(int i=1;i<=p;i++)
	{
		int k = 0;
		if(ansy[i] == W)
		{
			printf("%d %d %d %d\n",ansx[i],ansy[i],ansx[i]+1,ansy[i]);
		}
		else
		{
			printf("%d %d %d %d\n",ansx[i],ansy[i],ansx[i],ansy[i]+1);
		}
		
	}
    return 0;
}

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

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

    long long table[n] = {};

    for(int i = 0; i < n; i++) table[a[i] - 1]++;

    long long res = 0;
    for(int i = 0; i < n; i++) {
        res += table[i] * (table[i] - 1) / 2;
    }

    /*
    for(int i = 0; i < n; i++) {
        cout << table[i] << ' ';
    }
    cout << endl << res << endl << "===" << endl;
    */
    

    for(int i = 0; i < n; i++) {
        long long ans;
        ans = res - (table[a[i]-1] - 1);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 4992
import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)

N, Q, *ABPX = map(int, open(0).read().split())
AB, PX = ABPX[:2 * (N - 1)], ABPX[2 * (N - 1):]

E = [[] for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].append(b)
    E[b].append(a)

ans = [0] * (N + 1)
for p, x in zip(*[iter(PX)] * 2):
    ans[p] += x

def dfs(v, p):
    for c in E[v]:
        if c == p:
            continue
        ans[c] += ans[v]
        dfs(c, v)

dfs(1, 0)

print(*ans[1:])

Measured memory_bytes: 251188
/*
 _    _    _______   _    _
| |  / /  |  _____| | |  / /
| | / /   | |       | | / /
| |/ /    | |_____  | |/ /
| |\ \    |  _____| | |\ \
| | \ \   | |       | | \ \
| |  \ \  | |_____  | |  \ \
|_|   \_\ |_______| |_|   \_\

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek

const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 2e6 + 6;

string s;
int cnt[33];
ll ans;

int main() {

    cin >> s;
    int n = sz(s);

    forn(i, 0, n - 1) {
        ans += i - cnt[s[i] - 'a'];
        cnt[s[i] - 'a']++;
    }

    cout << ans + 1 << "\n";

	return 0;
}


Measured memory_bytes: 640
def up2words str
  low2words(str)[1..-1]
end

def low2words str
  str.gsub! /([A-Z])/, '*\1'
  str.split(?*).map &:downcase
end

def under2wods str
  str.split ?_
end

def what_case str
  return ?D if str.include? ?_
  return ?U if str[0] =~ /[A-Z]/
  return ?L
end

def words2up words
  words.map(&:capitalize).join
end

def words2low words
  result = words2up(words)
  result[0] = result[0].downcase
  result
end

def words2under words
  words.join ?_
end

$<.each do |line|
  str, rule = line.chomp.split
  break if rule == ?X
  str_rule = what_case str
  words = case str_rule
          when ?U
            up2words str
          when ?L
            low2words str
          when ?D
            under2wods str
          end
  result = case rule
           when ?U
             words2up words
           when ?L
             words2low words
           when ?D
             words2under words
           end
  puts result
end

Measured memory_bytes: 6128
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main()
{
	int n, a, b;
	cin >> n >> a  >> b;
	if (b > n * a) {
		cout << n * a << endl;
	}
	else {
		cout << b << endl;
	}

    return 0;
}

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

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll; 
typedef long double ld; 
typedef vector<int> vi; 
typedef pair<int,int> pii; 
#define pb push_back
#define mp make_pair
#define prarr(a,n) cerr<<#a<<" : ";for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define prmat(mat,row,col) cerr<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<"\t";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
template <class T> void prall(T a) { prc(all(a)); }
const int inf=1000*1000*1000+9; 
const ll infl=1ll*inf*inf; 
const int mod=1000*1000*1000+7;  

// ----------------------------------------------------------------------------	-------------- 


const int nax=1e5+5; 
vector<pii> adj[nax];
int deg[nax];

int digs(ll n){
  int ret=0; 
  while(n>0) {
    ret++; 
    n/=10; 
  }
  return ret; 
}

void solve(){
  int n; cin>>n;
  string s; cin>>s; 
  for(char c:s){
    c+=n; 
    if(c>'Z') c-=26; 
    cout<<c; 
  }
}



int main(){
	// clock_t beg=clock(); 
	fast_io; 
  // cout << fixed << setprecision(13); 
  int t; 
  t=1; 
  //cin>>t; 
  while(t--){
	  solve(); 	
  }
	// clock_t end=clock(); 
	// fprintf(stderr, "%lf\n", (double)(end-beg)/(CLOCKS_PER_SEC));
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007

int main(){
    int h,w;
    cin >> h>>w;
    vector< vector <int>> d(h, vector<int>(w,0));
    int n;
    cin>>n;
    vector<int64_t> a(n);
    rep(i,n){
        cin>>a[i];
    }
    bool up=false,down=true;
    int t=0,y=0;
    int color=0;
    while(d[0][w-1]==0||d[h-1][w-1]==0){
        while(a[color]>=1){
        d[t][y] =  color+1;
        //cout << "d["<<t<<"]["<<y<<"]="<<d[t][y]<< endl;
        a[color] --;
        if(t==h-1&&down){//下まで行った
            down=false;
            up=true;
            y++;
            continue;
        }
        else if(t==0 && y!=0&&up){//上まで行った
            down=true;
            up=false;
            y++;
            continue;
        }
        if(down){
            t++;
        }
        if(up){
            t--;
        }
        }
        //全部塗り切った
        color++; 
    }
    rep(i,h){
        rep(j,w){
            cout <<d[i][j]<<" ";
        }
        cout <<endl;
    }

}

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

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

    int ab = abs(a - b);
    int bc = abs(b - c);
    int ac = abs(a - c);

    int Max;
    Max = max(ab, max(bc, ac));

    int ans;
    ans = ab + bc + ac - Max;

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using treap = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
    {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
    {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
    {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
    #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
    #define dump(...)
    #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(nullptr); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
    int n; cin >> n;
    vector<int> b(n);
    REP (i, n) {
        int a; cin >> a;
        a--;
        b[a] = i;
    }
    int ans = 0;
    multiset<int> s = {-1, -1, n, n};
    for (int i = n - 1; i >= 0; i--) {
        s.insert(b[i]);
        auto it = s.find(b[i]);
        int l1 = *prev(it);
        int l2 = *prev(prev(it));
        int r1 = *next(it);
        int r2 = *next(next(it));
        ans += (i + 1) * ((b[i] - l1) * (r2 - r1) + (r1 - b[i]) * (l1 - l2));
    }
    cout << ans << endl;
}


Measured memory_bytes: 5760
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra(){
    int minv;
    int d[MAX], color[MAX];

    for(int i=0; i<n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0;
    color[0] = GRAY;
    while(1){
        minv = INFTY;
        int u = -1;
        for(int i=0; i<n; i++){
            if(minv > d[i] && color[i] != BLACK){
                u = i;
                minv = d[i];
            }
        }
        if(u == -1) break;
        color[u] = BLACK;
        for(int v=0; v<n; v++){
            if(color[v] != BLACK && M[u][v] != INFTY){
                if(d[v] > d[u] + M[u][v]){
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

    for(int i=0; i<n; i++){
        cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
    }
}

int main(){
    cin >> n;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            M[i][j] = INFTY;
        }
    }

    int k, c, u, v;
    for(int i=0; i<n; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v >> c;
            M[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}


Measured memory_bytes: 3120
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 
 using namespace std;
 
 int abs(int m)
 {
   if(m<0) return -m;
   else return m;    
 }
 
 int main()
 {
   int n;
   while(cin>>n)
   {
     int num;
     int arr[100000+5]={0};
     int a,b;
     if(2==n)
     {
       cin>>a>>b;        
     }
     else
     {
       for(int i=0;i<n;i++) 
       {
         cin>>num;
         arr[num]++;        
       }
     }            
     if(1==n) cout<<"1"<<endl;
     else if(2==n)
     {
       if(abs(a-b)>2) cout<<"1"<<endl;
       else cout<<"2"<<endl;     
     } 
     else
     {
       int result=0;
       for(int i=0;i<(100000);i++)
       {
         if(result<(arr[i]+arr[i+1]+arr[i+2]))
         {
           result=arr[i]+arr[i+1]+arr[i+2];                                     
         }          
       }    
       cout<<result<<endl;
     }
   } 
   return 0;    
 }
 
 
 
 

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

void Main() {
  int n, m;
  cin >> n >> m;
  if (n == m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		List <Integer> H = new ArrayList <Integer> ();
		List <Integer> W = new ArrayList <Integer> ();
		
		int lastH = 0;
		int lastW = 0;
		do {
			lastH = stdIn.nextInt();
			lastW = stdIn.nextInt();
			
			H.add(lastH);
			W.add(lastW);
		} while (lastH != 0 || lastW != 0);
		
		for(int i = 0; i < H.size()-1; i++) {
			for(int j = 0; j < H.get(i); j++) {
				if(j == 0 || j == H.get(i) - 1) {
					for(int k = 0; k < W.get(i); k++) {
						System.out.print("#");
					}
				}
				else {
					System.out.print("#");
					for(int k = 0; k < W.get(i) - 2; k++) {
						System.out.print(".");
					}
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}

}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010, M = 13;

int n, m;
int a[N];
int p[N];

int find(int x)
{
	if (x != p[x]) p[x] = find(p[x]);
	return p[x];
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i ++ ) scanf("%d", a + i);
	for (int i = 0; i < N; i ++ ) p[i] = i;
	
	while (m -- )
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a = find(a), b = find(b);
		p[a] = b;
	}
	
	int res = 0;
	for (int i = 1; i <= n; i ++ )
	{
		int pa = find(i), pb = find(a[i]);
		if (pa == pb) res ++ ;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 1024
start = Time.now
D = gets.to_i
@c = gets.split.map(&:to_i)
@s = Array.new D
D.times do |i|
  @s[i] = gets.split.map(&:to_i)
end

t = Array.new D
score = 0
last = Array.new 26, 0
D.times do |i|
  best = -99999999999
  res = nil
  base_c = 0
  26.times do |t|
    base_c += (i - last[t] + 1) * @c[t]
  end
  
  26.times do |t|
    diff = @s[i][t]
    diff -= base_c
    diff += @c[t] * (i - last[t] + 1)

    if diff > best
      best = diff
      res = t
    end
  end
  score +=  best
  last[res] = i + 1
  t[i] = res
end

@q = Array.new
def calc_pena t
  kei = Array.new(26, (1+D)*D/2)
  last = Array.new(26, 0)
  t.each_with_index do |_t, i|
    kei[_t] -= (i+1 - last[_t]) * (D - i)
    last[_t] = i + 1
  end
  res = 0
  26.times do |i|
    res += kei[i] * @c[i]
  end
  res
end
pena = calc_pena(t)
base_score = score + pena
while(Time.now - start < 1.9) do
  d = rand(D)
  old = t[d]
  rep = rand(26)
  new_t = t.dup
  new_t[d] = rep
  new_base_score = base_score - @s[d][old] + @s[d][rep]
  new_pena = calc_pena(new_t)
  if new_base_score - new_pena > base_score - pena
    warn "A"
    t = new_t
    base_score = new_base_score
    pena = new_pena
  end
  # score = score - @s[d][old] + @s[d][rep] + calc_pena_diff(d,old,rep)
  # warn score
  # warn "---"
end
t.each do |_t|
  puts _t + 1
end

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

city = [0] * (2 * N + 3)
city[0] = 1
arriedCity = {1}
secondArrivedCity = set()

hantei = False
roopHazimari = 0
cnt = 0
for i in range(1, len(city)):
    if i == K:
        city[i] = A[city[i - 1] - 1]
        hantei = True
        break

    if A[city[i - 1] - 1] in arriedCity:
        if cnt == 0:
            roopHazimari = i
        if A[city[i - 1] - 1] in secondArrivedCity:
            city[i] = A[city[i - 1] - 1]
            break
        cnt += 1
        secondArrivedCity.add(A[city[i - 1] - 1])
        city[i] = A[city[i - 1] - 1]
    else:
        city[i] = A[city[i - 1] - 1]
        arriedCity.add(A[city[i - 1] - 1])
# print(city)
if hantei:
    print(city[K])
else:
    temp = (K - roopHazimari) % cnt
    print(city[roopHazimari + temp])


Measured memory_bytes: 35592
#include <bits/stdc++.h>
#define lli long long int
using namespace std;

 
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	string s, ss = "";
	
	cin >> s;
	
	sort(s.begin(), s.end());
	
	if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) cout << "Yes" << "\n";
	else cout << "No" << "\n";
	
	
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n;
	cin >> n;
	map<int, int> mp;
	rep (i, n) {
	  int a;
	  cin >> a;
	  if (mp[a] != 0) {
		cout << "NO" << endl;
		return 0;
	  }
	  mp[a]++;
	}
	cout << "YES" << endl;
    
    return 0;
}



Measured memory_bytes: 12992
#include<bits/stdc++.h>
using namespace std;
int main() {
	char a;
	cin >> a;
	if (a == 'a') {
		cout << "vowel" << endl;
	}
	else if (a == 'i') {
		cout << "vowel" << endl;
	}
	else if (a == 'u') {
		cout << "vowel" << endl;
	}
	else if (a == 'e') {
		cout << "vowel" << endl;
	}
	else if (a == 'o') {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>

using namespace std;

char s[101];

int main() {
    int n, r = 0, b = 0, i;
    
    scanf("%d", &n);
    scanf("%s", s);
    
    for (i = 0; i < n; i++) {
        if (s[i] == 'R') {
            r++;
        } else {
            b++;
        }
    }
    
    if (r > b) {
        puts("Yes");
    } else {
        puts("No");
    }
    
    return 0;
}


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

vector<int> graph[200009];
int visited[200009]={0};

void dfs(int x, int& nodes){
  visited[x]=1;
  nodes++;
  for(int a: graph[x]){
    if(!visited[a])
      dfs(a,nodes);
  }
}
   
int main()
{
  int n,m;
  scanf("%d%d", &n,&m);
  while(m--){
    int x,y;
    scanf("%d%d", &x,&y);
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  int ans=0;
  for(int a=1;a<=n;a++){
    if(!visited[a]){
	      int nodes=0;
	      dfs(a,nodes);
	      ans=max(ans,nodes);
	    }
	}
  printf("%d",ans);
}
    

Measured memory_bytes: 24808
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> T;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define MP make_pair
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

using Graph = vector<vector<pair<int, int>>>;
using vvec = vector<vector<int>>;
using vec = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int h;
    cin>>h;
    int memo=1;
    int ans=0;

    while(h!=0){

        ans+=memo;
        memo*=2;

        h/=2;
    }
    cout<<ans<<endl;
}

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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int h = sc.NextInt();
        int w = sc.NextInt();

        char[,] map = new char[h, w];
        for (int i = 0; i < h; i++)
        {
            string str = sc.Next();
            for (int j = 0; j < w; j++)
            {
                map[i, j] = str[j];
            }
        }

        List<int> removeH = new List<int>();
        List<int> removeW = new List<int>();

        for (int i = 0; i < h; i++)
        {
            bool remove = true;
            for (int j = 0; j < w; j++)
            {
                if (map[i, j] == '#')
                {
                    remove = false;
                    break;
                }
            }
            if (remove)
            {
                removeH.Add(i);
            }
        }

        for (int i = 0; i < w; i++)
        {
            bool remove = true;
            for (int j = 0; j < h; j++)
            {
                if (map[j, i] == '#')
                {
                    remove = false;
                    break;
                }
            }
            if (remove)
            {
                removeW.Add(i);
            }
        }

        for (int i = 0; i < h; i++)
        {
            string str = "";
            for (int j = 0; j < w; j++)
            {
                if (!removeH.Contains(i) && !removeW.Contains(j))
                {
                    str += map[i, j].ToString();
                }
            }
            if (!string.IsNullOrEmpty(str))
            {
                Console.WriteLine(str);
            }
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7  ))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
#define endl '\n'
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi;




	
int32_t main()
{
	IOS
	int n , k ; cin >> n >> k ;
	int r1 = n%k;
	int r2 = k - r1;
	cout << min( r1 , r2 ) << endl;
}




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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n,a,b; scanf("%d%d%d",&n,&a,&b);
	printf("%d %d\n",min(a,b),max(a+b-n,0));
	return 0;
}


Measured memory_bytes: 3736
N = int(input())
A = list(map(int, input().split()))
indexedA = []
for i in range(0, N):
	indexedA.append([i, A[i]])
indexedA.sort(key = lambda v: v[1])
m1 = indexedA[N//2-1][1]
m2 = indexedA[N//2][1]
anslist = []
for i in range(0, N):
	if i < N//2:
		anslist.append([indexedA[i][0], m2])
	else:
		anslist.append([indexedA[i][0], m1])
anslist.sort(key = lambda v: v[0])
for i in range(0, N):
	print(anslist[i][1])

Measured memory_bytes: 125780
import java.util.*;
public class Main {
	public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int a = scan.nextInt();
	int b = scan.nextInt();
	int c = scan.nextInt();
	
	if(a < b&&b < c){
		
		System.out.println("Yes");	
	}
	else System.out.println("No");
	}
}			

Measured memory_bytes: 17160
#169A
#A×Bを整数として出力せよ。

#やること①入力を受け取ること
a, b = map(int, input().split())
# print(a, b)

#やること②受け取った値を使って、適切に処理する
answer = a * b

#やること③計算した結果を出力すること
print(answer)

Measured memory_bytes: 9124
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef pair<ll, double> pld;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const ll INF = 1e18;
const int MAX_N = 1;

set<pld> candis;
vi ans;

ll S(ll x) {
  ll res = 0;
  while (x > 0) {
    res += x % 10;
    x /= 10;
  }
  return res;
}

void init() {
  for (int i = 1; i < 1000; i++) {
    for (int j = 0; j < 14; j++) {
      ll tmp = i;
      for (int k = 0; k < j; k++) {
        tmp *= 10;
        tmp += 9;
      }
      candis.insert(mp(tmp, (double)tmp/S(tmp)));
    }
  }

  double mn = INF;
  for (set<pld>::reverse_iterator it = candis.rbegin(); it != candis.rend(); ++it) {
    if (it->ss <= mn) {
      mn = it->ss;
      ans.pb(it->ff);
    }
  }
  reverse(ans.begin(), ans.end());
}

int main() {
  ll K; cin >> K;
  init();
  for (int i = 0; i < K; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long q = (b/c)-((a-1)/c);
	//	System.out.println(q);
	//	System.out.println(count);
//		if(q==1 && c<a) {
//			q=q-1;
//		}
//		else {
//			q=q;
//		}

		long r = (b/d)-((a-1)/d);
	//	System.out.println(r);
//		if(r==1 && d<a) {
//			r=r-1;
//		}
//		else {
//			r=r;
//		}
		long lcm = (c*d)/gcd(c,d);
		long s = (b/lcm)-((a-1)/lcm);
	//	System.out.println(s);
//		if(s==1 && lcm<a) {
//			s=s-1;
//		}
//		else {
//			s=s;
//		}
		//System.out.println(s);
		System.out.println((b-a+1)-(q+r-s));

	}
	public static long gcd(long a, long b) {
		if(b==0) {
			return a;
		}
		else {
			return gcd(b,a%b);
		}
	}

}


Measured memory_bytes: 23764
#include <stdio.h>

void con(long int a,long int x){
    long int s;
    long int q;

    s = a/x;
    q = a%x;

    printf("%c",'a'+s);

    if(x != 1)
        con(q,x/26);
}

void ans(long int a,long int x){

    if(a > x)
        ans(a-x,x*26);
    else {
        con(a-1,x/26);
    }
}

int main(){

    long int n;

    scanf("%ld",&n);

    ans(n,26);

    printf("\n");


    return 0;
}

Measured memory_bytes: 1724
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			if(n == 0)
			{
				break;
			}
			for(int i = 0; i < n; ++i)
			{
				int pm = stdIn.nextInt();
				int pe = stdIn.nextInt();
				int pj = stdIn.nextInt();
				if(pm == 100 || pe == 100 || pj == 100 || (pm + pe >= 180) || (pm + pe + pj >= 240))
				{
					System.out.println("A");
				}
				else if((pm + pe + pj >= 210) || (pm + pe + pj >= 150 && (pm >= 80 || pe >= 80)))
				{
					System.out.println("B");
				}
				else
				{
					System.out.println("C");
				}
			}
		}
	}
}

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

const int N = 1e5 + 5;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int n;
int a[N], op[N];
long long dp[N][20];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++ i) {
		if (i) {
			char c[5]; scanf("%s", c);
			op[i] = (c[0] == '-' ? -1 : 1);
		}
		scanf("%d", &a[i]);
	}
	memset(dp, -inf, sizeof(dp));
	dp[0][0] = a[0];
	for (int i = 1; i < n; ++ i) {
		for (int j = 0; j < 20; ++ j) {
			if (j && op[i] < 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + (j & 1 ? -1 : 1) * a[i]);
			dp[i][j] = max(dp[i][j], dp[i - 1][j] + (j & 1 ? -op[i] : op[i]) * a[i]);
			if (j < 19) dp[i][j] = max(dp[i][j], dp[i - 1][j + 1] + (j & 1 ? op[i] : -op[i]) * a[i]);
		}
	}
	printf("%lld\n", dp[n - 1][0]);
	return 0;
}

Measured memory_bytes: 16640
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

char c[101][101];
char cT[201][101];

int main()
{
  int h, w;
  cin >> h >> w;

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> c[i][j];
    }
  }
  for (int i = 1; i <= 2 * h; i++) {
    for (int j = 1; j <= w; j++) {
      cT[i][j] = c[(i + 1) / 2][j];
      if (j == w) cout << cT[i][j] << endl;
      else        cout << cT[i][j];
    }
  }

  // for (int i = 1; i <= 2 * h; i++) {
  //   for (int j = 1; j <= w; j++) {
  //     if (j == w) cout << cT[i][j] << endl;
  //     else        cout << cT[i][j];
  //   }
  // }
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <map>

using namespace std;

int main()
{
    int no_of_elements, M;
    scanf("%d %d", &no_of_elements, &M);

    vector <int> A(no_of_elements + 1, 0);
    for(int i = 1; i <= no_of_elements; i++)
        scanf("%d", &A[i]);

    vector <long long> sum(no_of_elements + 1, 0);
    for(int i = 1; i <= no_of_elements; i++)
        sum[i] = sum[i - 1] + A[i];

    long long good_pairs = 0;
    map <long long, int> frequency_mod;

    for(int i = 0; i <= no_of_elements; i++)
    {
        good_pairs += frequency_mod[sum[i]%M];

        frequency_mod[sum[i]%M]++;
    }

    printf("%lld\n", good_pairs);
    return 0;
}


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

struct UnionFind {
	vector<int> parent;
	
	UnionFind(int n){
		parent.resize(n);
		for (int i = 0; i < n; i++){
			parent[i] = i;
		}
	}
	
	int find(int x){
		if (parent[x] == x) return x;
		return parent[x] = find(parent[x]);
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}
	
	bool unite(int x, int y){
		x = find(x);
		y = find(y);
		if (x == y) return false;
		parent[x] = y;
		return true;
	}
};

int n, m;

int main()
{
	while (scanf("%d %d", &n, &m), n){
		bool res = true;
		
		UnionFind uf(n);
		vector<int> deg(n, 0);
		
		for (int i = 0; i < m; i++){
			int u, v;
			scanf("%d %d", &u, &v);
			if (!uf.unite(--u, --v)){
				res = false;
			}
			if (++deg[u] >= 3) res = false;
			if (++deg[v] >= 3) res = false;
		}
		
		puts(res ? "yes" : "no");
	}
}

Measured memory_bytes: 1792
S = input()
T = input()

if len(S)==len(T):
    count=0
    for i in range(len(T)):
        if T[i] != S[i]:
            count+=1
    print(count)

else:
    countbox=[]
    for n in range(len(S)-len(T)+1):
        count =0
        for i in range(len(T)):
            if T[i] != S[i+n]:
                count+=1
        countbox.append(count)
    print(min(countbox))

Measured memory_bytes: 8892
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	
	while(true)
	{
		c-=b;
		if(c <= 0)
		{
			printf("Yes\n");
			return 0;
		}
		a-=d;
		if(a <= 0)
		{
			printf("No\n");
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3652
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as BS
main=do
 [n,h]<-map read.words<$>getLine
 ab<-replicateM n (map (read.BS.unpack).BS.words<$>BS.getLine)
 print(f ((reverse.sort) ab) h)
  where f ab h = g (head(head ab)) ((reverse.sort) (map last ab)) h 0
        g a b h i |h<=0 = i
                  |b==[] = i+(quot(a+h-1)a)
                  |(head b)>a = g a (tail b) (h-(head b)) (i+1)
                  |otherwise = i+(quot(a+h-1)a)

Measured memory_bytes: 72060