akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i+=2) {
        cout << s.at(i);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#define HEIGHT 10

using namespace std;

int a[HEIGHT];

void solve(){
	bool f=true;
	int right,left;
	right = left = 0;
	for(int i=0;i<HEIGHT;i++){
		if(right<a[i] && left<a[i]){
			if(right<left){
				left = a[i];
			} else {
				right = a[i];
			}
		} else if(right<a[i]){
			right = a[i];
		} else if(left<a[i]){
			left = a[i];
		} else {
			f = false;
			break;	
		}
	}
	if(f){
		printf("YES\n");
	} else {
		printf("NO\n");
	}
}
			
int main(){
	
	int lp;
	scanf("%d",&lp);
	
	for(int i=0;i<lp;i++){
		for(int j=0;j<HEIGHT;j++){
			scanf(" %d",&a[j]);
		}
		solve();	
	}
	return 0;
}

Measured memory_bytes: 1008
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		for(;;){
			int x=sc.nextInt();
			int h=sc.nextInt();
			if((x|h)==0) break;
			double a = (double)x*x+(Math.sqrt((double)x*x/4+h*h))*x*2;
			System.out.println(a);
			
		}
		
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

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

int main() {
int a,b,s;
cin>>a>>b;
s=a+b;
if(a%3==0)  cout  << "Possible"   <<  endl;
else if(b%3==0){
cout <<"Possible"<<endl;
}
else if(s%3==0){
cout <<"Possible"<<endl;
}
else cout <<"Impossible"<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean solve() {
		int n = in.nextInt();
		int w = in.nextInt();
		if (n + w == 0) return false;

		int[] v = new int[n];
		int[] c = new int[120];
		for (int i=0; i<n; i++) {
			v[i] = in.nextInt();
			c[v[i]/w]++;
		}

		double max = 0, idx = 0;
		for (int i=0; i<120; i++) {
			if (c[i] > 0) idx = i;
			max = Math.max(max, c[i]);
		}

		double ans = 0;
		for (int i=0; i<120; i++) {
			ans += c[i]/max*(1-i/idx);
		}
		out.printf("%.6f\n", ans+0.01);

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

int main(){
    string s;
    cin >> s;
    char last;
    last = s.at(0);
    int c = 1, i;
    for(i = 1; i < s.size(); i++){
        if(i == s.size()-1){
            if(s.at(i) == last){
                continue;    
            }
            else{
                c++;
                continue;
            }
        }
        if(s.at(i) == last){
            i++;
            c++;
            last = '0';
            continue;
        } else{
            c++;
            last = s.at(i);
            continue;
        }

    }

    cout << c << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

int main(){
    ll N; cin >> N;
    for(ll k = 2; (k * (k - 1)) / 2 < 1000000; k++){
        if (N == (k * (k - 1)) / 2){
            vector<vector<ll>> list(k, vector<ll>(0));
            ll cnt = 1;
            for(ll i = 0; i < k; i++){
                rep(j, i){
                    list[i].emplace_back(list[j][i - 1]);
                }
                rep(j, k - 1 - i){
                    list[i].emplace_back(cnt);
                    cnt++;
                }
            }
            pt("Yes");
            pt(k);
            rep(i, k){
                cout << k - 1 << " ";
                rep(j, k - 1) cout << list[i][j] << " ";
                cout << endl;
            }
            return 0;
        }
    }
    pt("No");
}

Measured memory_bytes: 3200
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np
# import heapq
# from collections import deque

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr
tot = sum(A)
wo_X0 = 0
for i in range(1, N, 2):
    wo_X0 += A[i]
X = []
X.append(tot - 2 * wo_X0)

for i in range(1, N):
    X.append(2 * A[i - 1] - X[i - 1])

for x in X:
    print(x, end = ' ')

Measured memory_bytes: 20544
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String S = sc.next();

		char[] ch = S.toCharArray();

		int a=0;
		int b=0;
		int c=0;
		for (char cs : ch){
			if(cs=='a') a++;
			if(cs=='b') b++;
			if(cs=='c') c++;
		}



		if(a==b && b==c){
			System.out.println("YES");
			System.exit(0);
		}

		if(a==b+1 && a==c+1){
			System.out.println("YES");
			System.exit(0);
		}

		if(b==c+1 && b==a+1){
			System.out.println("YES");
			System.exit(0);
		}
		if(c==a+1 && c==b+1){
			System.out.println("YES");
			System.exit(0);
		}

		if(a==b-1 && a==c-1){
			System.out.println("YES");
			System.exit(0);
		}

		if(b==c-1 && b==a-1){
			System.out.println("YES");
			System.exit(0);
		}
		if(c==a-1 && c==b-1){
			System.out.println("YES");
			System.exit(0);
		}



		System.out.println("NO");
	}

}


Measured memory_bytes: 25900
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,n) for(int i=(1);i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}

/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    string s,t;
    cin>>s>>t;
    sort(all(s));
    sort(rall(t));
    if(s<t)cout<<"Yes";
    else cout<<"No";

    return 0;
}


