akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define printarray(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b)/gcd(a, b)
#define int long long int
#define ull unsigned long long

using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;

int fastexpo(int b, int exp){
    if(exp == 0) return 1;
    if(exp == 1) return b;
    int ans = (fastexpo(b,exp/2) % MOD);
    ans *= ans;
    ans %= MOD;
    if(exp % 2 == 1){
        ans *= b;
    }
    ans %= MOD;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    if(n & 1){
    	cout<<"No"<<endl;
    	return 0;
    }
    string s;
    cin>>s;
    string t = "";
    for(int i= 0;i<n/2;i++){
    	t += s[i];
    }
    t += t;
    if(s == t){
    	cout<<"Yes"<<endl;
    } else {
    	cout<<"No"<<endl;
    }
    return 0;
}





Measured memory_bytes: 256
/*Made by Shivam Solanki*/
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef priority_queue<int> pq;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
typedef queue<int> qii;
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int INF = 1e9+5;
const int MOD = 1e9+7;
 
void solve(){
    ll a,b,k;
    cin>>a>>b>>k;
    cout<<max((ll)0,a-k)<<' '<<max((ll)0,b-max((ll)0,k-a))<<'\n';
}
    
int main(){
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    // fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
N = int(input())
t = [list(map(int, input().split())) for i in range(N)] #[t,x,y]
t.insert(0, [0,0,0]) #リストに場所指定して要素追加：（リスト名）.insert(インデックス番号, 要素)
flag = True
for i in range(N):
    dt = t[i+1][0] - t[i][0]
    dist = abs(t[i+1][1]-t[i][1]) + abs(t[i+1][2]-t[i][2])
    if dt < dist:
        flag = False
    if dt%2!=dist%2:
        flag = False
print('Yes' if flag else 'No')

Measured memory_bytes: 27300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[100005] = {}, b[100005] = {}, c = 1, d = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    while (c != 2) {
        if (b[c]) {cout << -1; return 0;}
        b[c] = 1;
        c = a[c];
        d++;
    }
    cout << d;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

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

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll n;
    cin >> n;
    string ans = "";

    while(n > 0){
        n--;
        ll v = (n % 26);

        ans += char('a' + v);
        
        n = n/26;
    }

    reverse(ALL(ans));
    cout << ans << endl;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  int sum = 0;
  REP(i, N) {
    cin >> A.at(i);
    sum += A.at(i);
  }
  int count = 0;
  REP(i, N) {
    if (A.at(i) * 4 * M >= sum) {
      ++count;
    }
  }

  if (count >= M) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef signed long long ll;
typedef vector<int> vi;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a) (a).begin(), (a).end()
#define out(x) cout << (x) << endl


int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n >> s;
	vi a(n+1, 0), b(n+1, 0);
	REP(i,1,n){
		a[i] = a[i-1];
		b[n-i-1] = b[n-i];
		if(s[i-1] == 'W') ++a[i];
		if(s[n-i] == 'E') ++b[n-i-1];
	}
	
	f = 1e6;
	rep(i, n){
		f = min(f, a[i] + b[i]);
	}
	cout << f << endl;
}

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

using namespace std;

int N, K, A[200005];


int main(void) {

	cin >> N >> K;
	for (int i = 1; i <= N; i++) { cin >> A[i]; }

	vector<int> V(N + 2);

	for (int i = 1; i <= N; i++) { V[i] = A[i]; }

	for (int k = 1; k <= K;k++) {
		vector<int> B(N + 2);
		//vector<int> S(N + 2);
		vector<int>W(N+2);

		for (int i = 1; i <= N; i++) {
			B[max(1, i - V[i])]++;  B[min(N + 1, i + V[i] + 1)]--;
		}

		for (int i = 1; i <= N; i++) {
			W[i] = W[i - 1] + B[i];
		}

		if (W == V) { break; }

		V = W;
	}

	for (int i = 1; i <= N; i++) {
		if (i != 1) { cout << " "; }
		cout << V[i];
	}cout << endl;

	return 0;
}

Measured memory_bytes: 5964
n = int(input())
h = list(map(int,input().split()))
 
for i in reversed(range(1,n)):
    if h[i-1] - h[i] == 1:
        h[i-1] -= 1
    elif h[i-1] - h[i] >=2:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 14224
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		
		long n=sc.nextLong();
		long p=sc.nextLong();
		long x=(long)Math.pow(p,(double)1/n)+1;
		
		long ans=1;
		if(n==1) {
			ans=p;
		}
		else {
			for(long i=x;i>=1;i--) {
			if(p%Math.pow(i,n)==0) {
					ans=i;
					break;
				}
			}
		}
	
		
		System.out.println(ans);
	}
		
	
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

	}
	

}





