akhauriyash/Code-Regression huggingface dataset:
A, B, C, K = map(int, input().split())

if K % 2 == 0:
    if abs(A-B) > 10**18:
        print("Unfair")
    else:
        print(A-B)
        
else:
    if abs(B-A) > 10**18:
        print("Unfair")
    else:
        print(B-A)

Measured memory_bytes: 9120
#include<iostream>
#include<vector>
#include<limits>
using namespace std;
typedef long ll;
int main() { 
    ll n, k;
    cin >> n >> k;
    vector<ll> nums(n);
    for(auto&e:nums)
        cin >> e;

    vector<ll> dp(n, numeric_limits<ll>::max());

    dp[0] = 0;

    for(ll i=0; i < n; i++) { 
        for(int j=1; j <= k; j++)
            if(i + j < n)
                dp[i+j] = min(dp[i+j], dp[i] + abs(nums[i]-nums[i+j]));
        }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 4428
#include<stdio.h>
#define N 8

void printBoard(void);
int putQueen(int);

int A[N];
int row[N],col[N],dpos[2*N],dneg[2*N];

int main(){
  int i;
  int k,r,c;

  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    A[r]=c;
    row[c]=1;
    col[r]=1;
    dpos[r+c]=1;
    dneg[r-c+N-1]=1;
  }
  putQueen(0); 
  return 0;
}
void printBoard(void){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(A[i]==j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
int putQueen(int i){
  int j;
  if(i==N){
    printBoard();
    return 1;
  }
  if(col[i]){
    if(putQueen(i+1)){
      return 1;
    }
  }

  for(j=0;j<N;j++){
    if(row[j]==1 || col[i]==1 || dpos[i+j]==1 ||dneg[i-j+N-1]==1) continue;
    row[j]=1;
    dpos[i+j]=1;
    dneg[i-j+N-1]=1;
    A[i]=j;
    if(putQueen(i+1)) return 1;
    row[j]=0;
    dpos[i+j]=0;
    dneg[i-j+N-1]=0;
  }
  return 0;
}



Measured memory_bytes: 2112
s = gets.chomp.to_s.split(//)
n = s.size
ary = Array.new(n + 1, 0)

i = 0
while i < n
  if s[i] == "<"
    ary[i+1] = ary[i] + 1
  end
  i += 1
end

i = n - 1

while i >= 0
  if s[i] == ">"
    ary[i] = [ary[i+1] + 1, ary[i]].max
  end
  i -= 1
end

puts ary.inject(:+)

Measured memory_bytes: 49412
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18+1;
#define DIV 1000000007
vector<ll> counter(2000001);

void countup(unordered_map<ll, vector<ll>>& tree, ll prev, ll next)
{
    counter[next] += counter[prev];
    for(auto elem:tree[next])
    {
		if(elem==prev)continue;
		countup(tree, next, elem);
	}
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long idx=0;
    long N,Q;
    cin >> N >> Q;
    unordered_map<ll, vector<ll>> tree;
    for(size_t i=1;i<=N-1; i++)
    {
        ll a,b;
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    for(size_t i=0;i<Q; i++)
    {
        long p, x;
        cin >> p >> x;
        counter[p] += x;
    }
    countup(tree, 0L, 1L);
    for(size_t i=1;i<=N; i++)
    {
        cout << counter[i] << " ";
    }
    cout << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 48200
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

int main(){
  ll x;
  cin >> x;
  ll a = x/500;
  ll b = (x%500)/5;
  cout << a*1000+b*5 << endl;
}


Measured memory_bytes: 256
func readInt() -> Int {
    return Int(readLine()!)!
}

func mainB() {
    let n = readInt()
    let bottoms = (0..<n).map { _ in readInt() }

    var flashBotton = 1
    var count = 0
    while true {
        count += 1
        flashBotton = bottoms[flashBotton - 1]
        if flashBotton == 2 {
            print(count)
            return
        }

        if count > 2 * n {
            print(-1)
            return
        }
    }
}

mainB()

Measured memory_bytes: 8132
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

vec dy = {0, 1, 0, -1};
vec dx = {1, 0, -1, 0};

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

    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    Rep (i, H) {
        cin >> S[i];
    }

    ll ans = 0;

    Rep (i, H) {
        Rep (j, W) {
            if (S[i][j] == '#') continue;
            mat d(H, vec(W, inf));
            d[i][j] = 0;
            queue<pair<ll, ll>> q;
            q.push({i, j});
            while (!q.empty()) {
                auto e = q.front();
                q.pop();
                ll y = e.first;
                ll x = e.second;
                Rep (k, 4) {
                    ll ny = y + dy[k];
                    ll nx = x + dx[k];
                    if (0 <= ny && ny < H && 0 <= nx && nx < W && d[ny][nx] == inf && S[ny][nx] == '.') {
                        d[ny][nx] = d[y][x] + 1;
                        q.push({ny, nx});                        
                    }
                }
            }

            ll tmp = 0;
            Rep (k, H) {
                Rep (l, W) {
                    
                    if (d[k][l] < inf) chmax(tmp, d[k][l]);
                }
            }

            chmax(ans, tmp);
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int w, h, n;
	cin >> w >> h >> n;
	int l = 0, r = w, d = 0, u = h;
	rep(i,n){
		int x, y, a;
		cin >> x >> y >> a;
		if(a == 1) chmax(l, x);
		if(a == 2) chmin(r, x);
		if(a == 3) chmax(d, y);
		if(a == 4) chmin(u, y); 
	}
	int ans = max(r-l, 0) * max(u-d, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

MOD = 10**9+7
n,k = get_all_int()

ans = 0

for m in range(k, n+2):
    # m個選ぶ最小値
    a = (m-1) * m // 2

    # m個選ぶ最大値
    b = (n+(n-m+1)) * m // 2
    
    ans += b-a+1

print(ans % MOD)


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

using namespace std;

int main() {
  int n;
  cin >> n;

  const int m = 55556;
  vector<bool> primes(m, true);
  primes[0] = primes[1] = false;
  for (int i = 2; i * i < m; i++) {
    if (!primes[i]) continue;
    for (int j = i + i; j < m; j += i) {
      primes[j] = false;
    }
  }
  vector<int> ans;
  for (int i = 2; ans.size() < n; i++) {
    if (primes[i]) {
      if (i % 5 == 1) {
        ans.emplace_back(i);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;

  return 0;
}

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

int main() {
    int n; cin >> n;
    map<int, int> a;
    rep(i, n) {
        int b;
        cin >> b;
        a[b] = i+1;
    }
    for (auto p : a) {
        auto k = p.first;
        auto v = p.second;
        cout << v << " ";
    }
}

Measured memory_bytes: 5504
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
  int x,n[101],i=0;
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      n[i-1]+=n[i];
      i--;
    } else if ( s[0] == '-' ){
 n[i-1]-=n[i];
      i--;
    } else if ( s[0] == '*' ){
      n[i-1]*=n[i];
      i--;
    } else {
      x = atoi(s);
      i++;
      n[i] = x;

      
      
    }
  }
  printf("%d\n",n[1]);
  return 0;
}

Measured memory_bytes: 548
import itertools
n,m=map(int,input().split())
L=[]
for i in range(m):
  a,*l=map(int,input().split())
  L+=[l]
S=list(map(int,input().split()))
ans=0
for i in itertools.product([0,1], repeat=n):
  f=0
  for l,s in zip(L,S):
    ls=0
    for ll in l:
      ls+=i[ll-1]
    if ls%2==s:
      f+=1
  if f==m:
    ans+=1
print(ans)

Measured memory_bytes: 41456
N = int(input())
ansDict = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}
for i in range(N):
    s = input()
    ansDict[s] = ansDict[s] + 1

print("AC x {}".format(ansDict["AC"] or 0))
print("WA x {}".format(ansDict["WA"] or 0))
print("TLE x {}".format(ansDict["TLE"] or 0))
print("RE x {}".format(ansDict["RE"] or 0))


Measured memory_bytes: 9188
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;


int main(){
    int a,b;
    cin >> a >>b;
    if (a % 2 != 0 && b % 2 != 0)cout << "Yes" << endl;
    else cout << "No" << endl;
  
    return 0;
}

Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i): is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    n = II()
    aa = MII()
    aa.sort()
    DIV = 10**9+7
    if n%2==1:
        bb = [0]
        for i in range(2,n,2):
            bb.append(i)
            bb.append(i)
    else:
        bb = []
        for i in range(1,n,2):
            bb.append(i)
            bb.append(i)
    if aa != bb:
        print(0)
        return None

    if n==1: print(1)
    elif n==2: print(2)
    elif n==3: print(2)
    else: print((2**(n//2))%DIV)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14424
import java.util.Scanner;

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

			//入力と同時に文字列を配列arrayに初期化 
			char[] array = scanner.nextLine().toCharArray();
			
			//arrayの要素数繰り返す
			for(char a : array) {
				
				//小文字変換
				if(Character.isUpperCase(a)) {
					
					System.out.print(Character.toLowerCase(a));
				
				//小文字変換
				}else {
					
					System.out.print(Character.toUpperCase(a));			
				}

			}

			System.out.println();		//行送り

	}
}




Measured memory_bytes: 26612
/*
Problem : https://atcoder.jp/contests/abc145/tasks/abc145_e
Algorithm :dp
Status :
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const int MAXN = 3005;

int n,T,ans;
int f[MAXN][MAXN];
pair<int,int> a[MAXN];

signed main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	scanf("%lld%lld",&n,&T);
	for(int i = 1;i <= n;i++)
	    scanf("%lld%lld",&a[i].first,&a[i].second);
	sort(a + 1,a + 1 + n);
	for(int i = 1;i <= n;i++){
		for(int j = 0;j < T;j++){
			ans = max(ans,f[i - 1][j] + a[i].second);
			f[i][j] = f[i - 1][j];
			if(j >= a[i].first)
			    f[i][j] = max(f[i][j],f[i - 1][j - a[i].first] + a[i].second);
		}
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

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

void Main() {
  Cin(string, s);
  stack<char> st;

  int ans = 0;
  rep(i, sz(s)) {
    if (!st.empty()) {
      if (st.top() != s[i]) {
        ans += 2;
        st.pop();
      } else {
        st.push(s[i]);
      }
    } else {
      st.push(s[i]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int n = inp.nextInt();
        int a = inp.nextInt();
        inp.close();
        if (n % 500 <= a) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 21716
#include<stdio.h>
#define MAX 100
#define INFTY 1000000000
#define WHITE 0
#define BLACK 1
int M[MAX][MAX];
int color[MAX];
int d[MAX];
int n,cnt;

void trace(int A[],int n){
    int i;
    for(i=0;i<n;i++){
	printf("%d: %d\n",i,A[i]);
    }
    printf("\n");
}

int prim(){
    int sum,cnt,minv;
    int u;
    int i,j;

    sum=cnt=0;

    d[0]=0;
    color[0]=BLACK;
    cnt++;

    u=0;
    while(cnt<n){
	for(i=0;i<n;i++){
	    if(M[u][i]<d[i]) d[i]=M[u][i];
	}

//	printf("%d\n",u);
//	trace(d,n);
	
	minv=INFTY;

	for(i=0;i<n;i++){
	    if(d[i]<minv && color[i]!=BLACK){
		u=i;
		minv=d[i];
	    }
	}
	
	sum+=minv;
	color[u]=BLACK;
	cnt++;
    }
    return sum;
}

int main(void){
    int i,j;
    int t,ans=0;

    scanf("%d",&n);
    for(i=0;i<n;i++){
	for(j=0;j<n;j++){
	    scanf("%d",&t);
	    M[i][j]=( (t==-1) ? (INFTY):(t) );
	}
    }

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

    ans=prim();
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <cassert>
#include <fstream>

using namespace std;

int main() {
    string s;
    cin >> s;
    int n = (int)s.length();
    int cntp = 0, cntg = 0;
    for (int i = 0; i < n; ++i)
        if (s[i] == 'p')
            ++cntp;
        else
            ++cntg;
    int cntop = n / 2;
    int cntog = n - cntop;
    cntop -= cntp;
    cout << cntop << endl;
}

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

int main(){
	
	int n;
	cin>>n;
	map<ll,ll>mp1,mp2;
	while(n--){
		ll x,y;
		cin>>x>>y;
		mp1[x+y]++;
		mp2[x-y]++;
	}
	ll res=abs(mp1.rbegin()->first-mp1.begin()->first);
	res=max(res,abs(mp2.rbegin()->first-mp2.begin()->first));
	cout<<res<<endl;
	return 0;
}


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

int main () {
  string s;
  cin >> s;
  vector <bool> check (26);
  
  for (int i = 0; i < 26; i++){
   check.at(i) = false;
  }
  for (int i = 0; i < s.size(); i++){
    check.at(s.at(i)-'a') = true;
  }
  for (int i = 0; i < 26; i++){
    if (!check.at(i)) {
      printf ("%c\n", char('a' + i));
      break;
    }
    if (i == 25) cout << "None" << endl;
  }
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int stick[N];
  for(int i=0; i<N; i++)cin >> stick[i];
  
  int max = 0;
  sort(stick,stick+N,greater<int>());

  for(int i=0; i<K; i++){
    max += stick[i];
  }
  
  cout << max << endl;
}

Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 基本はdouble
//map<キー,値> p は辞書。p[キー] = 値
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,N) for(int i = 0; i < N;i++)
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}   // 


int main() {
	string S; cin >> S;
	int N = S.length();

	rep(i, N) {
		if (i != (N - 1) / 2 && S[i] != S[N - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}	
	}

	rep(i, (N - 1) / 2 - 1) {
		if (S[i] != S[(N - 1) / 2 - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	for (int i = (N+3)/2-1; i <N; i++) {
		if (S[i] != S[(3 * N - 1) / 2 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    string arange;
    
    cin >> arange;
    
    int right_edge = arange.size() - 1;
    long long move_sum = 0;

    while(right_edge > 0 && arange[right_edge] == 'B'){
        right_edge -= 1;
    }

    for(int i = right_edge; i >= 0; i--){
        if(arange[i] == 'B'){
            move_sum += right_edge - i;
            right_edge -= 1;
        }
    }

    cout << move_sum << endl;
}

Measured memory_bytes: 640
import sys

input = sys.stdin.readline

N = int(input())
h = list(map(int, (input().split())))

dp = [None] * N

dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    dp[i] = min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]))

print(dp[N-1])


Measured memory_bytes: 14016
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long unsigned int ll;
 
int main() {
 
  int a,b;
  cin >> a;
  cin >>b;
  
  if(a*b%3==0){
    cout << "Possible" << endl;
  }else if((a+b)%3==0){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
  
   return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() { ll x; cin >> x; return x; }
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

vector<int> to[2505];
vector<int> rto[2505];
bool reachablefrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v) {
  if (reachablefrom1[v]) return;
  reachablefrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}
void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}

int main() {
  string s;
  cin >> s;
  if (s.compare("Sunny") == 0) {
    cout << "Cloudy" << endl;
    return 0;
  }
  if (s.compare("Cloudy") == 0) {
    cout << "Rainy" << endl;
    return 0;
  }
  if (s.compare("Rainy") == 0) {
    cout << "Sunny" << endl;
    return 0;
  }
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  int N;cin>>N;
  int FS[N][5][2];
  int PS[N][11];
  REP(i,N) {
    REP(j,5) {
      REP(k,2) {
        cin>>FS[i][j][k];
      }
    }
  }
  REP(i,N) {
    REP(j,11) {
      cin>>PS[i][j];
    }
  }
  // それぞれの曜日・時間を見ていって、出した場合のプラマイを計算していく
  // 出した日付の全探索だと、2**10なので、いける（0を除く）
  // 全てのパターンでの最大値
  int ans = INT_MIN;
  for (int bit=1;bit<pow(2,10);bit++) {
    VECINT same_cnt(N);
    // 出す日付のidx。0が月曜日の午前、9が金曜日の午後
    for (int shift=0;shift<10;shift++) {
      if ((bit & 1<<shift)==0) continue;

      // その時間帯で出している店でだけインクリメント
      int date_idx = shift/2;
      int time_idx = shift%2;
      REP(i,N) {
        if (FS[i][date_idx][time_idx]) same_cnt[i]++;
      }
    }
    int tmp = 0;
    REP(i,N) {
      tmp += PS[i][same_cnt[i]];
    }
    ans = max(ans,tmp);
  }
  OUT(ans);

  return 0;
}

Measured memory_bytes: 256
def execute(h, w, c):
    result = []
    for ci in c:
        result.append(ci)
        result.append(ci)
    return result


if __name__ == '__main__':
    h, w = map(int, input().split())
    c = []
    for _ in range(h):
        c.append(input())
    for ci in execute(h, w, c):
        print(ci)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;
 
int main()
{
    int N; cin >> N;
    string S; cin >> S;
    int alp[26] = {0};
    int ans = 0, ANS = 0;
    for (int i = 1; i < N; i++)
    {
        ans = 0;
        for (int j = 0; j < 26; j++)
        {
            alp[j] = 0;
        }
        for (int j = 0; j < i; j++)
        {
            alp[S[j]-'a']++;
        }
        for (int j = i; j < N; j++)
        {
            if(alp[S[j]-'a']!=0) ans++;
            alp[S[j]-'a'] = 0;
        }
        ANS = max(ans,ANS);
    }
    cout << ANS << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a,b,c;
	
	scanf("%d %d %d",&a,&b,&c);
	if(a>=b){
		if(a>=c){
			printf("%d",c*b/2);
		}else{
			printf("%d",a*b/2);
		}
	}else if(b>=c){
		printf("%d",a*c/2);
	}else{
		printf("%d",a*b/2);
	}
	return 0;
}

	

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

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

    int length_N = (int) N.size();
    vector<vector<vector<long long>>> dp(length_N + 5,vector<vector<long long>>(4,vector<long long>(2,0)));

    dp[0][0][0] = 1;
    for(int i = 0; i < length_N; i++)
    {
        for(int j = 0; j < 4; j++)
        {
            for(int k = 0; k < 2; k++)
            {
                int nd = N[i] - '0';//見る桁の値を取得
                for(int d = 0; d < 10; d++)
                {
                    int ni = i+1;
                    int nj = j;
                    int nk = k;
                    if(d != 0)nj++;
                    if(nj > K) continue;
                    if(k == 0)
                    {
                        if(d > nd)continue;
                        if(d < nd)nk = 1;
                    }
                    dp[ni][nj][nk] += dp[i][j][k];
                }
            }
            
        }
    }
    int ans = dp[length_N][K][0] + dp[length_N][K][1];
    cout << ans <<endl;
    cin>>N;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    ll n,k;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i,n) cin >> v[i];
    ll right = 0;
    ll all = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        right = 0;
        all  = 0;
        for(int j = i+1 ;j < n; j ++){
            if(v[i] > v[j]) right++;
        }
        for(int j = 0; j < n ; j ++){
            if(v[i] > v[j]) all++;
        }
        ans += right * k % MOD;
        ans %= MOD;
        ans += k*(k-1)/2 %MOD * all % MOD;
        ans %= MOD;
    }
    /*
    ll ans = 0 ;
    ans += right * k % MOD;
    ans += k*(k-1)/2 %MOD * all % MOD;
    ans %= MOD;*/
    cout << ans << endl;
    return 0;
}

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

template <typename T>
T inverse(T a, T m) {
    T u = 0, v = 1;
    while (a != 0) {
        T t = m / a;
        m -= t * a; swap(a, m);
        u -= t * v; swap(u, v);
    }
    assert(m == 1);
    return u;
}
#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
    using u64 = std::uint_fast64_t;

public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};
int main() {
    using Mint = modint<998244353>;
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<vector<int>>> g(3, vector<vector<int>>(n));
    for (int r = 0; r < 3; r++) {
        int m;
        cin >> m;
        for (int i = 0; i < m; i++) {
            int x, y;
            cin >> x >> y;
            --x; --y;
            if (x > y) {
                swap(x, y);
            }
            g[r][x].push_back(y);
        }
    }
    Mint p = (long long) 1e18;
    vector<Mint> pw(n);
    pw[0] = p;
    for (int i = 1; i < n; i++) {
        pw[i] = pw[i - 1] * p;
    }
    const int MAX = 512;
    vector<vector<Mint>> cnt(3, vector<Mint>(MAX));
    for (int r = 0; r < 3; r++) {
        vector<int> gr(n);
        for (int i = n - 1; i >= 0; i--) {
            set<int> s;
            for (int j : g[r][i]) {
                s.insert(gr[j]);
            }
            while (s.find(gr[i]) != s.end()) {
                ++gr[i];
            }
            cnt[r][gr[i]] += pw[i];
        }
    }
    Mint ans = 0;
    for (int x = 0; x < MAX; x++) {
        for (int y = 0; y < MAX; y++) {
            ans += cnt[0][x] * cnt[1][y] * cnt[2][x ^ y];
        }
    }
    cout << ans.a << '\n';
    return 0;
}


Measured memory_bytes: 15960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;


int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> B(N-1+1);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
		scanf("%lld",&B[i]);
	}
	priority_queue<P, vector<P>, greater<P> > que;
	rep(i,N) {
		que.push(P(B[i], A[i]));
	}
	ll time = 0;

	while (!que.empty()) {
		P p = que.top(); que.pop();
		time += p.second;
		if (time > p.first) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 5492
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;


int main()
{
	int N, X;
	cin >> N >> X;
	vector<int>data(N);
	int S = 0, M = 10000000000000;

	for (int i = 0; i < N; i++)
	{	
		cin >> data.at(i);
		S += data.at(i);
		if (data[i] < M)
		{
			M = data[i];
		}

	}

	

	cout << (N +(X-S)/M)<< endl;


}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define maxn 100005
using namespace std;

bool visit[maxn];
vector<int> graph[maxn];
int par[maxn];


void dfs(int s)
{
    visit[s]=1;

    for(int i=0;i<graph[s].size();i++)
    {
        int a=graph[s][i];
        if(visit[a])
            continue;
        par[a]=s;
        dfs(a);
    }
}

bool vis[maxn];
bool vis2[maxn];

int cnt;
void src(int s)
{
    vis2[s]=1;
    cnt++;
    for(int i=0;i<graph[s].size();i++)
    {
        int a=graph[s][i];
        if(a==par[s]||vis2[a])
            continue;
        src(a);
    }
}
vector<int> lis;
int main()
{
    int n;
    cin>>n;

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

        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(1);
    int A=0,B=0;

    cnt=0;
    src(n);
    B=cnt-1;
    //cout<<B<<"\n";

    int tot=0;
    int s=n;
    while(1)
    {
        s=par[s];
        if(s==1)
            break;
        cnt=0;
        src(s);
        //cout<<s<<" "<<cnt<<"\n";
        tot+=cnt;
        lis.push_back(cnt);
    }
    cnt=0;
    src(1);
    A=cnt-1;
    //cout<<A<<"\n";
    int rr=0;
    for(int i=0;i<(lis.size())/2;i++)
    {
        rr+=lis[i];
    }
    A+=tot-rr;
    B+=rr;
    //cout<<A<<" "<<B<<"\n";
    if(A-B>0)
    {
        cout<<"Fennec";
    }
    else cout<<"Snuke";
    return 0;
}


Measured memory_bytes: 11644
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> dp(2, vector<long long>(100001, 0));
 
int main() {
	int N; cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	dp[0][1] = A[0];
	dp[1][1] = -A[0];
	for (int i = 1; i < N; i++) {
		dp[0][i + 1] = max(dp[0][i] + A[i], dp[1][i] - A[i]);
		dp[1][i + 1] = max(dp[1][i] + A[i], dp[0][i] - A[i]);
	}
 
	cout << dp[0][N] << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

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

struct UnionFind {
    Vec<i32> p;

    UnionFind(i32 N) {
        p = Vec<i32>(N, -1);
    }

    i32 root(i32 x) {
        if (p[x] < 0) return x;
        return p[x] = root(p[x]);
    }

    bool unite(i32 x, i32 y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (p[x] > p[y]) swap(x, y);
        p[x] += p[y];
        p[y] = x;
        return true;
    }

    bool same(i32 x, i32 y) {
        x = root(x);
        y = root(y);
        return x == y;
    }

    i32 size(i32 x) {
        return -p[root(x)];
    }
};

void Main() {
    i32 N, M;
    cin >> N >> M;
    UnionFind uf(N);
    for (i32 i = 0; i < M; i++) {
        i32 A, B;
        cin >> A >> B;
        A--; B--;
        uf.unite(A, B);
    }
    i32 ans = 0;
    for (i32 i = 0; i < N; i++) {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  vector<long long> A(N);
  map<long long, long long> count;
  long long sum = 0;
  rep(i, N)
  {
    cin >> A[i];
    count[A[i]]++;
    sum += A[i];
  }
  long long Q;
  cin >> Q;
  vector<long long> B(Q), C(Q);
  vector<long long> ans(Q);
  rep(i, Q)
  {
    cin >> B[i] >> C[i];
    sum -= B[i] * count[B[i]];
    sum += C[i] * count[B[i]];
    count[C[i]] += count[B[i]];
    count[B[i]] = 0;
    ans[i] = sum;
  }

  rep(i, Q)
  {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 12136
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int P = sc.nextInt();
		int S = 0;
		
		P = P + A * 3;
		if(P%2==1)
			S = (P - 1) / 2;
		else
			S = P /2;
	
		System.out.println(S);
	}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
//const int mod= int(1e9)+7;
const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<mod>;

int main(){
    int n,k;cin >>n>>k;
    vector<mint>dp(n+1,0);
    dp[0]=1;
    V l(k);
    V r(k);
    for (int i = 0; i < k; ++i) {
        cin >>l[i]>>r[i];
        r[i]++;
    }
    for (int i = 1; i < n; ++i) {
        dp[i]+=dp[i-1];
        for (int j = 0; j < k; ++j) {
            if(i-l[j]>=0){
                dp[i]+=dp[i-l[j]];
            }
            if(i-r[j]>=0){
                dp[i]-=dp[i-r[j]];
            }
        }
    }
    cout <<dp[n-1]-dp[n-2]<<endl;
}


Measured memory_bytes: 4784
#include <iostream>
#include <algorithm>
#include <complex>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>

#define rep(i, b) for(int i = 0; i < b; i++)
#define repi(i, a, b) for(int i = a; i < b; i++)
#define all(c) c.begin(),c.end()
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define MAX_V 1001
#define MAX_E 401
#define INF INT_MAX
#define MOD 1000000007
#define EPS 1e-7
typedef long long ll;
inline int toInt(std::string s) { int v; std::istringstream sin(s); sin >> v; return v; }
template<class T> inline std::string toString(T x) { std::ostringstream sout; sout << x; return sout.str(); }
using namespace std;

typedef double D;      // 座標値の型。doubleかlong doubleを想定
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
#define X real()
#define Y imag()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
	ll N;
	cin >> N;
	vector<ll> A(N);

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

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

	ll pre = A[0];
	repi(i, 1, N)
	{
		if (A[i] - pre > 1)
		{
			cout << -1 << endl;
			return 0;
		}
		pre = A[i];
	}

	pre = A[0];
	ll res = 0;
	repi(i, 1, N)
	{
		if (A[i] == 0)
		{
			pre = A[i];
			continue;
		}
		if (A[i] == 1)
		{
			res++;
			pre = A[i];
			continue;
		}
		if (A[i] - pre == 1)
		{
			res++;
			pre = A[i];
			continue;
		}
		res += A[i];
		pre = A[i];
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int L, R; std::cin >> L >> R;
  std::set<int> vs;
  for (LL i = L; i <= R; ++i) {
    int r = i % 2019;
    if (r == 0) {
      std::cout << 0 << std::endl;
      return 0;
    }
    vs.insert(r);
  }

  int min_v = INT_MAX;
  for (int v1 : vs) {
    for (int v2 : vs) {
      if (v1 == v2) continue;
      min_v = std::min(min_v, v1*v2%2019);
    }
  }

  std::cout << min_v << std::endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  
  int N ;
  int M ;
  cin >> N  ;
  int ans = 0 ;
  vector<int> A(N) ;
  rep(i,N) cin >> A.at(i) ;
  rep(i,N){
      while( A.at(i)%2 == 0 && A.at(i) != 0 ){
        ans++ ;
        A.at(i) = A.at(i)/2 ; 
  	}
  }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,j,k=0,cnt=0,ans=0;
  scanf("%d", &n);
  for(i=n; i>=1; i--){
    j=i;
    while(j>=1 && j%2==0){
      cnt++;
      j=j/2;

    }
    if(cnt>=k){
      k=cnt;
      ans=i;
    }
    if(j==1){
      break;
    }
  }

  printf("%d\n",ans);
  return 0;

}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	static int calc(int e){
		int cnt = 0;
		for(int i = 1 ; i <= e; ++i){
			e -= i;
			++cnt;
			if(e < (i + 1)){
				break;
			}
		}
//		System.out.println(e+" "+cnt);
		return cnt;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int primes[] = new int[1000001];
		Arrays.fill(primes, 1);		
		List<Integer> plist = new ArrayList<Integer>();
		for(int i = 2 ; i < primes.length ; ++i){
			if(primes[i] == 1){
				plist.add(i);
				for(int j = i * 2 ; j < primes.length ; j += i){
					primes[j] = 0;
				}
			}
		}
//		System.out.println(plist.size());
		long N = sc.nextLong();
		long ret = 0;
		for(int p : plist){
			int e = 0;
			while(N % p == 0){
				N = N / p;
				++e;
			}
			if(e > 0){
				ret += calc(e);
//				System.out.println(e);
			}
		}
		if(N != 1){
			ret++;
		}
		System.out.println(ret);
	}
}


Measured memory_bytes: 43168
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
   ll dp[2000000];
 int gcd(int a, int b)
{
  if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b,a%b));
}
}
int main(){
  map<ll,ll>a;
  ll b,c;cin>>b;
  rep(i,b){
    cin>>c;
    a[c]++;
  }
  cin>>b;
  vector<ll>d(b,0);
  rep(i,b){
    cin>>d[i];
  }
  rep(i,b){
    if(a[d[i]]==0){
      cout<<"NO";
      return 0;
    }
    a[d[i]]--;
  }
  cout<<"YES";
}



Measured memory_bytes: 40692
#include<cstdio>
#include<vector>
#include<algorithm>
#define maxn 200005
#define mod 1000000007
using namespace std;
typedef pair<int,int> PII;
int n,ans,date[maxn],l[maxn],r[maxn],f[maxn],s[maxn];
double t[maxn];
PII q[maxn];
struct node { int x,v,i,l,r; } a[maxn];
bool cmp(node p,node q) { return p.v>q.v; }
bool cmp2(node p,node q)
{
	if(p.r!=q.r) return p.r<q.r;
	return p.l<q.l;
}
void getl()
{
	int cnt=0;
	for(int i=1;i<=n;i++) q[++cnt]=PII(a[i].x,a[i].i);
	sort(q+1,q+cnt+1);
	for(int i=1;i<=n;i++)
		while(cnt)
		{
			if(a[i].x>q[cnt].first) break;
			l[q[cnt--].second]=i;
		}
}
void getr()
{
	int cnt=0;
	for(int i=1;i<=n;i++) q[++cnt]=PII(a[i].x,a[i].i);
	sort(q+1,q+cnt+1);
	reverse(q+1,q+cnt+1);
	for(int i=n;i;i--)
		while(cnt)
		{
			if(a[i].x<q[cnt].first) break;
			r[q[cnt--].second]=i;
		}
}
int dp()
{
	for(int i=1;i<=n;i++) a[i].l=n-r[i]+1,a[i].r=n-l[i]+1;
	sort(a+1,a+n+1,cmp2);
	int ans=0;
	for(int i=1,j=1;i<=n;i++)
	{
		while(a[j].r<a[i].l-1) j++;
		f[i]=(s[i-1]-s[j-1]+mod)%mod;
		if(a[i].l==1) f[i]++;
		if(a[i].r==n) ans=(ans+f[i])%mod;
		s[i]=(s[i-1]+f[i])%mod;
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) 
	{
		scanf("%d%d",&a[i].x,&a[i].v);
		a[i].i=i,date[i]=a[i].v;
	}
	sort(date+1,date+n+1);
	int c=unique(date+1,date+n+1)-date-1;
	for(int i=1;i<=n;i++) a[i].v=lower_bound(date+1,date+c+1,a[i].v)-date;
	sort(a+1,a+n+1,cmp);
	getl(); getr();
	printf("%d\n",dp());
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    int A, B, K;
    vector<int> v;
    cin >> A >> B >> K;
    REP(i, 1, max(A + 1, B + 1)) {
        // cout << i << endl;
        if (A % i == 0 && B % i == 0) {
            v.push_back(i);
        }
    }
    cout << v[v.size() - K] << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
intervals = [list(map(int, input().split())) for _ in range(M)]
intervals.sort(key=lambda ab: ab[1])
ans = 1
position = intervals[0][1]
for i in range(1,M):
  if position <= intervals[i][0]:
    ans += 1
    position = intervals[i][1]
print(ans)

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

int main(){
    int n,in;
    long long sum=0;
    cin>>n;
    vector <long long> a;
    vector <long long> c;
    a.push_back(0);
    c.push_back(0);
    for(int i=1; i<=n; i++){
        cin>>in;
        a.push_back(in);
        c.push_back(in-i);
    }
    sort(c.begin()+1,c.end());
    int b;
    if(n%2)
        b=c[n/2+1];
    else
        b=(c[n/2]+c[n/2+1])/2;
    for(int i=1; i<=n; i++){
        sum+=abs(a[i]-b-i);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3564