Measured memory_bytes: 3656
import math
input01 = input()
a=input01.split()

tate=float(a[0])
takasa=float(a[1])
mizu=float(a[2])
menseki1 = tate * takasa
menseki2 = mizu / tate
diff=menseki1-menseki2
rad=0
if(diff <= tate*takasa/2):
    stakasa=2*diff/(tate)
    rad = math.degrees(math.atan(stakasa/tate))
elif(diff > tate*takasa/2):
    stakasa=2*(menseki1-diff)/(takasa)
    rad = math.degrees(math.atan2(takasa,stakasa)) 
    

print(rad)


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

int main() {
  int A,B;
  cin >> A >> B;
  int ans;
  ans = max(A+B, max(A-B,A*B));

  cout << ans << endl;

}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, x int
	fmt.Scanf("%d %d %d\n", &a, &b, &x)

	r := a * a * b

	var theta float64
	if x >= r/2 {
		theta = math.Atan(float64(2*(a*a*b-x)) / float64(a*a*a))
	} else {
		theta = math.Atan(float64(a*b*b) / float64(2*x))
	}

	fmt.Println(theta * 180 / math.Pi)
}


Measured memory_bytes: 512
let (n,m,x) = cin.triple
/// [60 2 2 2]
let CA = Array(1...n).map { _ in
    return cin.array
}

var v = Int.max
for indexies in bit全探索(n: n) {
    let ca = indexies.map { CA[$0] }
    let c = ca.map { $0[0] }.sum
    let res = (1...m).allSatisfy { mi in
        return x <= ca.map { $0[mi] }.sum
    }
    if res {
        v = min(v, c)
    }
}

if v == Int.max {
    print(-1)
} else {
    print(v)
}

typealias Index = Int
func bit全探索(n: Int) -> [[Index]] {
    (0..<1<<n).map { bit in
        var s = [Int]()
        for i in 0..<n {
            if bit & 1<<i > 0 {
                s.append(i)
            }
        }
        return s
    }
}

// MARK: #### 以下、ライブラリ ####

import Foundation
#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

enum cin {
    // 123
    static var int: Int { Int(readLine()!)! }
    // 12 23
    static var pair: (Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!) }
    // 12 23 34
    static var triple: (Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!) }
    // AtCoder
    static var str: String { readLine()! }
    // At Coder
    static var arrayStr: [String] { str.components(separatedBy: " ") }
    // 1 2 3 4
    static var array: [Int] { str.components(separatedBy: " ").map { Int($0)! } }
    // 1
    // 2
    // 3
    static func v_array(count: Int) -> [Int] { (0..<count).map { _ in int } }
}

extension Int {
    // 123 -> [1, 2, 3]
    var digits: [Int] { Array(String(self)).map { Int(String($0))! } }
}

extension Array where Element == Int {
    // [2, 1, 3, 2] -> 8
    var sum: Int { self.reduce(0, +) }
    // [2, 1, 3, 2] -> [1, 2, 2, 3]
    var orderBy: [Int] { sorted() }
    // [2, 1, 3, 2] -> [3, 2, 2, 1]
    var orderByDesc: [Int] { sorted(by: { $0 > $1 }) }
    // [2, 1, 3, 2] -> [2, 1, 3]
    var distinct: [Int] { Array(Set(self)) }
}

precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ^^ : PowerPrecedence
func ^^ (radix: Int, power: Int) -> Int {
    return Int(pow(Double(radix), Double(power)))
}

extension String {
    // e.g. cin.line.regex(match: "^(dream|dreamer|erase|eraser)*$")
    func regex(match pattern: String) -> Bool {
        let regex = try! NSRegularExpression(pattern: pattern)
        return regex.firstMatch(in: self, range: NSRange(location: 0, length: self.count)) != nil
    }
    // "ABC"[1] -> "B"
    subscript(i: Int) -> Character {
        get {
            self[index(at: i)]
        }
        set(char) {
            var characters = Array(self)
            characters[i] = char
            self = String(characters)
        }
    }
    func index(at offset: Int) -> String.Index { index(startIndex, offsetBy: offset) }
    // "ABC".swapAt(0, 1) -> "BAC"
    mutating func swapAt(_ index1: Int, _ index2: Int) {
        var characters = Array(self)
        characters.swapAt(index1, index2)
        self = String(characters)
    }
}


Measured memory_bytes: 14556
import math
import itertools
import fractions
import heapq
import collections
import bisect
import sys
import copy

sys.setrecursionlimit(10**9)
mod = 998244353
inf = 10**20

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

h,n = LI()
a = LI()

