akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python

import sys
import math
import itertools as it
from collections import deque

sys.setrecursionlimit(10000000)

n = input()
ans = 0
x0, y0 = map(int, raw_input().split())
xp, yp = map(int, raw_input().split())
for loop in range(n - 2):
    xq, yq = map(int, raw_input().split())
    ans += (xp - x0) * (yq - y0) - (xq - x0) * (yp - y0)
    xp, yp = xq, yq

print "%.1f" % (float(ans) / 2)


Measured memory_bytes: 5048
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		String c1 = sc.next();
		String c2 = sc.next();
		String c3 = sc.next();
		sc.close();

		System.out.print(c1.charAt(0));
		System.out.print(c2.charAt(1));
		System.out.print(c3.charAt(2));

	}
}

Measured memory_bytes: 21332
#include<iostream>
#include<cstdio>
using namespace std;
int i=0;
int gcd(int W,int H)
{
	if(H==0)
	{
		return(W);
	}
	else
	{
		i=i+1;
		return(gcd(H,W%H));
	}
}
int main(void)
{
	int W=0,H=0,C=0;
	scanf("%d %d %d",&W,&H,&C);
	gcd(W,H);
	printf("%d\n",(W/gcd(W,H)*H/gcd(W,H))*C);
	return (0);
}


Measured memory_bytes: 3204
#
# 9b
#

def main():
    while True:
        c = input()
        if c == "-":
            break
        m = int(input())
        for i in range(m):
            h = int(input())
            c = c[h:] + c[0:h]
        print(c)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5596
using System;
class swap{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    int[] num = new int[n];
    String[] str = Console.ReadLine().Split(' ');
    for(int i=0; i<n; i++){
      num[i] = int.Parse(str[i]);
    }
    count c = new count();
    c.asc(n,num);
    c.desc(n,num);
    if((c.getcntasc()<=2)|| (c.getcntdesc()<=2)){
      Console.WriteLine("YES");
    }
    else{
      Console.WriteLine("NO");
    }
  }
}

class count{
  int cntasc,cntdesc;
  public count(){
    cntasc = 0;
    cntdesc = 0;
  }
  public int getcntasc(){
    return cntasc;
  }
  public int getcntdesc(){
    return cntdesc;
  }
  public void asc(int n, int[] num){
    for(int i=n-1; i>=0; i--){
      if(num[i] != i+1){
        cntasc++;
      }
    }
  }
  public void desc(int n, int[] num){
    for(int i=0; i<n; i++){
      if(num[i] != i+1){
        cntdesc++;
      }
    }
  }
}


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

int main(){
	int n ; cin >> n ;
	vector<vector<int>> a(4,vector<int>(30,0)) ;
	for(int i=0;i<n;i++){
		int b,f,r,v ;
		cin >> b >> f >> r >> v ;
		a.at(b-1).at(10*(f-1)+r-1) += v ;
	}
	for(int i=0;i<4;i++){
	    if(i!=0){
	        cout << endl ;
	        for(int j=0;j<20;j++) cout << "#" ;
	        cout << endl ;
	    }
	    for(int j=0;j<30;j++){
	        if(j%10==0&&j!=0) cout << endl ;
	        cout << " " << a.at(i).at(j) ;
	    }
	}
	cout << endl ;
}


Measured memory_bytes: 3168
#include <iostream>
using namespace std;
 
