akhauriyash/Code-Regression huggingface dataset:
#include <CodeforcesSolutions.h>
#include <ONLINE_JUDGE <solution.cf(contestID = "1362",problemID = "B",method = "GET")>.h>
"""
    Author : thekushalghosh
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    k = inp()
    s = insr()
    if len(s) <= k:
        print(s)
    else:
        print(s[:k] + "...")
                
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

def power_two(n):
    if n == 1:
        return(True)
    sttr = str(n)
    len_str = len(sttr)
    sttr = list(sttr)
    num = 0
    if (len_str == 1 and sttr[len_str - 1] == '1'): 
        return(False)
    while (len_str != 1 or sttr[len_str - 1] != '1'):
        if ((ord(sttr[len_str - 1]) - ord('0')) % 2 == 1):
            return(False)
        j = 0; 
        for i in range(len_str):  
            num = num * 10 + (ord(sttr[i]) - ord('0')); 
            if (num < 2): 
                if (i != 0):  
                    sttr[j] = '0'
                    j += 1
                continue
  
            sttr[j] = chr((num // 2) + ord('0'))
            j += 1; 
            num = (num) - (num // 2) * 2
        len_str = j
    return(True)

def log_two(n): 
    return(math.log(n) / math.log(2))

#-----------------------------------------------------------------------#
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()

Measured memory_bytes: 62864
s1=int(input())
s2=int(input())
s3=int(input())
s4=int(input())
s5=int(input())
s6=int(input())
s7=int(input())
s8=int(input())
s9=int(input())
s10=int(input())

print(s1+s2+s3+s4+s5+s6+s7+s8+s9+s10)




Measured memory_bytes: 5584
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long
#define ld long double
#define PB push_back
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define pii pair <int , int>
#define pll pair <long long , long long>
#define FAST ios::sync_with_stdio(false);cin.tie(0);
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

const ll maxn = 2e5 + 10 , N = 60000 + 20 , mod = 1e9 + 7 , INF = 1e9 , lg = 32;

ll a[maxn];

int main() {
    FAST
    ll x , k , d;
    cin >> x >> k >> d;
    if(x < 0) {x *= -1;}
    ll m = x % d;
    ll q = x / d;
    ll can = min(k , q);
    k -= can;
    x -= (can * d);
    if((k % 2) == 0) {
        cout << x << endl;
    }
    else {
        ll p = abs(x - d);
        cout << p << endl;
    }
}


Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>

long int arr[1000005], n;

void insert(int num,int loc)
{
	int par;
	while(loc>0)
	{
		par=(loc-1)/2;
		if(num<=arr[par])
		{
			arr[loc]=num;
			return;
		}
		arr[loc]=arr[par];
		loc=par;
	}
	
	arr[0]=num; 
}


void Delete(int num)
{
	int left,right,i,temp,par;

	for(i=0;i<n;i++)
	{
		if(num==arr[i])
		break;
	}
	
	if( num!=arr[i] )
	{
		return;
	}
	
	arr[i]=arr[n-1];
	n=n-1;
	par=(i-1)/2;
	   /*find parent of node i */
	if(arr[i] > arr[par])
	{
		insert( arr[i],i);
		return;
	}
	
	left=2*i+1;  /*left child of i*/
	right=2*i+2; /* right child of i*/
	
	while(right < n)
	{
		if( arr[i]>=arr[left] && arr[i]>=arr[right] )
			return;
		if( arr[right]<=arr[left] )
		{
			temp=arr[i];
			arr[i]=arr[left];
			arr[left]=temp;
			i=left;
		}
		else
		{
			temp=arr[i];
			arr[i]=arr[right];
			arr[right]=temp;
			i=right;
		}
		left=2*i+1;
		right=2*i+2;
	}
	
	if( left==n-1 && arr[i]<arr[left] ) /* right==n */
	{	temp=arr[i];
		arr[i]=arr[left];
		arr[left]=temp;
	}
}


int main()
{
	n = 0;
	char kata[50];
	long long int angka;
	
	
	do
	{
		scanf("%s",&kata); getchar();		
		if(strcmp(kata,"insert") == 0)
		{
			scanf("%lld",&angka); getchar();
			insert(angka,n);
			n++;
			//for (int i=0;i<n;i++) printf("{%d} ",arr[i]);
		}
	
		if (strcmp(kata,"extract") == 0)
		{
			if(n>0)
			{
			printf("%ld\n",arr[0]);
			Delete(arr[0]);
			//n--;
		    }
		}
		
	}while(strcmp(kata,"end")!=0);	
	
	
	return 0;
}



Measured memory_bytes: 10380
import sys
input = sys.stdin.readline

h, w = [int(x) for x in input().split()]
a = []
for _ in range(h):
    b = list(input().rstrip())
    if '#' in b:
        a.append(b)
h = len(a)
c = [1]*w
for i in range(w):
    flag = 1
    for j in range(h):
        if a[j][i] == "#":
            flag = 0
            break
    if flag:
        c[i] = 0
ans = []
for i in range(h):
    res = []
    for j in range(w):
        if c[j]:
            res.append(a[i][j])
    ans.append("".join(res))
for i in ans:
    print(i)



Measured memory_bytes: 3188
n, t = [int(_) for _ in input().split()]

ab = []

for i in range(n):
    ab_ = [int(_) for _ in input().split()]
    ab.append(ab_)

ab.sort()

dp = [-1 for _ in range(6000)]
dp[0] = 0
dp2 = dp[:]


dplist = [0]

for i in range(n):

    dp_trans = ab[i][0]
    dp_delicious = ab[i][1]

    for j in range(t):
        if dp[j] != -1:
            dp2[j+dp_trans] = max(dp[j+dp_trans], dp[j] + dp_delicious)
    dp = dp2[:]

print(max(dp))

Measured memory_bytes: 48088
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	unsigned long long x,y,Y;
	cin>>x>>y;
	if(x==y){
		cout<<"-1"<<endl;
	}
	else{
		Y=y;
		for(;;){
			Y=Y+y;
			if(Y>=x)break;
		}
		if(Y==x)cout<<"-1"<<endl;
		else cout<<x<<endl;
	}

}

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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#define REP(a, b) for (int a = 0; a < (b); a++)
#define FOR(a, b, c) for (int a = (b); a <= (c); a++)
#define REPD(a, b) for (int a = (b) - 1; a >= 0; a--)
#define FORD(a, b, c) for (int a = (b); a >= (c); a--)

#define MIN(a, b) (a) = min((a), (b))
#define MAX(a, b) (a) = max((a), (b))

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2> &p) {
  return is >> p.fi >> p.se;
}

const int N = 2e5 + 5;

ll bit[N];

ll query(int x) {
  ll ret = 0;
  for (int i = x + 1; i > 0; i -= i & -i) MAX(ret, bit[i]);
  return ret;
}

void update(int x, ll v) {
  for (int i = x + 1; i < N; i += i & -i) MAX(bit[i], v);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vi h(n), a(n);
  REP(i, n) cin >> h[i];
  REP(i, n) cin >> a[i];
  V<ll> dp(n);
  REP(i, n) {
    dp[i] = query(h[i] - 1) + a[i];
    update(h[i], dp[i]);
  }
  cout << *max_element(ALL(dp)) << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <tuple>
#include <iomanip>


using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}



int main(void){
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++){
		cin >> v[i];
	}

	vector<int> c(n);
	for (int i = 0; i < n; i++){
		cin >> c[i];
	}

	int ans = 0;
	for (int bit = 0; bit < (1 << n); bit++){
		vector<int> tmp;
		for (int i = 0; i < n; i++){
			if (bit & (1 << i)){
				tmp.push_back(i);
			}
		}
		int value = 0;
		int cost = 0;
		for (int i = 0; i < tmp.size(); i++){
			value += v[tmp[i]];
			cost += c[tmp[i]];
		}

		ans = max(ans, value - cost);

	}

	cout << ans << endl;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V
import Debug.Trace as De

-- 入出力ライブラリ（コピペ） --
readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

-- 関数 --
func :: Int -> V.Vector Int -> [Int]
func nn av = solve 0 0 0
  where
    solve :: Int -> Int -> Int -> [Int]
    solve n px qx
      | n == 310000 = []
      | px == nn = ((px-qx):(solve (n+1) px px))
      | (av V.! px) /= n = ((px-qx):(solve (n+1) px px))
      | (av V.! qx) == n = solve n (px+1) qx

get1 :: [Int] -> Int
get1 x = (x!!0)

get2 :: [Int] -> Int
get2 x = (x!!1)

hantei :: (Int, Int) -> Bool
hantei x
  | fst(x) == 0 = True
  | otherwise = False

reflect :: [Int] -> Int -> [Int]
reflect x border = map hikizan x
  where
    hikizan :: Int -> Int
    hikizan t = t - border

tansaku :: Int -> V.Vector Int -> V.Vector Int -> V.Vector Int -> V.Vector Int -> Int
tansaku n xv yv ix iy = solve 0
  where
    solve :: Int -> Int
    solve pos
      | pos == n = 0
      | otherwise = newnum + (solve (pos+1))
        where newnum = if ((ix V.! (xv V.! pos)) == 1 && (iy V.! (yv V.! pos)) == 1) then 1 else 0

main = do
  -- 入力 --
  [h, w, n] <- (map read . words) <$> getLine
  a <- getIntNList n
  
  -- パース --
  let x = map get1 a
  let y = map get2 a
  let xw = (V.fromList x) :: V.Vector Int
  let yw = (V.fromList y) :: V.Vector Int
  let xs = sort x
  let ys = sort y
  let xv = (V.fromList xs) :: V.Vector Int
  let yv = (V.fromList ys) :: V.Vector Int
  
  -- 本質部分 --
  let numx = func n xv
  let numy = func n yv
  let maxx = maximum numx
  let maxy = maximum numy
  let evalx = reflect numx maxx
  let evaly = reflect numy maxy
  let ex = zip evalx [0..310000]
  let ey = zip evaly [0..310000]
  let fx = filter hantei ex
  let fy = filter hantei ey
  let gx = snd (unzip fx)
  let gy = snd (unzip fy)
  let gx2 = (V.fromList gx) :: V.Vector Int
  let gy2 = (V.fromList gy) :: V.Vector Int
  
  -- 探索パート --
  let szx = length gx
  let szy = length gy
  let hx = func szx gx2
  let hy = func szy gy2
  let ix = (V.fromList hx) :: V.Vector Int
  let iy = (V.fromList hy) :: V.Vector Int
  let ret = tansaku n xw yw ix iy
  
  -- 答えを出力 --
  let ans = if (ret == (szx * szy)) then (maxx + maxy - 1) else (maxx + maxy)
  putStrLn $ show ans

Measured memory_bytes: 268232
n,m = map(int,input().split())
mod = 10**9+7

fact = [1,1]
finv = [1,1]
inv = [0,1]
 
for i in range(2,max(n,m)+5):
    fact.append((fact[-1]*i)%mod)
    inv.append((inv[mod%i]*(mod-mod//i))%mod)
    finv.append((finv[-1]*inv[-1])%mod)
 
def nCr(n,r,mod):
    if r > n:
        return 0
    else: 
        return fact[n]*finv[r]*finv[n-r]%mod

def nPr(n,r,mod):
    if r > n:
        return 0
    else: 
        return fact[n]*finv[n-r]%mod


ans = 0
for i in range(n+1):
    now = nCr(n,i,mod)
    now *= nPr(m-i,n-i,mod)
    now %= mod
    if i%2:
        now = -now
    ans += now
    ans % mod
ans *= nPr(m,n,mod)
ans %= mod
print(ans)

Measured memory_bytes: 68628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t MOD=1000000007;
const long long INF = 1LL<<60;

int main() {
  int64_t N; cin>>N;
  if(N%2==1) cout<<0;
  else{
    int64_t ans=0;
    ans+=N/10;
    N/=10;
    while(N>=5){
      N/=5;
      ans+=N;
    }
    cout<<ans;
  }
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n, match = 0;
	cin >> n;
	for(int i=0;i<n;i++) {
		int t;
		cin >> t;
		if(t == match+1)
			match++;
	}
	if(match == 0) cout << -1 << endl;
	else cout << n - match << endl;
}





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

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> vc;
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        vc.push_back(a);
    }

    int cnt = 0;
    int index = 1;
    bool ok = false;
    while (cnt < n) {
        index = vc[index - 1];
        ok = index == 2;
        ++cnt;
        if (ok == true) break;
    } 

    cout << (ok ? cnt : -1) << endl;

    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>

using LL = long long;
using ULL = unsigned long long;

using namespace std;

int main()
{
    string s, t;
    vector<string> temp;

    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());

    temp.emplace_back(s);
    temp.emplace_back(t);
    sort(temp.begin(), temp.end());

    if (temp[0] == s && temp[1] != s)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    int c[N];
    vector<int> a(M), b(M);
    for (int i = 0; i < M; i++)
    {
        cin >> a.at(i) >> b.at(i);
    }
    for (int i = 0; i < N; i++)
    {
        c[i] = 0;
        for (int j = 0; j < M; j++)
        {
            if (a.at(j) == i + 1 || b.at(j) == i + 1)
            {
                c[i] += 1;
            }
        }
        cout << c[i] << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	void run(){
		boolean[] p=new boolean[2000000];
		Arrays.fill(p,true);
		p[0]=p[1]=false;
		for(int i=2;i<p.length;i++){
			if(p[i]){
				for(int j=i*2;j<p.length;j+=i){
					p[j]=false;
				}
			}
		}
		for(;;){
			int m=sc.nextInt();
			if(m==0){
				break;
			}
			int ans=0;
			for(int i=m;i>=0&&!p[i];i--){
				ans++;
			}
			for(int i=m;i<p.length&&!p[i];i++){
				ans++;
			}
			System.out.println(""+ans);
		}
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 14000
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a1;
		int a2;
		int a3;

		int HUNDRED = 100;

		boolean flag = false;

		int c[][] = new int[3][3];

		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {

				c[i][j] = sc.nextInt();

			}
		}

		for (a1 = 0; a1 <= HUNDRED && !flag; a1++) {
			int b1 = c[0][0] - a1;
			int b2 = c[0][1] - a1;
			int b3 = c[0][2] - a1;

			for (a2 = 0; a2 <= HUNDRED && !flag; a2++) {

				if (c[1][0] == a2 + b1 && c[1][1] == a2 + b2 && c[1][2] == a2 + b3) {

					for (a3 = 0; a3 <= HUNDRED && !flag; a3++) {
						if (c[2][0] == a3 + b1 && c[2][1] == a3 + b2 && c[2][2] == a3 + b3) {
							flag = true;
						}
					}
				}
			}
		}

		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();

	}
}

Measured memory_bytes: 23764
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		  try(Scanner sc = new Scanner(System.in)) {
			  while(sc.hasNext()) {
				  String str=sc.next();
				  String s;
				  int joicount=0, ioicount=0;
				  for(int i=0; i<str.length()-2; i++) {
					  s=str.substring(i, i+3);
					  if(s.equals("JOI")) joicount++;
					  else if(s.equals("IOI")) ioicount++;
				  }
				  
				  System.out.println(joicount);
				  System.out.println(ioicount);
			  }
		}
	}
}



Measured memory_bytes: 28200
def get_digits_sum(num):
    result = 0
    while num > 0:
        result += num % 10
        num //= 10
    return result


def main():
    NUMBER = int(input())
    digits_sum = get_digits_sum(NUMBER)
    print("Yes" if not NUMBER % digits_sum else "No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

struct Mo {
  static constexpr int MAX_N = 512345;
  int left[MAX_N], right[MAX_N], order[MAX_N];
  int width;
  int nl, nr, ptr, li, sz;
  Mo(int n) : width((int)sqrt(n)), nl(0), nr(0), ptr(0), li(0) {}
  /* [l, r) */
  void insert(int l, int r) {
    left[li] = l;
    right[li++] = r;
  }

  void build() {
    iota(order, order + li, 0);
    sort(order, order + li, [&](int a, int b) {
      const int ab = left[a] / width, bb = left[b] / width;
      return ab != bb ? ab < bb
                      : (ab & 1 ? right[a] < right[b] : right[b] < right[a]);
    });
  }

  inline int process() {
    if (ptr == li) return (-1);
    const auto id = order[ptr];
    while (nl > left[id]) add(--nl);
    while (nr < right[id]) add(nr++);
    while (nl < left[id]) del(nl++);
    while (nr > right[id]) del(--nr);
    return (order[ptr++]);
  }
  inline void add(int idx);
  inline void del(int idx);
};

int c[512345];
int cnt[512345];
int sum;

void Mo::add(int idx) {
  if (cnt[c[idx]]++ == 0) sum++;
}

void Mo::del(int idx) {
  if (--cnt[c[idx]] == 0) sum--;
}

int ans[512345];

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  for (int i = 0; i < N; i++) cin >> c[i];
  Mo mo(N);
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    mo.insert(--l, r);
  }
  mo.build();
  for (int i = 0; i < Q; i++) {
    int idx = mo.process();
    ans[idx] = sum;
  }
  for (int i = 0; i < Q; i++) printf("%d\n", ans[i]);
  return 0;
}


Measured memory_bytes: 15504
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;inline int inn() { int x;scanf("%d",&x);return x; }const int N=270000,LOG=20;int x[N],v[N],L[LOG][N],R[LOG][N],val[N],Lf[N],Rf[N];
int main()
{
    int n=inn(),k=0;v[0]=inn();rep(i,1,n) x[i]=inn();while(v[k]) v[k+1]=v[k]>>1,k++;int all=(1<<k)-1;
    rep(i,0,k)
    {
        L[i][1]=1;for(int j=1+1;j<=n;j++) if(x[j]-x[j-1]<=v[i]) L[i][j]=L[i][j-1];else L[i][j]=j;
        R[i][n]=n;for(int j=n-1;j>=0;j--) if(x[j+1]-x[j]<=v[i]) R[i][j]=R[i][j+1];else R[i][j]=j;
    }
    rep(i,1,all) Lf[i]=1,Rf[i]=n;Lf[0]=0,Rf[0]=n+1;
    rep(i,0,all) rep(j,1,k) if(!((i>>(j-1))&1)) Lf[i|(1<<(j-1))]=max(Lf[i|(1<<(j-1))],R[j][Lf[i]+1]),Rf[i|(1<<(j-1))]=min(Rf[i|(1<<(j-1))],L[j][Rf[i]-1]);
    rep(i,0,n+1) val[i]=n+n;rep(i,0,all) val[Lf[i]]=min(val[Lf[i]],Rf[all^i]);for(int i=n;i>=0;i--) val[i]=min(val[i],val[i+1]);
    rep(i,1,n) printf(val[L[0][i]-1]<=R[0][i]+1?"Possible\n":"Impossible\n");return 0;
}

Measured memory_bytes: 49536
n = int(input())
h = list(map(int, input().split()))
D = [0] * n
D[0] = 0
D[1] = abs(h[1] - h[0])
for i in range(2, n):
    x1 = D[i - 1] + abs(h[i] - h[i - 1])
    x2 = D[i - 2] + abs(h[i] - h[i - 2])
    D[i] = min(x1, x2)
print(D[n - 1])

Measured memory_bytes: 13928
import math

N = int(input())
S = [0] * N
for i in range(N):
    S[i] = sorted(str(input()))

Sum = 0
hoge = 1

S.sort()

for i in range(N-1):
    if S[i] == S[i+1]:
        hoge += 1
    if (S[i] != S[i+1] or i == N-2) and hoge != 1:
        #Sum += math.factorial(hoge) // (math.factorial(hoge - 2) * math.factorial(2))
        Sum += hoge*(hoge-1)//2
        hoge = 1

print(Sum)


Measured memory_bytes: 94028
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <utility>
#include <map>
#include <functional>
#include <initializer_list>
using namespace std;

typedef long long int ll;

int main(){
    ll N, K, a, b;
    cin >> N >> K;
    map<ll, ll> A;
    for(int i=0; i<N; i++){
        cin >> a >> b;
        A[a] += b;
        }
    ll Count=0;
    for(int i=1; i<10*10*10*10*10+1; i++){
        if(A.count(i) != 0){
            Count += A[i];
            if(Count >= K){
                cout << i;
                break;
                }
            }
        }
}

Measured memory_bytes: 4224
n = int(input())
powof10 = 1
powof9 = 1
powof8 = 1
MOD = 10**9+7
for _ in range(n):
    powof10 *= 10
    powof10 %= MOD
    powof9 *= 9
    powof9 %= MOD
    powof8 *= 8
    powof8 %= MOD
print((powof10-2*powof9+powof8) % MOD)


Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

bool can_be_red[100000];
int ball_num[100000];
int main(){
    int N;
    int M;
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        ball_num[i] = 1;
    }
    can_be_red[0] = true;
    for(int i = 0; i < M; i++){
        int x;
        int y;
        cin >> x >> y;
        if(can_be_red[x - 1]){
            if(ball_num[x - 1] > 1){
                can_be_red[x - 1] = true;
                can_be_red[y - 1] = true;
            } else {
                can_be_red[x - 1] = false;
                can_be_red[y - 1] = true;
            }
        }
        ball_num[x - 1] --;
        ball_num[y - 1] ++;
        /* 
        for(int i = 0; i < N; i++){
            cout << can_be_red[i] << " ";
        }
        cout << endl;
        */
    }
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(can_be_red[i]){
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    H, W = li_input()
    C = [input().split() for _ in range(H)]

    for c in C:
        print(c[0])
        print(c[0])


main()


Measured memory_bytes: 4724
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#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 EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

LL tb[100010];

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

		if (a[i] - 1 >= 0) {
			tb[a[i] - 1]++;
		}
		
		tb[a[i]]++;

		tb[a[i] + 1]++;
	}


	LL ans = 1;
	for (int i = 0; i < 100010; i++) {
		ans = max(ans, tb[i]);
	}

	cout << ans << endl;

	return 0;
	
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i,N) cin >> H[i];
    for(int i=N-1;i>0;i--){
        if(H[i]-H[i-1]<-1){
            cout << "No" << endl;
            return 0;
        }else if(H[i]-H[i-1]==-1){
            H[i-1]--;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int n;
    cin >> n;
    vector<ll> a(3*n);
    ll sum1 = 0;
    ll sum2 = 0;
    priority_queue<ll, vector<ll>, greater<ll>> que1;
    priority_queue<ll> que2;
    for (int i = 0; i < 3*n; ++i) {
        cin >> a[i];
        if(i < n){
            sum1 += a[i];
            que1.push(a[i]);
        }
        if(2*n <= i){
            sum2 += a[i];
            que2.push(a[i]);
        }
    }

    vector<ll> v(n+1, 0);
    v[0] = sum1;
    v[n] = -sum2;
    for (int i = 0; i < n; ++i) {
        que1.push(a[n + i]);
        que2.push(a[2*n - i - 1]);
        sum1 += a[n+i];
        sum2 += a[2*n-i-1];
        sum1 -= que1.top();
        sum2 -= que2.top();
        que1.pop();
        que2.pop();
        v[i+1] += sum1;
        v[n-i-1] -= sum2;
    }
    ll res = -1e18;
    for (int i = 0; i < n+1; ++i) {
        res = max(res, v[i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 5108
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] count = new int[N];
        for(int i=1;i<=N;i++){
            int x = i;
            while(i != 0){
                if(x % 2 == 0){
                    count[i-1]++;
                    x = x / 2;
                }
                else{
                    break;
                }
            }
        }
        int max = count[0];
        int soeji = 0;
        for(int i = 1;i< N;i++){
            if(count[i] > max){
                max = count[i];
                soeji = i;
            }
        }
        System.out.println(soeji+1);
    }
}


Measured memory_bytes: 22100
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_map>
using namespace std;

void solve() {
    int r; cin >> r;
    cout << 3 * pow(r,2) << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

const int Cin()
{
    int n;
    cin >> n;
    return n;
}

class Mod
{
    LLONG m_mod;
    vector<LLONG> m_fac;
    vector<LLONG> m_ifac;

public:
    Mod(const int max, const LLONG mod)
    {
        m_mod = mod;
        m_fac = vector<LLONG>(max + 1);
        m_ifac = vector<LLONG>(max + 1);
        m_fac[0] = m_ifac[0] = 1;
        for (int i = 0; i < max; ++i)
        {
            m_fac[i + 1] = m_fac[i] * (i + 1) % mod;    // n! (mod M)
            m_ifac[i + 1] = m_ifac[i] * ModPow(i + 1, mod - 2) % mod;   // k!^(M-2) (mod M)
        }
    }

    const LLONG ModSubtract(LLONG a, LLONG b) const
    {
        LLONG diff = a - b;
        return diff >= 0 ? diff : diff + m_mod;
    }

    const LLONG ModMulti(LLONG a, LLONG b) const
    {
        LLONG prod = a * b % m_mod;
        return prod >= 0 ? prod : prod + m_mod;
    }

    const LLONG ModDiv(LLONG a, LLONG b) const
    {
        LLONG c = m_mod, u = 1, v = 0;
        while (c)
        {
            LLONG t = b / c;
            b -= t * c; swap(b, c);
            u -= t * v; swap(u, v);
        }
        u %= m_mod;
        if (u < 0) u += m_mod;
        return (a % m_mod) * u % m_mod;
    }

    const LLONG ModPow(LLONG x, LLONG n) const
    {
        LLONG ret = 1;
        while (n != 0)
        {
            if (n & 1) ret = ret * x % m_mod;
            x = x * x % m_mod;
            n = n >> 1;
        }
        return ret;
    }

    const LLONG ModComb(LLONG n, LLONG r) const
    {
        if (n == 0 && r == 0) return 1;
        if (n < r || n < 0) return 0;
        LLONG tmp = m_ifac[n - r] * m_ifac[r] % m_mod;
        return tmp * m_fac[n] % m_mod;
    }
};

int main()
{
    LLONG N, K;
    cin >> N >> K;
    vector<LLONG> As(N);
    for (auto &Ai : As) cin >> Ai;
    // 昇順にソートしておく
    sort(As.begin(), As.end());
    if (K == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    Mod mod(110000, MOD);
    LLONG sum = 0;
    for (int i = K - 1; i < N; ++i) sum += As[i];
    for (int i = 0; i <= N - K; ++i) sum -= As[i];
    LLONG ans = 0;
    // 数字を選ぶ幅をKからNまで広げながら行う
    for (int n = K - 2; n <= N - 2; ++n)
    {
        ans += mod.ModMulti(mod.ModComb(n, K - 2), sum);
        ans %= MOD;
        sum = sum - As[n + 1] + As[N - n - 2];
        sum %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2688
MOD = 10**9 + 7
n = 2 * 10**5 + 10

fac = [1] + [0] * n
fac_inv = [1] + [0] * n
for i in range(1, n+1):
    fac[i] = fac[i-1] * (i) % MOD
    fac_inv[i] = fac_inv[i-1] * pow(i, MOD-2, MOD) % MOD

def mod_nCr(n, r):
    if n == 0 and r == 0:
        return 1
    if n < r or n < 0:
        return 0
    tmp = fac_inv[n-r] * fac_inv[r] % MOD
    return tmp * fac[n] % MOD 

n, a, b, c = [int(item) for item in input().split()]
p = 0; q = 0
for i in range(n):
    p += (pow(a, n, MOD) * pow(b, i, MOD) + pow(a, i, MOD) * pow(b, n, MOD)) * pow(a+b, n-i-1, MOD) * mod_nCr(n+i-1, i) * 100 * (n+i)
    p %= MOD
q = pow(a+b, n*2-1, MOD) * (a + b)
print(p * pow(q, MOD-2, MOD) % MOD)

Measured memory_bytes: 46448
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string n;
    int k=0,t=-1;
    cin>>n;
    k=n.size();
    for (int i=0;i<=k-1;i++)
    {
        if (n[i]=='C')
        {
            t=i;
            break;
        }
    }
    if (t!=-1)
    {
        for (int i=t+1;i<=k-1;i++)
        {
            if (n[i]=='F')
            {
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
def cal(operand,a,b):
  if operand == "+":
    return int(a)+int(b)

  elif operand == "-":
    return int(a)-int(b)

  elif operand == "*":
    return int(a)*int(b)

por=[]

por = list(input().split())

stk=[]

for i in por:
  if i.isdigit() == True:
    stk.append(int(i))

  else:
    b=stk.pop()
    a=stk.pop()
    stk.append(cal(i,a,b))

print(stk[0])


Measured memory_bytes: 5600
arr = gets.split.map(&:to_i) 
arr.sort!

if arr[0]%2 == 0 && arr[1]%2 == 0 && arr[2]%2 == 0 ||  arr[0]%2 == 1 && arr[1]%2 == 1 && arr[2]%2 == 1
	puts (arr[2]-arr[0])/2 + (arr[2]-arr[1])/2 
elsif arr[0]%2 == 0 && arr[1]%2 == 0 || arr[0]%2 == 1 && arr[1]%2 == 1
	puts (arr[2]-arr[0]-1)/2 + (arr[2]-arr[1]-1)/2 + 1
elsif arr[0]%2 == 0 && arr[2]%2 == 0 || arr[0]%2 == 1 && arr[2]%2 == 1
	puts (arr[2]-arr[0])/2 + (arr[2]-arr[1]+1)/2 + 1
else
	puts (arr[2]+1-arr[0])/2 + (arr[2]-arr[1])/2 + 1
end

Measured memory_bytes: 1788
n,m=map(int,input().split())
D=[list(map(int,input().split())) for i in range(m)]
maxI=n
minI=1
for i in range(m):
  maxI=min(maxI,D[i][1])
  minI=max(minI,D[i][0])
print(max(maxI-minI+1,0))

Measured memory_bytes: 27336
s=input()
s=s[::-1]

t=0

x=1
cnt=[0]*2019
cnt[0]=1


for i in s:
    t += int(i)*x
    t %= 2019
    x *= 10
    x %= 2019
    cnt[t]+=1

ans=0
for i in cnt:
    ans +=i*(i-1)//2

print(ans)   

Measured memory_bytes: 9188
import itertools
N = int(input())
A = list(map(int, input().split(' ')))
A.sort()
summe = {k: len(list(g)) for k, g in itertools.groupby(A)}
cnt = 0
for k, v in summe.items():
    if k < v:
        cnt += v - k
    elif k > v:
        cnt += v
print(cnt)

Measured memory_bytes: 18284
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll X;
  cin >> X;
  while (true) {
    bool is_comp = false;
    for (int x = 2; x < X; x++) {
      if (X % x == 0) {
        X++;
        is_comp = true;
        break;
      }
    }
    if (!is_comp) break;
  }
  cout << X << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <math.h>
#include <algorithm>
#include<queue>
// #include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)

main(){
    int N, L, dif;
    int taste = 0;
    vector<int> a;
    cin >> N >> L;

    FOR(i,0,N){
        taste += L+i;
        dif = abs(L+i);
        a.push_back(dif);
    }

    sort(a.begin(),a.end());
    if(taste >= 0){taste -= a[0];}
    else{taste += a[0];}
    cout << taste << endl;  

}

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

using namespace std;


template<class T>
class BinarySearch {
public:
  vector<T> vec;

  BinarySearch(vector<T> &v) {
    vec = v;
  }

  /*
   * vec中からkeyを二分探索します.
   * 見つかった場合はkeyが出現する最小のインデックスを返します.
   * 見つからない場合はkeyを初めて超えたインデックスを返します.
   */
  int lower_bound(T key) {
      int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
      int ok = (int)vec.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

      /* ok と ng のどちらが大きいかわからないことを考慮 */
      while (abs(ok - ng) > 1) {
          int mid = (ok + ng) / 2;

          if (isOK(mid, key)) ok = mid;
          else ng = mid;
      }
      return ok;
  }

  /*
   * keyがvec中に含まれるかどうかを返します.
   */
  bool include(T key) {
    int idx = lower_bound(key);
    if (idx >= vec.size()) return false;
    return vec.at(idx) == key;
  }

private:
  // index が条件を満たすかどうか
  bool isOK(int index, T key) {
      if (vec.at(index) >= key) return true;
      else return false;
  }
};

int N, Q;
vector<int> S, T;

int main() {
  // input
  cin >> N;
  int x;
  for (int i=0; i<N; i++) cin >> x, S.push_back(x);
  cin >> Q;
  for (int i=0; i<Q; i++) cin >> x, T.push_back(x);

  // solve

  int total = 0;
  auto bs = BinarySearch<int>(S);
  for (auto t: T) {
    total += bs.include(t);
  }
  cout << total << endl;
  return 0;
}



Measured memory_bytes: 4184
'''
https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_d
'''
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    N = int(input())
    for i in range(10**3):
        if i*(i-1) == N*2:
            res = i
            break
    else:
        print('No')
        exit()

    s = [[] for _ in range(res)]
    num = 1

    for a,b in combinations(range(res), 2):
        s[a].append(num)
        s[b].append(num)
        num += 1

    print('Yes')
    print(res)
    for i in s:
        print('{} {}'.format(res-1, ' '.join(map(str, i))))

if __name__ == '__main__':
    main()

Measured memory_bytes: 43484
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.HashSet;

public class Main {
    public static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

    public static int nextInt() {
        try {
            in.nextToken();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return (int) in.nval;
    }

    public static String next() {
        try {
            in.nextToken();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return in.sval;
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        HashSet<String> set = new HashSet<String>();
        int n = nextInt();
        while (n-- > 0) {
            set.add(next());
        }
        System.out.println(set.size());
    }

}


Measured memory_bytes: 59296
h,w,n,*l=map(int,open(0).read().split())
g=[[] for i in range(h)]
r=t=0
for i,c in enumerate(l):
  i+=1
  while c>=(s:=w-t):
    g[r]+=[i]*s
    r+=1; c-=s; t=0
  if c:
    g[r]+=[i]*c
    t+=c
for i in range(h): print(*g[i][::2*(i%2)-1])

Measured memory_bytes: 9632
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll LL_INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  REP(i, 100){
    REP(j, 100){
      if(i*4 + j*7 == N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


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

using namespace std;

int N;


int main() {
  int s = 0;
  int t = 1000;
  cin >> N;

  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    s = max(s,a);
    t = min(t,a);
  }

  cout << s - t <<endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pii         pair<int,int> 
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F         first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define mem(x)      memset(x,0,sizeof(x));
#define what_is(x)  cerr << #x << " is " << x << endl;
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
using namespace std;
 
void solve(){
    int n,W;
    cin>>n>>W;
    ll w[n+1],v[n+1];
    rep(i,0,n)cin>>w[i+1]>>v[i+1];

    ll dp[W+1][n+1];

    


    

    rep(j,0,n+1){
        rep(i,0,W+1){
            if(i==0||j==0){
                dp[i][j]=0;
                continue;
            }
            else if(i>=w[j])dp[i][j]=max(dp[i-w[j]][j-1]+v[j],dp[i][j-1]);
            else
                dp[i][j]=dp[i][j-1];
        }
    }

    ll mx=0;

    rep(i,0,W+1){
        rep(j,0,n+1){
            
            mx=max(mx,dp[i][j]);
        }
    }
    cout<<mx;


}
 
 
 
int main(){
    // #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
   
 
    int t=1,i=1;
   // cin>>t;
    
 
    while(t--){
       // cout<<"Case #"<<i++<<": ";
        solve();
    
    }
 
    return 0;
}

Measured memory_bytes: 79104
import scala.io.StdIn.{readInt, readLine};
import scala.collection.immutable.HashMap;
import scala.annotation.tailrec;

object Main {
    def main(args: Array[String]): Unit = {
        val relations = readLine.split(" ").map(_.toInt).last;
        val g = (0 until relations).foldLeft(Graph[Int]()) { (graph, i) =>
            readLine.split(" ").map(_.toInt) match {
                case Array(src, dst) => graph.add(src, dst);
                case _ => graph;
            }
        }
        val groups = g.dfs;
        (0 until readInt).foreach { i =>
            readLine.split(" ").map(_.toInt) match {
                case Array(n1, n2) => {
                    if (groups.contains(n1) && 
                         groups.contains(n2) && 
                         groups.get(n1) == groups.get(n2)) {
                        println("yes");
                    } else {
                        println("no");
                    }
                }
            }
        }
        
    }
}
case class Graph[A](graph: HashMap[A, List[A]]) {
    def dump: Unit = graph.foreach { e => println("%d -> %s".format(e._1, e._2.mkString(" ")))}

    def add(n1: A, n2: A): Graph[A] = {
        val n1Value = n2 :: graph.getOrElse(n1, Nil)
        val n2Value = n1 :: graph.getOrElse(n2, Nil);
        new Graph[A](graph.updated(n1, n1Value).updated(n2, n2Value));
    }
    
    def dfs: HashMap[A, Int] = {
        @tailrec
        def go(stack: List[A], visited: HashMap[A, Int], group: Int): HashMap[A, Int] = stack.headOption match {
            case None => visited;
            case Some(curr) => {
                val nextNodes = graph.getOrElse(curr, Nil).filter(!visited.contains(_));
                go(nextNodes ::: stack.tail, visited.updated(curr, group), group);
            }
        }
        var cnt = 0;
        graph.keys.foldLeft(HashMap[A, Int]()) { (gList, node) =>
            if (!gList.contains(node)) {
                cnt += 1;
                go(List[A](node), gList.updated(node, cnt), cnt);
            } else {
                gList;
            }
        }
    }
}
object Graph {
    def apply[A](): Graph[A] = new Graph(HashMap[A, List[A]]());
}


Measured memory_bytes: 339096
N = int(input())
an = [0] + [int(i) for i in input().split()]+[0]
t = sum([abs(an[i+1]-an[i]) for i in range(N+1)])
ts = []
for i in range(N):
  a,b,c = an[i:i+3]
  ts.append(t+(0 if 0 <= (a-b)*(b-c) else -2*(min(abs(a-b),abs(b-c)))))
print('\n'.join(map(str,ts)))


Measured memory_bytes: 20080
main :: IO ()
main = do
    input <- getLine
    putStrLn (show (disp input))

disp :: String -> Integer
disp input = list2 * (100 ^ list1)
        where
            list1  = read ( (words input) !! 0)
            list2  = if (read ( (words input) !! 1)) == 100
                then 101
                else (read ( (words input) !! 1))


Measured memory_bytes: 508
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

//		while(true) {
//			a.main(null);
//		}
		
		
		a.main(null);
		
	}

}

class a {

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

		int count = (r - l) / d;
		if (r % d == 0) {
			count++;
		}
		
		if (r == l) {
			count=1;
		}

		System.out.println(count);

	}

}

Measured memory_bytes: 35644
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
#include <set>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    double a , b , c , k;
    cin >> a >> b >> c >> k;
    cout << a + b + c - max( a , max( b , c ) ) + max( a , max( b , c ) ) * pow( 2 , k );
}


Measured memory_bytes: 4216
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
using namespace std;
#define INF 1LL<<62
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll

signed main(){
    int N;
    cin>>N;
    ll A[110000],sum=0,ans[110000];
    for(int i=0;i<N;i++){
        cin>>A[i];
        sum+=A[i];
    } 
    for(int i=1;i<N;i+=2){
        sum-=A[i]*2;
    }
    ans[0]=sum;
    for(int i=1;i<N;i++){
        ans[i]=(A[i-1]-ans[i-1]/2)*2;
    }
    for(int i=0;i<N;i++){
        if(i) cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;
}


Measured memory_bytes: 2944