if sum(a)>=h:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 16104
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<vector<int>> a(n,vector<int>(m+1));
    rep(i,n) rep(j,m+1) cin>>a[i][j];
    
    int sum1,sum2,sum3,cost;
    int minv=1000000005;
    bool exist=false;
    for(int bit=0;bit<(1<<n);bit++){
        vector<int> sum(m,0);
        cost=0;
        bool flag=true;
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                rep(h,m) sum[h]+=a[i][h+1];
                cost += a[i][0];
            }
        }
        rep(i,m){
            if(sum[i]<x) flag=false;
        }
        if(flag){
            minv=min(minv,cost);
            exist=true;
        }
    }
    
    if(exist) cout<<minv<<endl;
    else cout<<-1<<endl;
    return 0;
}

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

b=[0]*40
for a in A:
    for k in range(40):
        if a&(1<<k):
            b[k]+=1

x=0
for k in range(39,-1,-1):
    if x+(1<<k)>K:
        continue
    if b[k]<(N+1)//2:
        x+=(1<<k)
ans=0
for a in A:
    ans+=x^a

print(ans)


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(); // 冷蔵庫
		int b = sc.nextInt(); // 電子レンジ
		int c = sc.nextInt(); // 割引券
		Integer d[] = new Integer[a];
		Integer e[] = new Integer[b];
		int f = 0;

		for (int i = 0; i < a; i++) {
			d[i] = sc.nextInt();
		}
		for (int i = 0; i < b; i++) {
			e[i] = sc.nextInt();
		}
		for (int i = 0; i < c; i++) {
			int l = sc.nextInt() - 1;
			int m = sc.nextInt() - 1;
			int n = sc.nextInt();
			if (i > 0) {
				f = Integer.sum(d[l], e[m]) - n > f ? f
						: Integer.sum(d[l], e[m]) - n;
			} else {
				f = Integer.sum(d[l], e[m]) - n;
			}
		}

		Arrays.sort(d);
		Arrays.sort(e);
		int h = d[0] + e[0];

		System.out.println(f > h ? h : f);

	}
}

Measured memory_bytes: 159324
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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 n,m,c;
  cin >> n >> m >> c;
  int b[m];
  FOR(i,0,m-1) cin >> b[i];
  int a[n][m];
  int sum;
  int ans = 0;
  FOR(i,0,n-1){
    sum = 0;
    FOR(j,0,m-1){
      cin >> a[i][j];
      sum += b[j] * a[i][j];
    }
    if(sum+c>0) ++ans;
  }

  cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
long long n,x;
long long wk(long long x,long long y)
{//cerr<<x<<" "<<y<<" "<<endl;
	if(y%x==0)
		return 2ll*y-x;
	return !x?0ll:(2ll*x*(y/x)+wk(y%x,x));
}
int main()
{
	scanf("%lld%lld",&n,&x);
	printf("%lld\n",n+wk(min(x,n-x),max(x,n-x)));
	return 0;
}     

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<int> gr[1010];
int a[252521],b[252521];
int dp[1010][1010];
int from[1010];
void dfs(int v,int r,int s){
	if(v==r) return;
	if(dp[r][v]>=2) return;
	if(dp[r][v]==1 && from[v]==s) return;
	if(dp[r][v]==0) from[v]=s;
	dp[r][v]++;
	//cout<<v<<' '<<r<<' '<<s<<' '<<dp[r][v]<<endl;
	rep(i,gr[v].size()) dfs(gr[v][i],r,s);
}
int main()
{
	int n,m;cin>>n>>m;
	rep(i,m){
		cin>>a[i]>>b[i];a[i]--;b[i]--;
		gr[a[i]].pb(b[i]);//gr[b[i]].pb(a[i]);
	}
	memset(dp,0,sizeof(dp));
	rep(i,n){
		memset(from,-1,sizeof(from));
		rep(j,gr[i].size()) dfs(gr[i][j],i,gr[i][j]);
	}
	rep(i,n){
		//rep(j,n) cout<<i+1<<' '<<j+1<<' '<<dp[i][j]<<endl;
	}
	rep(i,m){
		bool f=(dp[a[i]][b[i]]>=2);
		bool g=(dp[b[i]][a[i]]>=1);
		if(f==g) cout<<"same"<<endl;else cout<<"diff"<<endl;
	}
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

string s;
int a[30],b[30];
bool used[30];
string t="abcdefghijklmnopqrstuvwxyz";

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

	cin>>s;
	int sz=(int)s.size();
	
	if(sz<26) {
		REP(i,sz) used[s[i]-'a']=true;
		REP(i,26) {
			if(!used[i]) {
				cout<<s<<t[i]<<endl;
				return 0;
			}
		}
	}
	if(s=="zyxwvutsrqponmlkjihgfedcba") {
		cout<<-1<<endl;
		return 0;
	}
	REP(i,sz) a[i]=b[i]=s[i]-'a';
	next_permutation(b,b+sz);
	REP(i,sz) {
		if(a[i]!=b[i]) {
			REP(j,i+1) cout<<t[b[j]];
			cout<<endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);    
    int n = in.nextInt();
    int[] A = new int[n];
    for (int i = 0; n != 0; i++) {
      A[i] = in.nextInt();
      n--;
    }
     
    int q = in.nextInt();
    int[] M = new int[q];
    for (int i = 0; q != 0; i++) {
      M[i] = in.nextInt();
      q--;
    }
     
    for (int i = 0; i < M.length; i++) {
      System.out.println((dfs(0, A, 0, M[i])) ? "yes" : "no" );
    }
  }
  static boolean dfs(int p, int[] A, int t, int sum) {
    if (t < 0 ) return false;
    if (p == A.length) return t == sum;
    if (dfs(p + 1, A, t + A[p], sum)) return true;
    if (dfs(p + 1, A, t, sum))        return true;
    return false;
  }
}

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