int main(){
  int x;
  cin>>x;
  int i,j;
  int flag=0;
  for(i=-120;i<=120;i++){
    for(j=-120;j<=120;j++){
      if(i*i*i*i*i-j*j*j*j*j==x){
        flag=1;
        break;
      }
    }
    if (flag==1) break;
  }
  cout <<i<<" "<<j<<endl;
  return 0;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

ll gcd(ll m, ll n)
{
	if (m < n) {
		swap(m, n);
	}

	if (n == 0) {
		return m;
	}

	return gcd(n, m % n);
}

signed main() {
	ll n, a, ans;

	cin >> n;

	vector<ll> v(n, 0);

	REP(i, n) {
		cin >> a;
		v[i] = a;
	}

	ans = v[0];

	REP(i, n) {
		ans = gcd(ans, v[i]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define IF (1<<30)

int H,Ax[MAX+1];

void mh(int i){
  int left,right,max;
  left=2*i;
  right=2*i+1;

  if(left <= H && Ax[left]>Ax[i]){
    max = left;
  }
  else max = i;
  if(right <= H && Ax[right] > Ax[max] ){
    max = right;
  }

  if(max != i){
    swap(Ax[i],Ax[max]);
    mh(max);
		  }

}

int ex() {
  int mv;
  if(H<1){
    return -IF;
  }
  mv = Ax[1];
  Ax[1] = Ax[H--];
  mh(1);
  return mv;
}

void is(int i,int im){
  if(im < Ax[i]){
    return;
  }
  Ax[i] = im;
  while(i > 1 &&Ax[i/2] < Ax[i]){
    swap(Ax[i],Ax[i/2]);
    i = i/2;
  }
}

void in(int key){
  H++;
  Ax[H] = -IF;
  is(H,key);
}

int main(){
  int im;
  char da[10];

  while(1){
    scanf("%s",da);
    if(da[0] == 'e' && da[1] == 'n'){
      break;
    }
    if(da[0] == 'i'){
      scanf("%d",&im);
      in(im);
    }
    else{
      printf("%d\n",ex());
    }
  }
  return 0;
}



Measured memory_bytes: 6448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;

int main() {
    ll n,m; cin >> n >> m;
    ll cnt = min(n,m/2);
    m-=cnt*2;
    if(m >= 4){
     cnt+=m/4;
    }
    cout << cnt;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;

int main() {
	int h, w;
	cin >> h >> w;
	string a[h];
	rep (i, h) cin >> a[i];

	rep (i, w + 2) cout << "#"; cout << endl;
	rep (i, h) {
		cout << "#";
		cout << a[i];
		cout << "#" << endl;
	}
	rep (i, w + 2) cout << "#"; cout << endl;

	return 0;
}

Measured memory_bytes: 256
/*
首先想到同样例1的构造方式。还是能过三十多个点的。
比如1 4 1 3，会输出无解（会填[1 1 -3 1]）。怎么改呢。对于一个点，它可以覆盖多个h*w的子矩形，只要对每个子矩形满足负权和，它们的和可以尽量大。
将原方案中的所有正数扩大d倍，不得不填负的格子只需恰好大于一个子矩形的和。这样多个格子加起来的和就大了。
如1 4 1 3，可以填[1000 1000 -2001 1000]。
*/
#include <cstdio>
#include <algorithm>
const int N=505;

bool A[N][N];

int main()
{
	int H,W,h,w; scanf("%d%d%d%d",&H,&W,&h,&w);
	if(!(H%h) && !(W%w)) return puts("No"),0;//每个子矩形都是负的，拼一块还是负的 

	int r=h,c=w,tot=0,lr=2*(h-1),lc=2*(w-1);
//	while(1)
//	{
//		while(1)
//		{
//			++tot, A[r][c]=1;
//			if(c+w>W) break;
//			c=std::min(W,c+lc+1);
//		}
//		c=w;
//		if(r+h>H) break;
//		r=std::min(H,r+lr+1);
//	}
	for(int i=1; i<=H; ++i)
		for(int j=1; j<=W; ++j)
			if(!(i%h) && !(j%w)) ++tot, A[i][j]=1;
	
	int v=-h*w*1000+999;
	if(-1ll*tot*v>=1000*(H*W-tot)) puts("No");
	else
	{
		puts("Yes");
		for(int i=1; i<=H; ++i,putchar('\n'))
			for(int j=1; j<=W; ++j) printf("%d ",A[i][j]?v:1000);
	}

	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main()
{
    int a, b, c, d, n, result;
    
    while (scanf("%d", &n) != EOF) {
        result = 0;
        
        for (a = 0; a <= 9; a++) {
            for (b = 0; b <= 9; b++) {
                for (c = 0; c <= 9; c++) {
                    for (d = 0; d <= 9; d++) {
                        if (a + b + c + d == n) {
                            result++;
                        }
                    }
                }
            }
        }
        
        printf("%d\n", result);
    }
    
    return 0;
}

Measured memory_bytes: 0
ss = list(input())
t = list(input())

ans = "UNRESTORABLE"
for i in range(len(ss) - len(t), -1, -1):
  flag = True
  for j in range(i, i + len(t)):
    if ss[j] != t[j-i] and ss[j] != "?":
      flag = False
      break
  if flag:
    ss[i:i+len(t)] = t
    ans = "".join(ss).replace("?", "a")
    break
    
print(ans)

Measured memory_bytes: 3064
a, b, c, d = map(int, input().split())

if(abs(a-c) <= d): 
    print("Yes")
elif(a <= b and b <= c and (abs(a-b) <= d and abs(c-b) <= d)):
    print("Yes")
elif(a >= b and b >= c and (abs(a-b) <= d and abs(c-b) <= d)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;

int main(int argc, char const *argv[])
{
    int n, d;
    cin >> n >> d;
    cout << (n + 2 * d) / (2 * d + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
N =int(input())
n=[]
for i in range(N):
	n.append(int(input()))

mx = max(n)
m = n.index(mx)
b = sorted(n)
my = b[N-2]

for i in range(N):
	if i == m:
		print(my)
	else:
		print(mx)

Measured memory_bytes: 14112
package main
 
import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	"sort"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}
 
//func nextString() string {
//	sc.Scan()
//	return sc.Text()
//}
 
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var N int
var ANS float64
var L []int
func main() {
	N = nextInt()
	L = make([]int, N)
	for i := 0; i < N; i++ {
		L[i] = nextInt()
	}
	sort.Slice(L, func (i, j int) bool { return L[i] < L[j]})
	ANS = float64(L[0])
	for i := 1; i < N; i++ {
		ANS = (ANS + float64(L[i])) / float64(2)
	}
	fmt.Println(ANS)
}


Measured memory_bytes: 1808
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

//#include<boost/circular_buffer.hpp>
using namespace std;

//cout << fixed << setprecision(10);
typedef long long ll;
#define PI 3.141592653589793
#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}
	long long int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

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

vector<long long  int> Prime;
void Eratosthenes(long long int n) {
	vector<bool> is_prime(n, true);
	for (int i = 2; i * i <= n; i++) {
		;
		if (is_prime.at(i)) {
			for (int j = i * i; j <= n; j += i) {
				is_prime.at(j) = false;
			}
		}
		Prime.emplace_back(i);
	}
}

/*
map<int, int> prime;
void Prime_number(long long int n) {
	for (int i = 2; i <= n; i++) {
		int count = 0;
		while (n % i == 0) {
			count++;
			n /= i;
		}
		if (count != 0) {
			prime.insert(make_pair(i, count));
		}
	}
}
*/
//std::cout.fill('0');

int keta(long long int N) {
	int k = 0;
	while (N > 0) {
		N /= 10;
		k++;
	}
	return k;
}



int Combination(int n, int m) {
	long long int s = 1, t = 1;
	int tmp = n;
	while (n - m != tmp) {
		s *= tmp;
		tmp--;
	}
	tmp = m;
	while (tmp != 1) {
		t *= tmp;
		tmp--;
	}
	return s / t;
}


int main() {
	long long int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0) {
		cout << (b - a) / 2 << endl;
	}
	else {
		cout << min(a,n-b+1) + (b - a - 1) / 2 << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<vector<double>> vvd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x_, i_, j_) cerr << #x_ << "------------" << "\n";cerr << "from " << i_ << " to " << j_ << "\n";for(ll k_=i_; k_<=j_; k_++) cerr << x_[k_] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

const ll MOD = 1e9 + 7;
const int INF = 2e9;
const int MAX_LOG = 21;
const int MAX_N = 1000*101;

#define forn(i, n) for(int i = 0; i < n; i++)
#define forsn(i, s, n) for(int i = s; i < n; i++)
#define all(x) x.begin(), x.end()


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

	ll n, a, b;
	cin >> n >> a >> b;
	ll ans = n / (a + b) * a + min(a, n % (a + b));
	cout << ans << endl;
}		


Measured memory_bytes: 256
import sys
import collections
from collections import deque
input = sys.stdin.readline
N = int(input())
mod = 10 ** 9 + 7
e = [[] for i in range(N+1)]
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

vis = [0] * (N + 1)
dp = [[1] * 2 for _ in range(N + 1)]
order = deque()
parent = [0] * (N + 1)
s = [1]

while len(s):
  x = s.pop()
  vis[x] = 1
  order.appendleft(x)
  for y in e[x]:
    if vis[y]:continue
    s.append(y)
    parent[y] = x


for x in order:
  y = parent[x]
  dp[y][0] *= dp[x][0] + dp[x][1]
  dp[y][0] %= mod
  dp[y][1] *= dp[x][0]
  dp[y][1] %= mod

print(dp[0][0])

Measured memory_bytes: 74032
/* ***************************************
Author        :Scau.ion
Created Time  :2017/01/15 20:12:01 UTC+8
File Name     :ion.cpp
*************************************** */

#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

const int maxn=100010;

LL x[maxn];

int main()
{
    IOS;
    int n;
    LL a,b;
    cin>>n>>a>>b;
    for (int j=1;j<=n;++j)
        cin>>x[j];
    LL ans=0;
    for (int j=2;j<=n;++j)
    {
        ans+=min((x[j]-x[j-1])*a,b);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX = 51000;
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

llong POW(llong a, llong b){
  if(b == 0) return 1;
  else{
    if(b%2 == 0) return POW(a * a % MOD9, b / 2) % MOD9;
    else return a * POW(a * a % MOD9, b / 2) % MOD9;
  }
}

int main(){
  llong ans = 0;
  llong N, M, K;
  cin >> N >> M >> K;
  llong com = 1;
  for(llong i=0; i<=K; ++i){
    if(i==0 || i==N-1){
      ans += M * POW(M-1, N-1-i) % MOD9;
    }else{
      com *= N - 1 - i + 1;
      com %= MOD9;
      com *= POW(i, MOD9 - 2);
      com %= MOD9;
      ans += M * POW(M-1, N-1-i) % MOD9 * com % MOD9;
    }
  }
  if(ans < 0) ans += MOD9;
  cout << ans%MOD9 << endl;
}


Measured memory_bytes: 3608
#include <cstdio>
#include <set>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int, int> P;
int n;
P st[3000];
int main() {
    while (scanf("%d",&n)) {
        if (!n) break;
        set<P> stat;
        for (int i=0; i<n; i++) {
            scanf("%d%d",&st[i].first,&st[i].second);
            stat.insert(st[i]);
        }
        int res=0;
        for (int i=0; i<n; i++) {
            P a=st[i];
            for (int j=0; j<n; j++) {
                P b=st[j];
                int dist1=b.first-a.first, dist2=a.second-b.second;
                if (stat.find(P(b.first-dist2,b.second-dist1))!=stat.end()&&stat.find(P(a.first-dist2,a.second-dist1))!=stat.end()) {
                    res=max(res,dist1*dist1+dist2*dist2);
                }
            }
        }
        printf("%d\n",res);
    }
}

Measured memory_bytes: 932
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,h,w = inpl()
x,y = 30*(h+(w/60)), 6*w
C = min(abs(x-y),360-abs(x-y))
# print(C)
if C == 0:
    print(abs(a-b))
elif C == 180:
    print(a+b)
else:
    tmp = a**2 + b**2 - 2*a*b*math.cos(math.radians(C))
    # print(math.cos(math.radians(C)))
    print(math.sqrt(tmp))
    # print(tmp)

Measured memory_bytes: 10676
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let n = read::<i64>();
  let mut ans = 0;
  ans += (n / 11) * 2;
  if n % 11 == 0 {
    ans += 0;
  } else if n % 11 <= 6 {
    ans += 1;
  } else {
    ans += 2;
  }

  println!("{}", ans);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll x; cin >> x;
    cout << x/11*2+(x%11+5)/6 << endl;;
    return 0;
}

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

using namespace std;

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

	int n;
	cin >> n;
	switch (n % 10) {
		case 3:
			cout << "bon\n";
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			cout << "pon\n";
			break;
		default:
			cout << "hon\n";
			break;
	}

	return 0;
}


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

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>

using namespace std;
using ll = long long;


vector<int> c;
vector<vector<int>> s;
int D;
vector<int> v;
vector<set<int>> U;
vector<set<int>> minusU;
int now;

ll calc(){
    ll ans = 0;
    vector<int> last(26, 0);
    for(int i = 0;i < D;i++){
        last[v[i] - 1] = i + 1;
        ans += s[i][v[i] - 1];
        //cout<<s[i][v[i] - 1]<<endl;
        for(int j = 0;j < 26;j++){
            ans -= (ll)(i + 1 - last[j]) * c[j];
        }
    }
    now = ans;
    return ans;
}

ll calc(int d, int i){
    int prev = v[d];
    now += s[d][i];
    now -= s[d][prev];
    int n = *U[i].upper_bound(d);
    int p = -*minusU[i].upper_bound(-d);
    int term = n - p - 1;
    now += term * (term + 1) / 2 * c[i];
    now -=  (n - d) * (n - d - 1) / 2 + (d - p - 1) * (d - p) / 2 * c[i];
    n = *U[prev].upper_bound(d);
    p = -*minusU[prev].upper_bound(-d);
    term = n - p - 1;
    now -= term * (term + 1) / 2 * c[prev];
    now +=  (n - d) * (n - d - 1) / 2 + (d - p - 1) * (d - p) / 2 * c[prev];
    v[d] = i;
    U[prev].erase(d);
    minusU[prev].erase(-d);
    U[d].insert(d);
    minusU[prev].insert(-d);
    return now;
}

int retrnd(int n){ //乱数生成                                    
	std::random_device rnd;
    std::mt19937 mt(rnd());
    std::uniform_int_distribution<> rand100(0, n);
    return rand100(mt);
}

int main(){
    cin >> D;
    for(int i = 0;i < 26;i++){
        int a;cin >> a;
        c.push_back(a);
    }
    for(int i = 0;i < D;i++){
        vector<int> a;
        for(int j = 0;j < 26;j++){
            int b;cin >> b;
            a.push_back(b);
        }
        s.push_back(a);
    }
    U = vector<set<int>>(26);
    minusU = vector<set<int>>(26);
    for(int i = 0;i < 26;i++){
        U[i].insert(0);
        U[i].insert(D);
        minusU[i].insert(0);
        minusU[i].insert(D);
    }
    for(int i = 0;i < D;i++){
        v.push_back(retrnd(25) + 1);
        U[v.back() - 1].insert(i);
        U[v.back() - 1].insert(-i);
    }
    now = calc();
    int try_cnt = 1000;
    for(int cnt = 0;cnt < try_cnt;cnt++){
        int rnd = retrnd(D - 1);
        for(int i = 1;i < 27;i++){
            int p = now;
            int prev = v[rnd];
            v[rnd] = i;
            calc();
            if(now < p){
                v[rnd] = prev;
                calc();
            }
        }
    }
    for(int i = 0;i < D;i++){
        cout<<v[i]<<endl;
    }
}

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

int main(){
  int a, b;
  cin >> a >> b;
  if (a==2){
    if (b==2) {
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  else if((a==4)||(a==6)||(a==9)||(a==11)){
    if ((b==4)||(b==6)||(b==9)||(b==11)){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  else{
    if ((b==2)||(b==4)||(b==6)||(b==9)||(b==11)) {
      cout << "No" << endl;
    }
    else{
      cout << "Yes" << endl;
    }
  }
}

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

#define for0(i, n) for (ll i = 0; i < (ll)(n); ++i) // 0 based indexing
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (ll i = (ll)(l); i <= (ll)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (ll i = (ll)(n); i >= 1; --i) // reverse 1 based

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
  cin >> n;
  cout << n*n*n<<endl;
	
	return 0;
}


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

typedef long long ll;

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

    ll n;
    string s;
    cin >> n >> s;
    if(n%2!=0){
        cout << "No" << endl;
    }else{
        for(ll i=0;i<n/2;i++){
            if(s[i] != s[i+n/2]){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
class c
{
  static void Main()
  {
    string[]s=Console.ReadLine().Split(' ');
    int x=int.Parse(s[0]);
    int y=int.Parse(s[1]);
    string ans="No";
    if(x==2&&y==2)ans="Yes";
    else if(y==2||x==2)ans="No";
    else if(x<8&&y<8&&x%2==y%2)ans="Yes";
    else if(x>=8&&y<8&&x%2!=y%2)ans="Yes";
    else if(x<8&&y>=8&&x%2!=y%2)ans="Yes";
    else if(x>=8&&y>=8&&x%2==y%2)ans="Yes";
    Console.WriteLine(ans);
  }
}


Measured memory_bytes: 11092
a = list(raw_input())
b = list(raw_input())

a = sorted(a)
b = sorted(b)
new_a = []
new_b = []
for x in a:
  if ord(x) >= ord('a') and ord(x) <= ord('z'):
     new_a.append(x)
      
for x in b:
  if ord(x) >= ord('a') and ord(x) <= ord('z'):
     new_b.append(x)

new_a = new_a
new_b = new_b[::-1]
la = len(new_a)
lb = len(new_b)

for x in range(101):
  if x >= lb:
    print "No"
    exit(0)
  if x >= la:
    print "Yes"
    exit(0)
  if ord( new_a[x] ) > ord( new_b[x] ):
    print "No"
    exit(0)
  if ord( new_a[x] ) < ord( new_b[x] ):
    print "Yes"
    exit(0)


Measured memory_bytes: 2696
#include "stdio.h"
int main() {
	int n;
	char *s, *t;
	scanf("%d", &n);
	s = new char[n];
	t = new char[n];
	scanf("%s%s", s, t);
	for (int i = 0; i < n; i++) {
      printf("%c%c", s[i], t[i]);
	}
 
	return 0;
}

Measured memory_bytes: 256
#import time

def main():
    N, M, X = map(int, input().split())
    Cs = [list(map(int, input().split())) for _ in range(N)]
    mi = 100000000000000000000 #->float("inf")
    for i in range(1<<N):
        lis = [0] * (M+1)
        for j in range(N):
            if i & (1<<j) == 0:
                continue
            for k in range(M+1):
                lis[k] += Cs[j][k]
        if all(v>=X for v in lis[1:]):
            mi = min(lis[0], mi)

    return -1 if mi == 100000000000000000000 else mi

if __name__ == '__main__':
    #start = time.time()
    print(main())
    #elapsed_time = time.time() - start
    #print("経過時間:{}".format(elapsed_time * 1000) + "[msec]")

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int b;
  int c;
  int d;
  int e;
  cin >> a >> b >> c >> d >> e;
  if (a == 0) {
    cout << "1" << endl;
  }
  else if (b == 0) {
    cout << "2" << endl;
  }
  else if (c == 0) {
    cout << "3" << endl;
  }
  else if (d == 0) {
    cout << "4" << endl;
  }
  else {
    cout << "5" << endl;
  }
}
    

Measured memory_bytes: 3596
from collections import Counter
n = int(input())
S = []
for i in range(n):
  S.append(input())
S = sorted(S)
c = Counter(S)
X = c.most_common()
A = []
for i in range(len(X)):
  if X[0][1] == X[i][1]:
    A.append(X[i][0])
  else:
    break
A = sorted(A)
for i in range(len(A)):
  print(A[i])

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

int main() {
    int n,m;cin>>n>>m;
    
    int a[m];
    
    for(int i=0;i<m;++i){
        a[i]=0;
    }
    int tmp,tmp2;
    for(int i=0;i<n;++i){
        cin>>tmp;
        for(int j=0;j<tmp;++j){
            cin>>tmp2;
            a[tmp2-1]+=1;
        }
    }
    int ans=0;
    for(int i=0;i<m;++i){
        if(a[i]==n)ans+=1;
    }
    cout<<ans<<endl;
	return 0;
}

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

#define ALL(a) (a).begin(), (a).end()

using namespace std;

signed main(){
	vector<int> inp(28);
	for(auto &&e: inp) cin >> e;
	vector<bool> tab(31, false);
	for(auto e: inp) tab[e] = true;
	for(int i = 1; i <= 30; i++){
		if(!tab[i])cout << i << endl;
	}

	return 0;
}




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

typedef long long ll;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

vector<ll> dp;
vector<int> v;
int n;

void solve(){
    cin>>n;
    v.resize(n+1);
    dp.resize(n+1);
    for(int i=1;i<=n;i++)cin>>v[i];
    dp[1]=v[1];
    dp[2]=v[2];
    for(int i=3;i<=n;i++){
        if(i&1)dp[i]=dp[i-2]+v[i];
        else dp[i]=max(dp[i-2],dp[i-3])+v[i];
    }
    if(n&1){
        ll bj=v[n],ans=max(dp[n-1],dp[n-2]);
        for(int i=n-2;i>=3;i-=2){
            ans=max(ans,bj+max(dp[i-1],dp[i-2]));
            bj+=v[i];
        }
        cout<<max(ans,bj);
    }else cout<<max(dp[n-1],dp[n]);;

}

int main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 5484
import sys
"""
方針：まず左端を固定して実際にPで割ったあまりを計算しながら数値列を伸ばしていけばO(N^2)で計算ができる
文字列の左右を固定した場合に（部分文字列について？）Pで割ったあまりを計算できないか，定式化を考えてみよう．
Ui := S[i:N]をSのi文字以降を評価した整数と置く．便宜上UN+1=0とする．
この時Sのi文字目からj文字目までを評価した整数は(Ui - Uj+1)/10^(j+1-i)と表せる．

"""

sys.setrecursionlimit(10 ** 6)
readline = sys.stdin.readline
read = sys.stdin.read

n, p = [int(i) for i in readline().split()]
s = input()

if p == 2 or p == 5:
    ans = 0
    for i, c in enumerate(s):
        if int(c) % p == 0:
            ans += i + 1
    print(ans)
    exit()

res = [0] * p
res[0] = 1
t = 1
now = 0
for i in s[::-1]:
    i = int(i)
    now += i * t
    now %= p
    res[now] += 1
    t = t * 10 % p

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

print(ans)



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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  vector<ll> a(n);
  vector<ll> b(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  ll l = 0;
  if (n%2 == 0) {
    l = a[n/2-1] + a[n/2];
  } else {
    l = a[(n+1)/2-1];
  }

  ll r = 0;
  if (n%2 == 0) {
    r = b[n/2-1] + b[n/2];
  } else {
    r = b[(n+1)/2-1];
  }

  cout << r-l+1 << endl;

  return 0;
}


Measured memory_bytes: 6420
#include <stdio.h>
int main(){
  int n, count, ac=0, wa=0, tle=0, re=0;
  char string[10];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", &string);
    if (strcmp(string, "AC")==0) ac+=1;
    if (strcmp(string, "WA")==0) wa+=1;
    if (strcmp(string, "TLE")==0) tle+=1;
    if (strcmp(string, "RE")==0) re+=1;
  }
  printf("AC x %d\n", ac);
  printf("WA x %d\n", wa);
  printf("TLE x %d\n", tle);
  printf("RE x %d\n",re);
  return 0;
}

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

using namespace std;

namespace {

vector<complex<double>> Fft(const vector<complex<double>>& f, double sign) {
  const auto n = f.size();
  if (n == 1)
	return f;
  vector<complex<double>> f0(n/2), f1(n/2);
  for (int i = 0; i < n/2; i++) {
	f0[i] = f[2*i];
	f1[i] = f[2*i+1];
  }
  f0 = Fft(f0, sign);
  f1 = Fft(f1, sign);
  vector<complex<double>> ff(n);
  const complex<double> zeta = {cos(M_PI*2/n), sign*sin(M_PI*2/n)};
  complex<double> pow_zeta = 1;
  for (int i = 0; i < n; i++) {
	ff[i] = f0[i%(n/2)] + pow_zeta*f1[i%(n/2)];
	pow_zeta *= zeta;
  }
  return ff;
}

vector<complex<double>> InvDft(const vector<complex<double>>& ff) {
  const auto n = ff.size();
  auto f = Fft(ff, -1);
  for (auto& c : f) {
	c /= n;
  }
  return f;
}

vector<complex<double>> Multiply(const vector<complex<double>>& a, const vector<complex<double>>& b) {
  size_t n = 1;
  while (n < a.size()+b.size()+1)
	n *= 2;
  auto ca = a;
  auto cb = b;
  ca.resize(n);
  ca = Fft(ca, 1);
  cb.resize(n);
  cb = Fft(cb, 1);
  for (int i = 0; i < n; i++) {
	ca[i] *= cb[i];
  }
  return InvDft(ca);
}

}

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

  long long N,M; cin>>N>>M;
  vector<complex<double>> X;
  for (int i = 0; i < N; i++) {
    int a; cin>>a;
    if (X.size() < a+1)
      X.resize(a+1);
    X[a] += 1;
  }
  const auto maxA = X.size()-1;
  auto cnvX = Multiply(X, X);
  long long ans = 0;
  long long m = M;
  long long a = maxA*2;
  while (m and a >= 0) {
    auto c = min(m, (long long)(cnvX[a].real()+0.5));
    ans += c*a;
    m -= c;
    a--;
  }
  cout << ans << endl;

  return 0;
}


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

int main(){
  int H,W,i,j;
  
  
  while(1){
    
    cin >> H >> W;
    if(H == 0 && W == 0 ) break;
    
    for(i=1;i<=H;i++){
      
      for(j=1;j<=W;j++){

	  cout << "#" ;
      }    
      cout << endl;
    }
    cout << endl;
    
  } 
}



Measured memory_bytes: 3096
n,d = gets.split.map{ |x| x.to_i }

v = []

n.times{
	v << gets.split.map{ |x| x.to_i }
}

result = 0

(0...v.size).each{ |i|
	((i+1)...v.size).each{ |j|
		sum = 0
		(0...v[i].size).each{ |k|
			sum += (v[i][k] - v[j][k]) ** 2
		}
		
		x = sum ** (1/2.0)
		
		if x.ceil == x then
			result+=1
		end
	}
}

puts result


Measured memory_bytes: 1788
# coding: utf-8
def get_ln_inputs():
    return input().split()


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def main():
    N = get_ln_int_inputs()[0]
    K = get_ln_int_inputs()[0]
    xs = get_ln_int_inputs()

    ans = 0
    for x in xs:
        ans += min(abs(K - x), abs(x))

    print(2 * ans)
    return


main()

Measured memory_bytes: 3060
#include <iostream>
#include <cstdint>
#include <vector>

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

public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
    constexpr u64& value() noexcept { return a; }
    constexpr const u64& value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
        return modint(*this) /= rhs;
    }
    constexpr modint& operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint& operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint& operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint& operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};

using Mint = modint<1000000007>;

Mint pow2(int n) {
    if (n == 0)
        return 1;

    if (n % 2 == 0) {
        Mint t = pow2(n / 2);
        return t * t;
    }

    return pow2(n - 1) * 2;
}

int main() {
    int n, a, b;
    std::cin >> n >> a >> b;

    std::vector<Mint> facts(200000 + 1);
    facts[0] = 1;
    for (int i = 1; i <= 200000; ++i)
        facts[i] = facts[i - 1] * i;

    Mint x = 1;
    for (int i = 0; i < a; ++i)
        x *= n - i;

    Mint y = 1;
    for (int i = 0; i < b; ++i)
        y *= n - i;

    x /= facts[a];
    y /= facts[b];
    
    std::cout << (pow2(n) - x - y - 1).a << std::endl;
}

Measured memory_bytes: 1792
n=int(input())
s,t=input().split()
a=[str(c) for c in s]
b=[str(c) for c in t]
x=["o"]*n*2
for i in range(n*2):
  if i%2==0:
    x[i]=a[i//2]
  else:
    x[i]=b[i//2]
print("".join(x))

    

Measured memory_bytes: 38384
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

	public Main() {
		FastScanner scanner = new FastScanner();
		String S = scanner.next();
		if (S.equals("RSS")){
			System.out.println(1);
		} else if(S.equals("SRS")){
			System.out.println(1);
		} else if(S.equals("SSR")){
			System.out.println(1);
		} else if(S.equals("RRS")){
			System.out.println(2);
		} else if(S.equals("SRR")){
			System.out.println(2);
		} else if(S.equals("RSR")){
			System.out.println(1);
		} else if(S.equals("RRR")){
			System.out.println(3);
		} else {
			System.out.println(0);
		}
	}

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

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int bufLen = 0;

	private boolean hasNextByte() {
		if (ptr < bufLen) {
			return true;
		} else {
			ptr = 0;
			try {
				bufLen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (bufLen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte()) return buffer[ptr++];
		else return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}

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


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

int main() {
    int n, m; cin >> n >> m;
    vector<bool> a(n+1);
    vector<bool> b(n+1);
    rep(i, m) {
        int tmp_a, tmp_b;
        cin >> tmp_a >> tmp_b;
        if (tmp_a == 1) a[tmp_b] = true;
        if (tmp_b == n) b[tmp_a] = true;
    }
    rep(i, a.size()) {
        if (a[i] && b[i]) {
            puts("POSSIBLE");
            return 0;
        }
    }
    puts("IMPOSSIBLE");
}

Measured memory_bytes: 3628
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O2")
// #pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
 #define int ll
#define pb push_back
#define pob pop_back
#define __bp __builtin_popcount
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pdd = pair<ld,ld>;
using vint = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
#define F first
#define S second
const int N = 2e5+5;//(1 << 18) + 5;
//const ll inf = 1e18+7;
const int Inf = 1e9+7;
const ll INF = 1e18+7;
const int Mod = 998244353;
const ld eps = 1e-9;
#ifndef M_PI
#define M_PI 3.1415926535
#endif

void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//	freopen("sweets.in", "r", stdin);
//	freopen("sweets.out", "w", stdout);
//	cout << setprecision(7) << fixed;
}

ll n;

struct segt
{
	vint t, add;
	int s, e, res, val;
	segt()
	{
		t.assign(4 * n, n - 1);
		add.assign(4 * n, n - 1);
	}
	void upd_v(int v)
	{
		int vl = v << 1, vr = vl + 1;
		t[v] = min(t[vl], t[vr]);
	}
	int get(int _s)
	{
		s = _s;
		return query(1, 0, n);
	}
	int query(int v, int l, int r)
	{
		if (r - l == 1)
			return t[v];
		int m = (l + r) >> 1, vl = v << 1, vr = vl + 1;
		if (s < m)
			return min(add[v], query(vl, l, m));
		else
			return min(add[v], query(vr, m, r));
	}
	void upd(int _s, int _e, int _val)
	{
		s = _s;
		e = _e;
		val = _val;
		upd_t(1, 0, n);
	}
	void upd_t(int v, int l, int r)
	{
		if (r <= s || e <= l || l >= r)
			return;
		if (s <= l && r <= e)
		{
			t[v] = min(t[v], val);
			add[v] = min(add[v], val);
			return;
		}
		int m = (l + r) >> 1, vl = v << 1, vr = vl + 1;
		upd_t(vl, l, m);
		upd_t(vr, m, r);
		upd_v(v);
	}
};

void solve()
{
	int q;
	cin >> n >> q;
	segt vert, hor;
	ll cnt = ll(n - 2) * (n - 2);
	vert.upd(n - 1, n, 0);
	hor.upd(n - 1, n, 0);
	for (int i = 0; i < q; ++i)
	{
		// cerr << "VERT STATE:\n"; 
		// for (int j = 0; j < n; ++j)
		// {
		//  cerr << vert.get(j) << ' ';
		// }
		// cerr << '\n';
		int t, x;
		cin >> t >> x;
		if (t == 1)
		{
			int len = vert.get(x - 1);
			// cerr << "LN: " << len << '\n';
			cnt -= len - 1;
			hor.upd(0, len, x - 1);
			vert.upd(x - 1, x, 0);
		}
		else
		{
			int len = hor.get(x - 1);
			 // cerr << "LN: " << len << '\n';
			cnt -= len - 1;
			vert.upd(0, len, x - 1);
			hor.upd(x - 1, x, 0);
		}
		// cerr << cnt << '\n';
	}
	cout << cnt << endl;
}

signed main()
{
	io();
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		// solve();
		solve();
//		cerr << '\n';

	}
}

Measured memory_bytes: 28296
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pi pair<int,int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
// const int INF = 1e18+10;

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

signed main(){
  int n,m;
  cin>>n>>m;
  rep(i,m){
    int a;
    cin>>a;
    n-=a;
  }
  cout<<max(-1,n)<<endl;

  return 0;
}


Measured memory_bytes: 3596
from sys import stdin
from itertools import repeat
def main():
    n = int(stdin.readline())
    a = map(int, stdin.readline().split(), repeat(10, n))
    b = map(int, stdin.readline().split(), repeat(10, n))
    f = 1
    c = 0
    while f:
        f = 0
        for i in xrange(n):
            if b[i-1] < b[i] > b[(i+1)%n] and a[i] + b[i-1] + b[(i+1)%n] <= b[i]:
                t = b[i-1] + b[(i+1)%n]
                x = (b[i] - a[i]) / t
                c += x
                b[i] -= x * t
                if b[i] - t >= a[i]:
                    b[i] -= t
                f = 1
    if a == b:
        print c
    else:
        print -1
main()


Measured memory_bytes: 26452
#include <stdio.h>
int main()
{
    int a[3];
    int max,min;
    for (int i=0;i<3;i++){
        scanf("%d", &a[i]);
    }
    max = a[0];
    min = a[0];
    for (int i = 0;i<3;i++){
        if (a[i] > max) max = a[i];
        if (a[i] < min) min = a[i]; 
    }
    printf("%d", max-min);
    return 0;
}

Measured memory_bytes: 128
N = int(input())
c = [0, 0, 0]  # 0, 2, 4

for i in map(int, input().split()):
    if i % 4 == 0:
        c[2] += 1
    elif i % 2 == 0:
        c[1] += 1
    else:
        c[0] += 1

if c[0] <= c[2] + (c[1] == 0):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 11096
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include <cmath>
#include <limits>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N;
	cin >> N;
	int flag = 0;
	for (int i = 1;i <= 9; i++)
	{
		for (int j = 1; j <= 9; j++)
		{
			if (N == i * j)flag++;
		}
	}
	if (flag == 0)cout << "No";
	else cout << "Yes";
}

Measured memory_bytes: 256
n = gets.to_i
quakes = (1..n).map { gets.split.map(&:to_i) }.sort
accum = [0]
quakes.each {|t, a| accum << accum[-1] + Math.log10((10 - a) / 10.0) }
q = gets.to_i
q.times do
  l, r = gets.split.map(&:to_i)
  i = (0..quakes.size-1).bsearch {|i| l < quakes[i][0] } || quakes.size
  j = ((0..quakes.size-1).bsearch {|i| r < quakes[i][0] } || quakes.size) - 1
  p 10 ** (9 + (accum[j + 1] - accum[i]))
end



Measured memory_bytes: 16012
#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;
    map<int,int> m;
    for(int i=2;i<=N;i++){
        int tmp = i;
        for(int j=2;j<=tmp;j++){
            while(tmp%j==0){
                tmp/=j;
                m[j]++;
            }
        }
    }
    ll ans = 1;
    for(int i=2;i<=N;i++){
        ans *=(m[i]+1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 配列数取得
	int liACnt;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &liACnt);

	// ４の倍数・２の倍数・その他の数を取得
	int liCnt4 = 0;
	int liCnt2 = 0;
	int liCntO = 0;
	for (i = 0; i < liACnt; i++) {
		int liVal;
#ifdef D_TEST
		fscanf(szpFpT, "%d", &liVal);
#else
		fscanf(stdin, "%d", &liVal);
#endif
		if (liVal % 4 == 0) {
			liCnt4++;
		}
		else if (liVal % 2 == 0) {
			liCnt2++;
		}
		else {
			liCntO++;
		}
	}
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif

	// 結果セット
	if (liCnt4 >= liCntO) {
		sprintf(lc1Out, "Yes\n");
	}
	else if (liCnt4 == liCntO - 1) {
		if (liCnt2 > 0) {
			sprintf(lc1Out, "No\n");
		}
		else {
			sprintf(lc1Out, "Yes\n");
		}
	}
	else {
		sprintf(lc1Out, "No\n");
	}

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128