Measured memory_bytes: 23124
N = int(input())
A = [int(x) for x in input().split()]

def f(sgn):
    cum = 0
    cnt_operation = 0
    for a in A:
        sgn *= -1
        cum += a
        if cum * sgn > 0:
            continue
        else:
            cnt_operation += abs(cum) + 1
            cum = sgn
    return cnt_operation
print(min(f(-1), f(1)))



Measured memory_bytes: 14332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll ans = 0;
    for(int i = 1; i + i < N; i++) {
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  if (A <= 5)
  {
    cout << 0 << endl;
  }
  else if (5 < A && A < 13)
  {
    cout << B / 2 << endl;
  }
  else
  {
    cout << B << endl;
  }
}

Measured memory_bytes: 3464
#include<stdio.h>

int main(){
	int max,min,n,t,c,i;
	while(~scanf("%d",&n)){
		if(n==0)break;
		max=0;
		min=500;
		while(n--){
			t=0;
			for(i=0;i<5;i++){
				scanf("%d",&c);
				t+=c;
			}
			if(t>max)max=t;
			if(t<min)min=t;
		}
		printf("%d %d\n",max,min);
	}
	return 0;
}

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

int main()
{
    int n, k;
    string s;
    cin >> n >> k >> s;
    s.push_back('?');
    vector<int> v, w;
    char now = '1';
    int ren = 0;
    for(int i = 0; i <= n; i++){
        if(now != s[i]){
            if(now == '0'){
                v.push_back(ren);
                now = '1';
            }
            else{
                w.push_back(ren);
                now = '0';
            }
            ren = 0;
        }
        ren++;
    }
    w.push_back(0);
    int l = v.size();
    if(l <= k){
        cout << n << endl;
        return 0;
    }
    int sum = w[0];
    int ans = 0;
    for(int i = 0; i < l; i++){
        sum = sum + v[i] + w[i + 1];
        if(i >= k){
            sum = sum - v[i - k] - w[i - k];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
  string S, T; cin >> S >> T;
  int len = S.size();
  string ans = "No";
  for (int i = len; i > 0; --i) {
    S = S.back() + S.substr(0, len - 1);
    if (S == T) ans = "Yes";
  }

  cout << ans;
}

Measured memory_bytes: 256
def bubble_sort(A):
    swap_cnt = 0
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                swap_cnt += 1
    return A, swap_cnt


n = int(input())
A = list(map(int, input().split()))
A, swap_cnt = bubble_sort(A)
print(' '.join(map(str, A)))
print(swap_cnt)



Measured memory_bytes: 5600
n, k = map(int, input().split())
T = [int(input()) for i in range(n)]

def update(P):

    i=0
    for j in range(k):
        s=0
        while s + T[i] <= P:
            s += T[i]
            i += 1
            if(i == n):
                return n

    return i

left = 0
right = 1e+9

while right - left > 1:
    mid = int((left+right)/2)

    v = update(mid)
    if(v >= n):
        right = mid
    else:
            left = mid

print(right)


Measured memory_bytes: 9572
n=int(input())
a=list(map(int,input().split()))

even_num=[]
for i in range(n):
  if a[i]%2==0:
    even_num.append(a[i])

flag = True
for j in range(len(even_num)):
  if even_num[j]%3==0 or even_num[j]%5==0:
    flag = True
  else:
    flag = False
    break

if flag == False:
  print('DENIED')
else:
  print('APPROVED')

Measured memory_bytes: 3064
import itertools
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())
lis = list(itertools.combinations_with_replacement(range(1, K+1), 3))

ans=0
for i, j, k in lis:
    if i==j and j==k and i==k:
        ans+=gcd(i, j, k)
    elif i!=j and j!=k and i!=k:
        ans+=6*gcd(i, j, k)
    else:
        ans+=3*gcd(i, j, k)

print(ans)


Measured memory_bytes: 106080
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,k,j,flag=0,t,sum=0;
    cin>>n>>k;
    int arr[n+3];
    for(i  = 0 ;i< n;i++){
        cin>>arr[i];
    sum+=arr[i];
    }
    sort(arr,arr+n,greater<int>());
    for(i = 0 ;i<k ;i++)
    {
        if(arr[i]*4*k<sum)
            flag =1;
            //cout<<4*arr[i]<<" "<<sum<<endl;
    }
    if(flag == 0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
import math

def solve(h, alist, blist):
    amax = max(alist)
    c = 0
    for b in sorted(blist, reverse=True):
        if b <= amax:
            break
        c += 1
        h -= b
        if h <= 0:
            return c
    return c + math.ceil(h / amax)
 
 
n, h = map(int, input().split())
alist, blist = [], []
for _ in range(n):
    a, b = map(int, input().split())
    alist.append(a)
    blist.append(b)
 
print(solve(h, alist, blist))

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


#define ll long long



#define biggestFactor (n)      for (ll j = 2; j <= sqrt(n); j++){if (n % j == 0){cout << n / j << "\n";break;}}
                               //First find smallest factor and then divide that factor and the answer itself is biggest factor
                          
using namespace std;


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll x;
    cin >> x;
    if (x >= 30)
    {
        cout << "Yes" << "\n";
    }
    else
    {
        cout << "No" << "\n";
    }
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

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

int main(){
    string s, t; cin >> s >> t;
    vector<ll> sr(26, -1), tr(26, -1);
    rep(i, s.length()){
        if(sr[s[i] - 'a'] == -1) sr[s[i] - 'a'] = t[i] - 'a';
        else{
            if(sr[s[i] - 'a'] != t[i] - 'a'){
                cout << "No" << endl;
                return 0;
            }
        }
        if(tr[t[i] - 'a'] == -1) tr[t[i] - 'a'] = s[i] - 'a';
        else{
            if(tr[t[i] - 'a'] != s[i] - 'a'){
                cout << "No" << endl;
                return 0;
            }
        }
    }    
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3908
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        Arrays.sort(arr);

        int res = arr[arr.length / 2] - arr[arr.length / 2 - 1];
        System.out.println(res);
    }
}


Measured memory_bytes: 52396
#include <stdio.h>

int main(void) {
    int N;
    int A[100];
    int i;
    int min;
    int max;
    
    scanf("%d\n",&N);
    for (i=0; i<N; i++) {
        scanf("%d",&A[i]);
    }
    min=A[0];
    max=A[0];
    for (i=0; i<N; i++) {
        if (A[i]<min) {
            min=A[i];
        }
        if (A[i]>max) {
            max=A[i];
        }
    }

    printf("%d",max-min);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
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(){
  ll a, b;
  cin >> a >> b;
  if(a+b>=10){
    print("error");
  }
  else{
    print(a + b);
  }
}

Measured memory_bytes: 256
def solve_abc065d():
    from collections import namedtuple
    from heapq import heappush, heappop
    from operator import attrgetter
    from itertools import tee
    import sys

    input = sys.stdin.readline

    City = namedtuple('City', 'x y idx')
    Edge = namedtuple('Edge', 'cost to')
    N = int(input())

    cities = []
    for city_idx in range(N):
        x, y = map(int, input().split())
        c_ = City(x, y, city_idx)
        cities.append(c_)
    cities_x_asc = sorted(cities, key=attrgetter('x'))
    cities_y_asc = sorted(cities, key=attrgetter('y'))

    graph = tuple(set() for _ in range(N))

    it_x = iter(cities_x_asc)
    gx1, gx2 = tee(it_x, 2)
    next(gx2)
    for c1, c2 in zip(gx1, gx2):
        d_ = c2.x - c1.x
        graph[c1.idx].add(Edge(d_, c2.idx))
        graph[c2.idx].add(Edge(d_, c1.idx))
    # x方向にN-1本の辺を張る

    it_y = iter(cities_y_asc)
    gy1, gy2 = tee(it_y, 2)
    next(gy2)
    for c1, c2 in zip(gy1, gy2):
        d_ = c2.y - c1.y
        graph[c1.idx].add(Edge(d_, c2.idx))
        graph[c2.idx].add(Edge(d_, c1.idx))
    # y方向にN-1本の辺を張る

    # <Prim’s Algorithm>
    # https://tjkendev.github.io/procon-library/python/graph/min_st_prim.html
    # プリム法では、グラフGの1頂点からなる木から始め、
    # 木に含まれる頂点と木に含まれない頂点を繋ぐ辺のうち、
    # 一番コストが小さい辺が繋ぐ(木に含まれない方の)頂点を木に追加する、
    # ことを繰り返すことで最小全域木を求める。
    # G[v] = [w, ...]
    #     グラフG上で頂点vが隣接する辺集合

    start = 0  # 起点とする頂点

    used = [-1] * N
    used[start] = 1

    h = []
    for e_ in graph[start]:
        heappush(h, e_)

    mi = 0
    while h:
        e_ = heappop(h)
        if ~used[e_.to]: continue

        used[e_.to] = 1
        mi += e_.cost

        for ne_ in graph[e_.to]:
            if ~used[ne_.to]: continue
            heappush(h, ne_)

    # miが最小全域木の解

    print(mi)
    return


if __name__ == '__main__':
    solve_abc065d()


Measured memory_bytes: 86064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int inf = 1<<30;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

  vi nve(100001), nvo(100001);
  int nve_max = 0, nvo_max = 0;
  int ve_m, vo_m;
  rep(i,n/2) {
    int ve, vo;
    cin >> ve >> vo;
    nve[ve]++; nvo[vo]++;
    if(nve[ve]>nve_max) {
      nve_max = nve[ve];
      ve_m = ve;
    }
    if(nvo[vo]>nvo_max) {
      nvo_max = nvo[vo];
      vo_m = vo;
    }
  }

  RSORT(nve);
  RSORT(nvo);

  if(ve_m != vo_m) {
    cout << (n/2-nve[0])+(n/2-nvo[0]) << endl;
  }
  else {
    cout << min((n/2-nve[1])+(n/2-nvo[0]), (n/2-nve[0])+(n/2-nvo[1])) << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	if (n == 0) {
		cout << 0 << endl; return 0;
	}
	int i = 1;
	string ans = "";
	while (n != 0) {
		if (n % (i*(-2)) != 0) {
			n -= i; ans += '1';
		}
		else ans += '0';
		i *= (-2);
	}
	reverse(ALL(ans));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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(int argc, char const *argv[]) {
  int n;
  cin >> n;
  bool even=true;
  rep(i,n){
    ll b;
    cin >> b;
    if(b%2) even=false;
  }
  if(even) cout << "second" << endl;
  else cout << "first" << endl;
  return 0;
}


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

using namespace std;

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

#define INF 2<<29
#define F first
#define S second

int main(){
  double a;
  double temp;
  char ans1[8];
  char ans2[4];

  while(1){
    scanf("%lf",&a);
    if(a<0) break;

    for(int i=7;i>=0;i--){
      temp=(double)(1<<i);
      if(temp<=a){
	a-=temp;
	ans1[7-i]='1';
      }else{
	ans1[7-i]='0';
      }
    }
    
    for(int i=1;i<=4;i++){
      temp=pow(2.0,-(double)i);
      if(temp<=a){
	a=a-temp;
	ans2[i-1]='1';
      }else{
	ans2[i-1]='0';
      }
    }
    
    if(a!=0){
      printf("NA\n");
    }else{
      for(int i=0;i<8;i++){
	printf("%c",ans1[i]);
      }
      putchar('.');
      for(int i=0;i<4;i++){
	printf("%c",ans2[i]);
      }
      putchar('\n');
    }
  }
	       
  return (0);
}



Measured memory_bytes: 3404
N = int(input())
A = [int(input()) for _ in range(N)]
A = [a-1 for a in A]

fin = set()
cnt = 0
i = 0
while True:
    if i in fin:
        cnt = -1
        break
    if i == 1:
        break
    cnt += 1
    fin.add(i)
    i = A[i]
print(cnt)

Measured memory_bytes: 20012
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	final static PrintStream so = System.out;
	final static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		Map<Integer, Integer> counter = new HashMap<>();
		for (int i = 0; i<n; i++) {
			int in = sc.nextInt();
			if (counter.containsKey(in)) {
				counter.put(in, counter.get(in) + 1);
			} else {
				counter.put(in, 0);
			}
		}
		int sum = counter.values().stream().mapToInt(i -> i).sum();
		so.println(sum % 2 == 0 ? n - sum : n - sum - 1);
	}
}


Measured memory_bytes: 60508
n,k = gets.split.map(&:to_i)
MOD = 10**9 + 7
ans = []
k.upto(n+1){|i|
  min = (i*(i-1))/2
  max = (i*((2*n)-i+1))/2
  l = (max - min + 1)%MOD
  ans << l
}
puts (ans.sum)%MOD

Measured memory_bytes: 16056
def prime_pair(n):
    pairs = {}
    tmp = n
    for i in range(2, n):
        if i * i > n:
            break
        if tmp % i != 0:
            continue
        ex = 0
        while tmp % i == 0:
            ex += 1
            tmp /= i
        pairs[i] = ex
    if tmp != 1:
        pairs[int(tmp)] = 1
    return pairs

N, P = list(map(int, input().split()))
ppp = prime_pair(P)

res = 1
for k in ppp.keys():
    cnt = ppp[k]//N 
    
    if cnt>= 1:
        res *= k**cnt
print(res)

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;

    vector<li> ps(a), qs(b), rs(c);
    for (int i = 0; i < a; ++i) {
        cin >> ps[i];
    }
    for (int i = 0; i < b; ++i) {
        cin >> qs[i];
    }
    for (int i = 0; i < c; ++i) {
        cin >> rs[i];
    }

    sort(ps.begin(), ps.end(), greater<>());
    sort(qs.begin(), qs.end(), greater<>());
    sort(rs.begin(), rs.end(), greater<>());

    vector<li> pacc(a + 1), qacc(b + 1), racc(c + 1);
    for (int i = 0; i < a; ++i) {
        pacc[i + 1] = pacc[i] + ps[i];
    }
    for (int i = 0; i < b; ++i) {
        qacc[i + 1] = qacc[i] + qs[i];
    }
    for (int i = 0; i < c; ++i) {
        racc[i + 1] = racc[i] + rs[i];
    }

    li ans = 0;
    for (int cred = 0; cred <= min({a, c, x}); ++cred) {
        const li use_red = x - cred;
        li tans = pacc[use_red];

        const li unused_gray = c - cred;
        li p = 0, q = min({b, unused_gray, y}) + 1;
        while (q - p > 1) {
            li m = (p + q) / 2;
            if (qs[y - m] > rs[cred + m - 1]) {
                q = m;
            } else {
                p = m;
            }
        }
        li cgreen = p;
        const li use_green = y - cgreen;
        const li use_gray = cred + cgreen;
        tans += qacc[use_green];
        tans += racc[use_gray];
        ans = max(ans, tans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
/**
 * Created by hiramekun at 17:03 on 2019-10-23.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    vl d(n);
    cin >> d;
    ll m;
    cin >> m;
    vl t(m);
    cin >> t;
    
    
    ump<ll, ll> mp;
    rep(i, n) {
        mp[d[i]]++;
    }
    rep(i, m) {
        if (mp[t[i]] == 0) {
            cout << "NO" << '\n';
            return;
        }
        mp[t[i]]--;
    }
    cout << "YES" << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 11592
from collections import defaultdict

N = int(input())

cities = defaultdict(dict)
for i in range(N):
    S, P = input().split()
    cities[S][i] = int(P)

names = sorted(cities.keys())
for name in names:
    ps = sorted(cities[name].items(), reverse=True, key=lambda p: p[1])
    for p in ps:
        print('{}'.format(p[0]+1))

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

int main(void){
	int n1, n2, tmp, row;
	cin>>n1;
	vector < vector <int> > M(n1, vector <int>(n1));

	for (int j=0; j<n1; j++){
		cin>>row;
		cin>>n2;
		for (int i=0; i<n2; i++){
			cin>>tmp;
			M[row-1][tmp-1] = 1;
		}
	}

	for (int i=0; i<n1; i++){
		for (int j=0; j<n1; j++){
			if (j == n1-1)
				cout<<M[i][j]<<endl;
			else
				cout<<M[i][j]<<" ";
		}
	}
	return 0;
} 

Measured memory_bytes: 1260
N = int(input('')) #input()で入力を受け取ってint()で数字型に変換します。

A = list(map(int,input().split()))

A.insert(0,0)

A.insert(0,0)

subordinate = [0] * (N+1)
#subordinate[N-1] = 0

# print(subordinate)
# print(A)

for index in range(N, 1, -1):
    subordinate[A[index]] = subordinate[A[index]] + 1


for index in range(1, N+1, 1):
    print(subordinate[index])



Measured memory_bytes: 32316
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int n;
    ll a;
    list<ll> b;
    cin >> n;
    rep(i, n){
        cin >> a;
        if(i%2 == 0) b.push_back(a);
        else b.push_front(a);
    }

    if(n%2==1){
        rep(i, n){
            cout << b.back() << " ";
            b.pop_back();
        }
    }else{
        rep(i, n){
            cout << b.front() << " ";
            b.pop_front();
        }
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <algorithm>

using namespace std;

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

  sort(A, &A[3]);

  int ans;
  ans = ((A[2]-A[1])+(A[2]-A[0]))/2;
  int amari;
  amari = ((A[2]-A[1])+(A[2]-A[0]))%2;
  if(amari == 1) ans += 2;

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;                       
typedef long long ll;
  int main()
  {  int a,b,c,d,t1,t2,t11,t22;
      cin>>a>>b>>c>>d;
       t1=a/d;
       if(a%d!=0)
       t1++;
       t2=c/b;
       if(c%b!=0)
        t2++;
		if(t2>t1)
		 cout<<"No"<<endl;
		 else
		 cout<<"Yes"<<endl;
	
     }

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

int main() {
    int N, K;
    while (cin >> N >> K) {
        vector<long long> values;
        for (int i = 0; i < N; ++i) {
            long long v; cin >> v;
            values.push_back(v);
        }

        long long answer = -1;
        for (int n_left = 0; n_left <= N; ++n_left) {
            for (int n_right = 0; n_right <= N; ++n_right) {
                if (n_left + n_right > N || n_left + n_right > K) break;
                vector<long long> hand;
                hand.insert(hand.end(), values.begin(), values.begin() + n_left);
                hand.insert(hand.end(), values.end() - n_right, values.end());
                sort(hand.begin(), hand.end());
                long long sum_return = 0;
                for (int i = 0; i < (int)hand.size(); ++i) {
                    if (i >= K - (n_left + n_right)) break;
                    if (hand[i] >= 0) break;
                    sum_return += hand[i];
                }
                long long sum = 0;
                for (auto v : hand) {
                    sum += v;
                }
                answer = max(answer, sum - sum_return);
            }
        }

        cout << answer << endl;
    }
}

Measured memory_bytes: 256
import collections
n,m = map(int,input().split())
s = list(input())
g = [[] for i in range(0,n)]
ab = [{"A":0,"B":0}for _ in range(0,n)]
for i in range(0,m):
    A,B = map(int,input().split())
    g[A-1].append(B-1)
    g[B-1].append(A-1)
    ab[A-1][s[B-1]] += 1
    ab[B-1][s[A-1]] += 1

visit = [0 for i in range(0,n)]
que = collections.deque()
for i in range(0,n):
    if ab[i]["A"] == 0 or ab[i]["B"] == 0:
        que.append(i)
        visit[i] = 1

while len(que) > 0:
    q = que.popleft()
    for j in g[q]:
        ab[j][s[q]] -= 1
        if (ab[j]["A"] == 0 or ab[j]["B"] == 0)and visit[j] == 0:
            que.append(j)
            visit[j] = 1
if sum(visit) == n:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 102688
# https://atcoder.jp/contests/abc080/submissions/1829635

N, C = map(int, input().split())
ps = [[] for _ in range(C)]

for _ in range(N):
    s, t, c = map(int, input().split())
    c -= 1
    ps[c].append((s, t))

N_max = 10 ** 5
imos = [0] * (N_max + 1)

for c in range(C):
    ps[c].sort()
    cont = False
    for i, (s, t) in enumerate(ps[c]):
        if not cont:
            imos[s - 1] += 1
        if i + 1 < len(ps[c]) and t == ps[c][i + 1][0]:
            cont = True
        else:
            imos[t] -= 1
            cont = False

ans = t = 0
for imo in imos:
    t += imo  # ここでシミュレート
    ans = max(ans, t)
print(ans)


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

int main(){
  int K;
  string S;
  cin >> K >> S;
  if(S.size() <= K){
    cout << S << endl;
  }else{
    string s = "";
    for(int i = 0; i < K; i++){
      s += S[i];
    }
    s += "...";
    cout << s << endl;
  }
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int K;
  cin>>K;

  vector<int> used(K+1,0);
  int val=0;
  for(int i=1;;i++){
    val=val*10+7;
    val%=K;
    if(used[val]){
      cout<<-1<<endl;
      return 0;
    }
    used[val]=1;
    if(val==0){
      cout<<i<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 7152
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int n,a[410],rui[410];
int dp[410][410];

int merge(int l, int r){
    if (r-l <= 1) return 0;
    if (r-l == 2) return a[l] + a[l+1];
    if (dp[l][r]) return dp[l][r];
    int ret = 1LL << 60;
    FOR(mid, l+1, r){
        int lsize = rui[mid] - rui[l];
        int rsize = rui[r] - rui[mid];
        int lcost = merge(l,mid);
        int rcost = merge(mid,r);
        ret = min(ret, lsize + rsize + lcost + rcost);
    }
    return dp[l][r] = ret;
}

signed main(){
    I(n);
    REP(i,n) I(a[i]);
    REPS(i,n) rui[i] = rui[i-1] + a[i-1];
    cout << merge(0,n) << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

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

  int min = 300000;
  int count = 0;
  
  for (int n=0; n<N; ++n) {
    int p;
    cin >> p;
    if (p <= min) {
      ++count;
      min = p;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


unordered_map<char, char> s2t;
unordered_map<char, char> t2s;

int main() {
	string s, t; cin >> s >> t;
	REP(i, s.size()) {
		if (s2t.count(s[i]) == 0) {
			s2t[s[i]] = t[i];
		}
		else {
			if (s2t[s[i]] != t[i]) {
				print("No");
				return 0;
			}
		}
		if (t2s.count(t[i]) == 0) {
			t2s[t[i]] = s[i];
		}
		else {
			if (t2s[t[i]] != s[i]) {
				print("No");
				return 0;
			}
		}
	}
	print("Yes");

	return 0;
}


Measured memory_bytes: 776
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
#define Length 80000
using namespace std;
typedef pair<ll, ll> P;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

bool used[110];

bool cmp(const pair<int,int> &a,const pair<int,int> &b) {
	return a.first * a.first + a.second * a.second > b.first*b.first + b.second * b.second;
}

void solve(int n) {
	vector<pair<int, int>>p(n), q(n);
	for (int i = 0;i < n;i++) {
		cin >> p[i].first >> p[i].second;
	}
	for (int i = 0;i < n;i++) {
		cin >> q[i].first >> q[i].second;
	}
	int dist = Length, flag = 0;
	int ans = 0;
	sort(p.begin(), p.end());
	for (int i = 0;i < n;i++) {
		dist = Length;
		flag = 0;
		for (int j = 0;j < n;j++) {
			if (!used[j]) {
				int x = q[j].first - p[i].first;
				int y = q[j].second - p[i].second;
				if ((x > 0) && (y > 0) && y < dist) {
					dist = y;
					flag = j;
				}
			}
		}
		if (dist < Length) {
			ans++;
			used[flag] = true;
		}
	}
	cout << ans << endl;
}
	
int main(void){
	int n, sum = 0, x = 0;
	cin >> n;
	vector<int>a(n + 2);
	a[0] = 0;
	a[n + 1] = 0;
	for (int i = 1;i <= n;i++) cin >> a[i];
	for (int i = 0;i <= n;i++) {
		sum += (int)abs(a[i + 1] - a[i]);
	}
	for (int i = 1;i <= n;i++) {
		x = sum;
		if (((a[i - 1] <= a[i]) && (a[i] <= a[i + 1])) || ((a[i - 1] >= a[i]) && (a[i] >= a[i + 1]))) {
			cout << x << endl;
		}
		else {
			if (((a[i] <= a[i + 1]) && (a[i + 1] <= a[i - 1]))||((a[i-1]<=a[i+1])&&(a[i+1]<=a[i]))) {
				x = sum - 2 * (int)abs(a[i] - a[i + 1]);
				cout << x << endl;
			}
			else {
				x = sum - 2 * (int)abs(a[i] - a[i - 1]);
				cout << x << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main()
{
	long long ans = 0, i, j, k, N, T[100000], M, P[100], X[100];

	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> T[i];
		ans += T[i];
	}
	cin >> M;
	for (i = 0; i < M; i++) {
		cin >> P[i] >> X[i];
	}

	for (i = 0; i < M; i++) {
		cout << ans - T[P[i]-1] + X[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public StringBuffer plus ( String big , String small ) {
		int next = 0;
		String result = "";
		StringBuffer b = new StringBuffer(big) , s = new StringBuffer(small);
		b.reverse(); s.reverse();
		for ( int i = 0; i < b.length(); i++ ) {
			String one = b.substring(i,i+1) , two = "0";
			if ( i < s.length() )
				two = s.substring(i,i+1);
			next = next + Integer.parseInt(one) + Integer.parseInt(two);
			if ( next >= 10 ) {
				result += Integer.toString(next - 10);
				next = 1;
			}
			else {
				result += Integer.toString(next);
				next = 0;
			}
		}
		if ( next != 0 ) result += "1";
		if ( result.length() > 80 ) {
			StringBuffer rtn = new StringBuffer("overflow");
			return rtn;
		} else {
			StringBuffer rs = new StringBuffer(result);
			return rs.reverse();
		}
	}
	
	public static void main ( String args[] ) {
		Main m = new Main();
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for ( int i = 0; i < n; i++ ) {
			String big , small;
			String in1 = sc.next();
			String in2 = sc.next();
			if ( in1.length() < in2.length() ) {
				big = in2; small = in1;
			} else {
				big = in1; small = in2;
			}
			System.out.println(m.plus(big, small));
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;

int main(){
    int a,b;
    cin>>a>>b;
    if(b%a==0)OUT(a+b);
    else OUT(b-a);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main (){
    int i,j;
    long long n,c,k;
    long long t[1000050] = {0};
    int b = 1;
    int p = 0;
    int cp = 0;
    
    scanf("%lld %lld %lld",&n,&c,&k);
    for(i=0; i<n; i++){
        scanf("%lld",&t[i]);
    }
    sort(t,t+n);
 
    p = t[0] + k;
    for(i=0; i<n; i++){
        if(cp < c && t[i] <= p){
            cp++;
        }else{
            cp = 1;
            b++;
            p = t[i] + k;
        }
    }
    printf("%d\n",b);
    return 0;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=55;
vector<int> e1[N],e2[N],e3[N];
int q[N],deg[N],n,ans,sum;
int vis[N][N],banx,bany;
int fa1[N],fa2[N],spe[N];
bool topo(){
	int h=0,t=0;
	For(i,1,n) if (!deg[i]) q[++t]=i;
	while (h!=t){
		int x=q[++h];
		For(i,0,e3[x].size()-1)
			if (!--deg[e3[x][i]])
				q[++t]=e3[x][i];
	}
	return t==n;
}
void dfs1(int x,int fl){
	sum-=fl; spe[x]=fl;
	For(i,0,e1[x].size()-1)
		if (e1[x][i]!=fa1[x]&&vis[x][e1[x][i]]!=-1){	
			fa1[e1[x][i]]=x;
			dfs1(e1[x][i],vis[x][e1[x][i]]&fl);
		}
}
void dfs2(int x){
	For(i,0,e2[x].size()-1)
		if (e2[x][i]!=fa2[x]){	
			fa2[e2[x][i]]=x;
			dfs2(e2[x][i]);
		}
}
int check(int id){
	memset(fa1,0,sizeof(fa1));
	memset(fa2,0,sizeof(fa2));
	memset(deg,0,sizeof(deg));
	int fl=vis[banx][bany]; sum=n;
	vis[banx][bany]=vis[bany][banx]=-1;
	dfs1(id,1); dfs2(id);
	For(i,1,n) e3[i].clear();
	For(i,1,n) if (!spe[i]){
		if (!spe[fa1[i]]){
			e3[i].PB(fa1[i]);
			++deg[fa1[i]];
		}
		if (!spe[fa2[i]]){
			e3[fa2[i]].PB(i);	
			++deg[i];
		}
	}
	if (!topo()) sum=1<<30;
	vis[banx][bany]=vis[bany][banx]=fl;
	//printf("QUERY %d %d\n",id,sum);
	return sum;
}
void solve(){
	scanf("%d",&n);
	For(i,1,n) e1[i].clear();
	For(i,1,n) e2[i].clear();
	memset(vis,0,sizeof(vis));
	For(i,1,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		e1[x].PB(y); e1[y].PB(x);
	}
	For(i,1,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		e2[x].PB(y); e2[y].PB(x);
		vis[x][y]=vis[y][x]=1;
	}
	int ans=1<<30;
	banx=bany=0;
	For(i,1,n) ans=min(ans,check(i));
	For(i,1,n) if (e1[i].size()==1){
		int opp=e1[i][0];
		For(j,1,n) if (j!=i&&j!=opp){
			banx=i,bany=opp;
			e1[i].PB(j); e1[j].PB(i);
			ans=min(ans,check(i)+1);
			e1[i].pop_back();
			e1[j].pop_back();
		}
	}
	if (ans>1<<29)
		ans=-1;
	printf("%d\n",ans);
}
int main(){
	int T;
	scanf("%d",&T);
	while (T--) solve();
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    var list: MutableList<Pair<Int, Int>> = mutableListOf()
    for (i in 1..m) {
        val (a, b) = readLine()!!.split(" ").map(String::toInt)
        val pair = if (a < b) Pair(a, b) else Pair(b, a)
        list.add(pair)
    }

    list.sortBy { p -> p.first }

    var res = 0
    var first = 0
    var prevSecond = 0
    for (p in list) {
        if (first < p.first && prevSecond <= p.first) {
            first = p.first
            prevSecond = p.second
            res++
        } else {
            if (prevSecond > p.second) {
                prevSecond = p.second
            }
        }

    }

    println(res)
}

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

const int mod=1e9+7;

int main(){
    int n; string s1,s2;
    cin>>n>>s1>>s2;
    if(n==1){cout<<3<<endl; return 0;}
    ll ans; int i=1;
    if(s1[0]==s2[0])ans=3;
    else ans=6;
    for(i; i<n; ++i){
        if(s1[i-1]==s2[i-1]&&s1[i]==s2[i])ans=ans*2%mod;
        if(s1[i-1]!=s2[i-1]&&s1[i]==s2[i])continue;
        if(s1[i-1]==s2[i-1]&&s1[i]!=s2[i])ans=ans*2%mod,i++;
        if(s1[i-1]!=s2[i-1]&&s1[i-1]!=s1[i])ans=ans*3%mod,i++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256