#define ll long long
#define ld long double
#define pb push_back
#define x first
#define y second
#define sz(v) (int)(v.size())
#define all(v) v.begin(),v.end()

using namespace std;

int main()
{
    //freopen("test.in","r",stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    int n,m; cin>>n>>m;
    int a[n];
    int tot=0;
    for(int i=0;i<n;i++) {cin>>a[i];tot+=a[i];}
    sort(a,a+n);
    reverse(a,a+n);
    string ans="Yes";
    if(a[m-1]*4*m<tot) ans="No";
    cout<<ans;
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n,k,i,a[500000];
	cin>>n>>k;
	for(i=0;i<n;i++) cin>>a[i];
	for(i=k;i<n;i++) {
		if(a[i]>a[i-k]) cout<<"Yes\n";
		else cout<<"No\n";
	}	
}

Measured memory_bytes: 5228
#include <math.h>
#include <stdio.h>

int rel_l_l( double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3, double *x, double *y ) {
	double a, b, c, d;
	int rel;

	if ( x0 != x1 ) {
		a = ( y0 - y1 ) / ( x0 - x1 );
		b = ( x0 * y1 - x1 * y0 ) / ( x0 - x1 );
	}
	if ( x2 != x3 ) {
		c = ( y2 - y3 ) / ( x2 - x3 );
		d = ( x2 * y3 - x3 * y2 ) / ( x2 - x3 );
	}

	rel = 0;
	if ( x0 == x1 ) {
		*x = x0;
		if ( x2 == x3 )
			if ( x0 == x2 )
				rel = 3;
			else
				rel = 2;
		else {
			*y = c * *x + d;
			if ( y2 == y3 )
				rel = 1;
		}
	} else {
		if ( x2 == x3 ) {
			*x = x2;
			if ( y0 == y1 )
				rel = 1;
		} else
			if ( fabs( a - c ) < 1e-10 )
				if ( fabs( b - d ) < 1e-10 )
					rel = 3;
				else
					rel = 2;
			else {
				*x = ( -b + d ) / ( a - c );
				if ( fabs( a * c + 1.0 ) < 1e-10 )
					rel = 1;
			}
		*y = a * *x + b;
	}

	return rel;
}

int main( void ) {
	double xA, yA, xB, yB, xC, yC, xD, yD, x, y;
	
	while( scanf( "%lf %lf %lf %lf %lf %lf %lf %lf", &xA, &yA, &xB, &yB, &xC, &yC, &xD, &yD ) != EOF ) {
		int rel = rel_l_l( xA, yA, xB, yB, xC, yC, xD, yD, &x, &y );

		printf( "%s\n", rel == 1 ? "YES" : "NO" );
	}

	return 0;
}

Measured memory_bytes: 612
/* dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll ,ll>
#define vll          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,k,i,j;
	cin>>n>>k;
    ll ans=(n/k)*(n/k)*(n/k);
    if(k%2==0){
    	k/=2;
    	ans+=(n/k-n/(2*k))*(n/k-n/(2*k))*(n/k-n/(2*k));
    }
    cout<<ans;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using static System.Math;
using static System.Console;
class Simple
{
    int X, A, B;
    void Solve() {
        //input
        X = io.Int;
        A = io.Int;
        B = io.Int;
        //cal
        var ans = X - A - B * ((X - A) / B);
        //ret
        WriteLine(ans);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() { Solve(); io.writeFlush(); }
}
class SimpleIO
{
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] { ' ' };
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if (BufferCnt < nextBuffer.Length)
            return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while (st == "")
            st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


Measured memory_bytes: 11092
<?php
while (true) {
  list($h, $w) = explode(" ", trim(fgets(STDIN)));
  if (!$h) break;

  for ($i = 0; $i < $h; $i++) {
    for ($j = 0; $j < $w; $j++) echo "#";
    echo "\n";
  }

  echo "\n";
}



Measured memory_bytes: 9212
$n = gets.to_i
colors = gets.chomp.bytes
color_array = Array.new(3) { Array.new }
colors.each.with_index(1) do |color, index|
  case color
  when 82
    color_array[0] << index
  when 71
    color_array[1] << index
  when 66
    color_array[2] << index
  end
end

$ngs = Array.new($n + 1, 0)

def count_ngs(a, b)
  gap = b - a
  $ngs[((a + b) / 2)] += 1 if gap.even?
  $ngs[a - gap] += 1 if (a - gap) > 0
  $ngs[b + gap] += 1 if (b + gap) <= $n
end

color_array[0].each do |i1|
  color_array[1].each do |i2|
    if i1 > i2
      count_ngs(i2, i1)
    else
      count_ngs(i1, i2)
    end
  end
end

ans = color_array[0].size * color_array[1].size * color_array[2].size

color_array[2].each do |i|
  ans -= $ngs[i]
end

puts ans

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int> > f(n, vector<int>(10));
    vector<vector<int> > p(n, vector<int>(11));
    rep (i, n) {
        rep (j, 10) cin >> f[i][j];
    }
    rep (i, n) {
        rep (j, 11) cin >> p[i][j];
    }
    int ans = -Inf;
    FOR (k, 1, 1 << 10) {
        int tmp = 0;
        rep (i, n) {
            int cnt = 0;
            rep (j, 10) {
                if (f[i][j] && (k >> j & 1)) cnt++;
            }
            tmp += p[i][cnt];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N, M;
	std::cin >> N >> M;
	int64_t P[100000], Y[100000];
	for (int64_t i = 0; i < M; i++) {
		std::cin >> P[i] >> Y[i];
	}
	std::vector<int64_t> vec[100001];

	for (int64_t i = 0; i < M; i++) {
		vec[P[i]].push_back(Y[i]);
	}
	for (int64_t i = 0; i < N; i++) {
		std::sort(vec[i + 1].begin(), vec[i + 1].end());
	}
	for (int64_t i = 0; i < M; i++) {
		std::cout << std::setfill('0') << std::right << std::setw(6) << P[i];
		std::cout << std::setfill('0') << std::right << std::setw(6) << std::lower_bound(vec[P[i]].begin(), vec[P[i]].end(), Y[i]) - vec[P[i]].begin() + 1 << std::endl;
	}
	
}

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


Measured memory_bytes: 8576
open Batteries
let () =
  let h,w = Scanf.scanf "%d %d " (fun a b -> a,b) in
  let mat = Array.to_list @@ Array.init h (fun _ -> Scanf.scanf "%s " (fun a -> a )) in
  let tmp = List.fold_right (fun x y ->  x :: x :: y) mat [] in
  List.iter (Printf.printf "%s\n") tmp 


Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
using namespace std;
long dp[1<<17][3],a;
char op;
int n;
main()
{
	cin>>n>>dp[0][0];
	dp[0][1]=dp[0][2]=-1e18;
	for(int i=1;i<n;i++)
	{
		cin>>op>>a;
		if(op=='+')
		{
			for(int j=0;j<3;j++)dp[i][j]=dp[i-1][j]+(j%2?-a:a);
		}
		else
		{
			dp[i][0]=dp[i-1][0]-a;
			dp[i][1]=max(dp[i-1][1]+a,dp[i-1][0]-a);
			dp[i][2]=max(dp[i-1][2]+a,dp[i-1][1]+a);
		}
	}
	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	string s;
	cin >> s;
	s[0] = (s[0] + 1);
	cout << s << endl;
	return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int c = 0;
  for(int i = 0; i < 3; i++)
    if(s.at(i) == t.at(i))
      c++;
  cout << c << endl;
}

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

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr, class func> void array_output(itr start, itr goal, func out = [](itr x) { return x; } ){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr, class func> void nint_output(itr start, itr goal, func out = [](itr x) { return x; } ){ string ans; for(auto i = start; i != goal; i++){ ans += string(out(*i)) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)

int main(){
    int mountains[10];
    for(int i = 0; i < 10; i++){
        cin >> mountains[i];
    }
    sort(mountains, mountains + 10, greater<int>());
    cout << mountains[0] << endl;
    cout << mountains[1] << endl;
    cout << mountains[2] << endl;
}



Measured memory_bytes: 3108
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

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

  int k; cin >> k;
  int cur = 7;
  for (int i = 0; i < k; ++i) {
    if (cur % k == 0) {
      cout << i + 1 << endl; return 0;
    } else {
      cur *= 10;
      cur += 7;
      cur %= k;
    }
  }

  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 3608
// 二分探索木の挿入
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

#define MAX_N 30
//const int NIL = -1;

typedef struct node
{
    // 節点の値
    int key;
    // 節点の親
    struct node *parent;
    // 節点の左の子
    struct node *left;
    // 節点の右の子
    struct node *right;
}Node;

// グローバル変数の定義
Node *Tree;

void preorderTreeWalk(Node *Tree);
void inorderTreeWalk(Node *Tree);
void postorderTreeWalk(Node *Tree);

void insert(int num);

int main(void)
{

    int n, num;
    char str[10];

    cin >> n;

    for(int i = 0; i < n; i++)
    {
    	// 命令を取得
        scanf("%s", str);

        if( str[0] == 'i' )
        {
        	// --- 挿入の命令の時 ---

        	scanf("%d", &num);

            insert(num);
        }
        else
        {
        	// --- 表示の命令 ---

            inorderTreeWalk(Tree);
            printf("\n");
            preorderTreeWalk(Tree);
            printf("\n");
        }
    }

    return 0;
}

// 二分探索木の挿入関数
void insert(int num)
{
    Node *tree, *parent;
    Node *newNode = new Node;

    // 追加する要素の親
    parent = NULL;
    // 木の根 ( 先頭アドレス )
    tree = Tree;

    // 追加する要素の設定
    newNode->key = num;
    newNode->parent = NULL;
    newNode->left = NULL;
    newNode->right = NULL;

    while( tree != NULL )
    {
        // 親の候補の取得
    	parent = tree;

        if( newNode->key < tree->key )
        {
            // 左の子へ移動
        	tree = tree->left;
        }
        else
        {
            // 右の子へ移動
        	tree = tree->right;
        }
    }

    // 追加する要素の親を設定
    newNode->parent = parent;

    if( parent == NULL )
    {
        // 木が空の時
    	newNode->parent = NULL;
        // 木が空のなので, 実体を入れる
        Tree = newNode;

    }
    else if( newNode->key < parent->key )
    {
        // 左の子にする
    	parent->left = newNode;
    }
    else
    {
        // 右の子にする
    	parent->right = newNode;
    }

    return;
}

// 先行順巡回
// 根節点、左部分木、右部分木の順で節点を巡回
void preorderTreeWalk(Node *Tree)
{

    if( Tree == NULL )
    {
    	return;
    }

    printf(" %d", Tree->key);
    preorderTreeWalk(Tree->left);
    preorderTreeWalk(Tree->right);

    return;
}

int pre_right = 0;

// 中間順巡回
// 左部分木、根節点、右部分木の順で節点を巡回
void inorderTreeWalk(Node *Tree)
{

    if( Tree == NULL )
    {
    	return;
    }

    inorderTreeWalk(Tree->left);
    printf(" %d", Tree->key);
    inorderTreeWalk(Tree->right);

    return;
}

// 後行順巡回
// 左部分木、右部分木、根節点の順で節点を巡回
void postorderTreeWalk(Node *Tree)
{

    if( Tree == NULL )
    {
    	return;
    }

    postorderTreeWalk(Tree->left);
    postorderTreeWalk(Tree->right);
    printf(" %d", Tree->key);

    return;
}



Measured memory_bytes: 26616
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;

const int N = 100005;
const int inf = 1000000000;
template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}

template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

struct edge {
	int to, nxt;
} tree[N << 1];
int n, head[N], deg[N], w[N], f[N], cnt = 0, ans = 0;
char str[N];
void addedge (int u, int v) {
	edge e = {v, head[u]};
	tree[head[u] = cnt++] = e;
}

bool vis[N];
queue<int> q;
void init () {
	for (int i = 1; i <= n; i++) vis[i] = false;
	for (int i = 1; i <= n; i++) {
		if (deg[i] <= 1 && str[i - 1] == 'B') q.push(i);
	}
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		if (vis[u]) continue;
		vis[u] = true;
		for (int i = head[u]; ~i; i = tree[i].nxt) {
			int v = tree[i].to;
			if (!vis[v]) {
				if (--deg[v] <= 1 && str[v - 1] == 'B') q.push(v);
			}
		}
	}
}

void dfs (int u, int fa) {
	int fi = w[u], se = inf;
	f[u] = w[u];

	for (int i = head[u]; ~i; i = tree[i].nxt) {
		int v = tree[i].to;
		if (v != fa && !vis[v]) {
			dfs(v, u), f[u] = min(f[u], w[u] + f[v]);
			if (w[u] + f[v] < fi) se = fi, fi = w[u] + f[v];
			else if (w[u] + f[v] < se) se = w[u] + f[v];
		}
	}
	ans = min(ans, fi + se - w[u]);
}

int main () {
	read(n);
	for (int i = 1; i <= n; i++) head[i] = -1, deg[i] = 0;
	for (int i = 1; i < n; i++) {
		int u, v;
		read(u), read(v);
		addedge(u, v), addedge(v, u);
		deg[u]++, deg[v]++;
	}
	scanf("%s", str);
	init();
	
	int pos = 0;
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) pos = i;
	}
	if (pos) {
		for (int i = 1; i <= n; i++) {
			if (!vis[i]) {
				if (deg[i] & 1) w[i] = (str[i - 1] == 'B') ? -2 : 0;
				else w[i] = (str[i - 1] == 'W') ? -2 : 0;
			}
		}
		dfs(pos, 0);

		ans -= 2;
		for (int i = 1; i <= n; i++) {
			if (!vis[i]) {
				ans += 2;
				if (deg[i] & 1) ans += (str[i - 1] == 'B');
				else ans += (str[i - 1] == 'W');
			}
		}
	}
	write(ans), putchar('\n');
	return 0;
}

Measured memory_bytes: 11008
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e5+5;
const LL mod=1e9+7;
LL read() {
	char ch=getchar();LL x=0,f=1;
	while(ch<'0' || ch>'9')	{if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int gcd_(int a,int b) {return b==0?a:gcd_(b,a%b);}
LL fpow(LL a,LL b) {
	LL res=1;
	while(b) {
		if(b&1) res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
LL Cnr(LL r,LL n) {
	LL res=1;
	for(LL i=1,j=n;i<=r;++i,--j) {
		res=(res*j)%mod;
		res=(res*fpow(i,mod-2))%mod;
	}
	return res;
}
int main() {
//	cout<<"Accepted!\n";
	LL n,a,b;
	n=read();
	a=read();
	b=read();
	LL sum=(fpow(2,n)+mod-1)%mod;
//	cout<<sum<<endl;
	LL aa,bb;
	aa=Cnr(a,n);
	bb=Cnr(b,n); 
//	cout<<aa<<"\n"<<b<<"\n"; 
	sum=(sum+mod-aa+mod-bb)%mod;
	printf("%lld",sum);
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll mod = 1e9+7;
#define rep(i,n) for(int i = 0;i<n;i++)

int main(){
	int n,k;
	cin >> n>>k;
	vector<int>h(n);
	rep(i,n)cin >> h[i];

	vector<int> cost(n,INF);
	cost[0] = 0;

	for(int i = 0; i<n; i++){
		for(int j = min(i+k,n-1); j>=i+1;j--){
			cost[j] = min(cost[j], cost[i]+abs(h[i]-h[j]));
		}
	}
	cout << cost[n-1] << endl;

	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int ans = 1;

        for(int i=0; i<N; i++){
            if(ans<=K){
                ans *= 2;
            }
            else{
                ans += K;
            }
        }
        System.out.println(ans);
    }
}

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

using namespace std;

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

    int N, K;
    cin >> N >> K;
    vector<int> D(K), forb(10, 0);
    for (int i = 0; i < K; ++i) {
        cin >> D[i];
        forb[D[i]] = 1;
    }
    int smallest_ok = 9, smallest_larg1 = 9;
    for (int i = 9; i >= 0; --i) {
        if (!forb[i]) {
            smallest_ok = i;
            if (i > 0) smallest_larg1 = i;
        }
    }
    string s(to_string(N));
    bool larger = false;
    for (int i = 0; i < (int)s.size(); ++i) {
        if (forb[s[i] - '0'] || larger) {
            if (larger) {
                s[i] = smallest_ok + '0';
            } else {
                bool success = false;
                for (int k = i; !success && k >= 0; --k) {
                    for (int j = s[i] - '0' + 1; !success && j <= 9; ++j) {
                        if (!forb[j]) {
                            s[k] = j + '0';
                            success = true;
                        }
                    }
                }
                if (!success) {
                    string tmp;
                    tmp += (smallest_larg1 + '0');
                    tmp += s;
                    s = tmp;
                    i = 0;
                }
                larger = true;
            }
        }
    }
    cout << s << "\n";

    return 0;
}

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

int main() {
  int N; cin >> N;
  long long ans = 1;
  bool over = false;
  for (int i = 0; i < N; i++) {
    long long A; cin >> A;
    if (A == 0) {
      ans = 0;
      over = false;
      break;
    }
    if (A/10000 * ans/10000 > 10000000000) {
      over = true;
    }
    ans *= A;
    if (ans > 1000000000000000000) {
      over = true;
    }
  }
  if (over) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 3636
from itertools import accumulate
N = int(input())
A = list(map(int, input().split()))

ans = 10 ** 18


A = tuple(accumulate(A, initial=0))
i = 1
j = 3


for mid in range(2, N - 1):
    # 左側をできるだけ等分
    b = A[i] - A[0]
    c = A[mid] - A[i]
    while i + 1 < mid and abs(b - c) > abs(A[mid] + A[0] - 2 * A[i+1]):
        i += 1
        b = A[i] - A[0]
        c = A[mid] - A[i]
    # 右側をできるだけ等分
    j = max(j, mid + 1)
    d = A[j] - A[mid]
    e = A[N] - A[j]
    while j + 1 < N and abs(d - e) > abs(A[N] + A[mid] - 2 * A[j+1]):
        j += 1
        d = A[j] - A[mid]
        e = A[N] - A[j]

    res = max(b, c, d, e) - min(b, c, d, e)
    ans = min(ans, res)

print(ans)

Measured memory_bytes: 32884
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Deque<Integer> deque = new ArrayDeque<Integer>();

        for(int i = 0; i < n; i++) {
        	int query = sc.nextInt();
       		int d = sc.nextInt();

        	switch(query) {
        	case 0:
        		int x = sc.nextInt();
        		if(d == 0) deque.addFirst(x);
        		else deque.addLast(x);
        		break;

        	case 1:
        		Iterator<Integer> iterator = deque.iterator();
        		for(int j = 0; j < d; j++) {
        			iterator.next();
        		}
        		System.out.println(iterator.next());
        		break;

        	case 2:
        		if(d == 0) deque.removeFirst();
        		else deque.removeLast();
        		break;
        	}
        }
	}
}



Measured memory_bytes: 302456
#include<bits/stdc++.h>
using namespace std;
struct vac{
	long long int a;
	long long int b;
	long long int c;
};
vector<vac> v;
long long int mem[100005][5];
long long int dp(long long int n,long long int ch)
{
	if(mem[n][ch]!=-1)
		return mem[n][ch];
	if(n==1)
	{
		if(ch==1)
			return (v[n].a);
		if(ch==2)
			return (v[n].b);
		if(ch==3)
			return (v[n].c);
	}
	if(ch==1)
		mem[n][ch]= max(dp(n-1,2)+v[n].a,dp(n-1,3)+v[n].a);
	if(ch==2)
		mem[n][ch]= max(dp(n-1,1)+v[n].b,dp(n-1,3)+v[n].b);
	if(ch==3)
		mem[n][ch]= max(dp(n-1,1)+v[n].c,dp(n-1,2)+v[n].c);
	return mem[n][ch];
}
int main()
{
	long long int n;
	cin>>n;
	vac x;
	x.a=0;
	x.b=0;
	x.c=0;
	v.push_back(x);
	memset(mem,-1,sizeof mem);
	for(long long int i=0;i<n;i++)
	{
		vac x;
		cin>>x.a;
		cin>>x.b;
		cin>>x.c;
		v.push_back(x);
	}
	cout<<max(dp(n,1),max(dp(n,2),dp(n,3)));
	return 0;
}

Measured memory_bytes: 11760
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <string.h>
#include <stdlib.h>

using namespace std;
// vector push_back push front top empty pop make_pair long long insert begin end  
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair <int,int> > vpi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define RB rbegin()
#define E end()
#define RE rend()
#define Z size()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define L length()
#define show(a) cerr << " *** " << a << endl;
#define show1(a) cerr << " /// " << a << endl;
#define valid(a,b,c) (a >= b && a < c ? 1 : 0)
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int mod = (int)1e9 + 7;
ll gcd(ll a, ll b) {return (b==0? a:gcd(b,a%b));}
ll egcd(ll a, ll b, ll & x, ll & y) {if (a == 0){x = 0;y = 1;return b;}ll x1, y1;ll d = egcd(b % a, a, x1, y1);x = y1 - (b / a) * x1;y = x1;return d;}
ll mbinp(ll a, ll b){a %= mod;if (b == 0)return 1;ll ans = mbinp(a, b/2);ll tmp = (ans * ans) % mod;if (b % 2)return ((tmp * a) % mod);return ((tmp) % mod);}
ll binp(ll a, ll b){if (b == 0)return 1;ll ans = binp(a, b/2);ll tmp = (ans * ans);if (b % 2)return ((tmp * a));return ((tmp));}

const int maax  = 3050;
int dp[maax][maax];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string str;
	string ptr;
	cin >> str >> ptr;
	REP(i,0,ptr.L)
	{
		REP(j,0,str.L)
		{
			if (str[j] ==ptr[i])
				dp[i+1][j+1] = dp[i][j] + 1;
			else
				dp[i+1][j+1] = max({dp[i][j+1],dp[i+1][j]});
		}
	}
	/*REP(i,0,ptr.L+1)
	{
		REP(j,0,str.L+1)
			cout  << dp[i][j] << " ";
		cout << endl;
	}*/
	int j = str.L;
	int i = ptr.L;
	string ans;
	while (i > 0 && j > 0)
	{
		if (dp[i][j] == 0)
			break;
		int od = i;
		while (i - 1 > 0 && dp[i-1][j] == dp[od][j])
			i--;
		int old = j;
		while (j - 1 > 0 && dp[i][j-1] == dp[i][old])
			j--;
		ans += str[j-1];
		i--;
		j--;
	}
	reverse(ans.B,ans.E);
	cout << ans;
}


Measured memory_bytes: 35968