akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

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

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

A,B,C,D = inputIL()

print(max(A*B,C*D))

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

#define x first
#define y second
#define x1 X1 
#define x2 X2
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

template <typename T> inline int Chkmax (T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (T &a, T b) { return a > b ? a = b, 1 : 0; }
inline LL read ()
{
	LL sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

LL A, B, C, K;

int main()
{
#ifdef hk_cnyali
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
#endif
	A = read(), B = read(), C = read(), K = read();
	if (K & 1) cout << B - A << endl;
	else cout << A - B << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
from itertools import groupby

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    N = len(S)
    M = 10 ** 5
    K = len(bin(M)) - 2
    A = [[0] * N for _ in range(K)]

    for i, c in enumerate(S):
        if c == 'R':
            A[0][i] += i + 1
        else:
            A[0][i] += i - 1

    for k in range(K - 1):
        for i in range(N):
            A[k + 1][i] = A[k][A[k][i]]

    B = list(range(N))
    ans = [0] * N
    for k in range(K):
        if M & (1 << k):
            for i in range(N):
                B[i] = A[k][B[i]]

    for b in B:
        ans[b] += 1

    print(*ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 93236
s = gets.chomp
f = s[0..1]
e = s[2..3]

month = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]

unless month.include?(f) || month.include?(e)
  puts "NA"
  exit
end

if month.include?(f) && month.include?(e)
  puts "AMBIGUOUS"
  exit
end

if month.include?(f)
  puts "MMYY"
else
  puts "YYMM"
end

Measured memory_bytes: 1916
#include<iostream>
#include<string>
using namespace std;
struct Dice2{
  int dice[6];
  void roll(char c){
    int b;
    if(c == 'E'){
      b = dice[0];
      dice[0] = dice[3];
      dice[3] = dice[5];
      dice[5] = dice[2];
      dice[2] = b;
    }
    if(c == 'W'){
      b = dice[0];
      dice[0] = dice[2];
      dice[2] = dice[5];
      dice[5] = dice[3];
      dice[3] = b;
    }
    if(c == 'N'){
      b = dice[0];
      dice[0] = dice[1];
      dice[1] = dice[5];
      dice[5] = dice[4];
      dice[4] = b;
    }
    if(c == 'S'){
      b = dice[0];
      dice[0] = dice[4];
      dice[4] = dice[5];
      dice[5] = dice[1];
      dice[1] = b;
    }
    if(c == 'R'){
      b = dice[1];
      dice[1] = dice[2];
      dice[2] = dice[4];
      dice[4] = dice[3];
      dice[3] = b;
    }    
  }
  int top() {
    return dice[0];
  }
  int right(){
    return dice[2];
  }
  int left(){
    return dice[3];
  }
  int front(){
    return dice[1];
  }
};

int main(){
  Dice2 d;
  for(int i = 0; i < 6; i++){
    cin >> d.dice[i];
  }
  int n;
  cin >> n;
  while(n--){
    int a,b;
    cin >> a >> b;
    if(d.left() == a){
        d.roll('E');
    }
    if(d.right()==a){
        d.roll('W');
    }
    while(d.top()!=a){
        d.roll('N');
    }
    while(d.front()!=b){
        d.roll('R');
    }
    cout << d.right() << endl;
  }
  return 0;
}



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

int main(){

  vector <int> a;
  int b;
  for(int i = 0;i < 3;i++){
    cin >> b;
    a.push_back(b);
  }
  sort(a.begin(),a.end());
  cout << a[0] + a[1];

}


Measured memory_bytes: 256
#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) + 2), 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: 15496
def s():
 def b(M,x,y,n=0):
  if M[x][y]==0:return n
  M[x][y]=0
  a=max(b(M,x+s,y+t,n+1)for s,t in[(-1,0),(0,-1),(1,0),(0,1)])
  M[x][y]=1
  return a
 for e in iter(input,'0'):
  n,m=int(e),int(input())
  P=[[0]*(n+2)for _ in[0]*(m+2)]
  for i in range(m):P[i+1][1:-1]=map(int,input().split())
  print(max(b(P,i,j)for i in range(1,m+1)for j in range(1,n+1)))
if'__main__'==__name__:s()


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


int main(void)
{
	char com[101];
	int num, x = 0 , max = 0;
	scanf("%d", &num);
	scanf("%s", com);
	
	for (int i = 0; i < num; i++) {
		if (com[i] == 'I') {
			x++;
		}
		else {
			x--;
		}
		if (max < x) {
			max = x;
		}
	}
	printf("%d", max);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  vector<int64_t> a(s.size()+1,0);
  vector<int64_t> b(s.size()+1,0);
  vector<int64_t> c(s.size()+1,0);
  int p=1000000007;
  int64_t x=1;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='A'){
      a[i+1]=(a[i]+x)%p;
      b[i+1]=b[i];
      c[i+1]=c[i];
    }
    if(s.at(i)=='B'){
      a[i+1]=a[i];
      b[i+1]=(b[i]+a[i])%p;
      c[i+1]=c[i];
    }
    if(s.at(i)=='C'){
      a[i+1]=a[i];
      b[i+1]=b[i];
      c[i+1]=(c[i]+b[i])%p;
    }
    if(s.at(i)=='?'){
      a[i+1]=(a[i]*3+x)%p;
      b[i+1]=(b[i]*3+a[i])%p;
      c[i+1]=(c[i]*3+b[i])%p;
      x=x*3%p;
    }
  }
  cout<<c[s.size()]<<endl;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
int main () {
  long double a;
  long double b;
  cin >> a >> b;
  unsigned long ans = a * b;
  cout << (ans > a * b ? ++ans : ans);
}

Measured memory_bytes: 3720
N,A,B=map(int,input().split())

if A>B :
    print(0)
elif N==1 and A!=B:
    print(0)
elif N==1 and A==B:
    print(1)
else:
    number=B-A+1
    N=N-2
    answer=N*(B-A)+1
    print(answer)
    

Measured memory_bytes: 61816
#include <bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0; i<n ; ++i)
#define lpx(i,x,n) for(int i=x; i<n ; ++i)
#define all(v) v.begin() , v.end()
#define sz(v) (int(v.size()))
typedef unsigned long long ul;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<char, int> pci;
typedef vector<pii> vp;
typedef vector<pci> vpc;
typedef pair<int,pii> piii;

int OO = 2e9;
const double eps = 1e-9 ;
const int N = 500000;
int mx = -1e9 , mn = 1e9 ;
int arr[N] ;

int dcmp(double x, double y)
{
    return fabs(x - y) <= eps ? 0 : x > y ? -1 : 1;
}



int main()
{
    ll a, b; cin>> a>> b;
    if((a+b)%2)
        cout << "IMPOSSIBLE\n";
    else
        cout << (a+b)/2 << endl;



    return 0;
}
























Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include "stdc++.h"
#define llint long long int
#define ldouble long double

using namespace std;

int main() {
    int A,B,C;
    cin>>A>>B>>C;
    if(A==B && B==C && C==A){
        cout<< "Yes" <<endl;
    }
    else{
        cout<< "No" <<endl;
    }
return 0;
}

Measured memory_bytes: 256
<?php
$n = trim(fgets(STDIN));
for($i = 0; $i < 4; $i++){
    for($j = 0; $j < 3; $j++){
        $arr[$i][$j] = array_fill(0,10,0);
    }
}
for($i = 0; $i < $n; $i++){
    $in = explode(" ",trim(fgets(STDIN)));
    $arr[$in[0]-1][$in[1]-1][$in[2]-1] += $in[3];
}
for($i = 0; $i < 4; $i++){
    if($i != 0) echo "####################\n";
    for($j = 0; $j < 3; $j++){
        echo " ".implode(" ",$arr[$i][$j])."\n";
    }
}

Measured memory_bytes: 15520
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 3e5 + 7;
int ans[MAXN];
void deal(int st, int ed)
{
    for (int i = st, j = ed; i < j; i++, j--) swap(ans[i], ans[j]);
}
int main()
{
    int n, a, b; scanf("%d%d%d", &n, &a, &b);
    if (n <= (ll)a * b && a + b <= n + 1)
    {
        for (int i = 1; i <= n; i++) ans[i] = i;
        int st = 1, cnt = n;
        for (int i = 0; i < a; i++)
        {
            int num = min(cnt - (a - (i + 1)), b); // printf("num = %d\n", num);
            deal(st, st + num - 1);
            st += num;
            cnt -= num;
        }
        assert(cnt == 0);
    }
    else 
    {
        puts("-1");
        return 0;
    }
    for (int i = 1; i <= n; i++) printf("%d%c", ans[i], " \n"[i == n]);
    return 0;
}

Measured memory_bytes: 3328
N = int(input())
lis = [[] for _ in range(N)]

for i in range(N):
    a = int(input())
    for _ in range(a):
        x,y = map(int,input().split())
        lis[i].append([x,y])

ans = 0
for i in range(2**N):
    s = True
    person =[]
    for _ in range(N):
        person.append(i%2)
        i = i // 2
    for j in range(N):
        if person[j]==1:
            for k in lis[j]:
                if person[k[0]-1] != k[1]:
                    s = False
                    break
            if not s:
                break
    if s and ans < person.count(1):
        ans = person.count(1)
print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


		  try{

			  int count=1;
			  while(true){

			      String ab = input.readLine();
			      int num=Integer.parseInt(ab);
			      if(num==0){
			    	  break;
			      }

			      System.out.println("Case" +" "+count+":"+" "+ num);
			      count++;
			   }


		    }catch(IOException e) {   System.out.println("Exception : " + e);
		    }

	}
}

Measured memory_bytes: 31624
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int count(int N)
{
        int cnt = 0;
        while (N % 2 == 0)
        {
                cnt++;
                N /= 2;
        }
        return cnt;
}

int main()
{
        int A;
        int ans = 0;

        cin >> A;
        bool ok = false;
        rep(i, 26)
        {
                if ((A-4*i)>=0&&(A - 4 * i) % 7 == 0)
                        ok = true;
        }
        if (ok)
                cout << "Yes" << endl;
        else
        {
                cout << "No" << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))

int main(){
	ll N;
	cin >> N;
	vector<pair<ll,ll>> X(N);
	FOR(i,0,N){
		ll x,l;
		cin >> x >> l;
		X[i].first = x+l;
		X[i].second = x-l;
	}
	SORT(X);
	ll ans = 0;
	ll nowx = -INF;
	FOR(i,0,N){
		if(nowx<=X[i].second){
			ans++;
			nowx = X[i].first;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
//#include<iostream>
//#include<vector>
//#include<algorithm>
//#include<map.h>
//#include<string.h>
//#include<climits>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

int main(){
  string s,t;
  cin>>s>>t;
  vector<int >a;
  int d=0;
  for(int i=d;i<t.size()+d;i++){
   if(t.size()+d>s.size())
     break;
    int c=0;
    int temp=i;
    for(int j=0;j<t.size();j++){
      if(s[temp]!=t[j])
        c++;
      temp++;}
    a.push_back(c);
    d++;}
  
  sort(a.begin(),a.end());
  
  cout<<a[0];}
    
   
        

Measured memory_bytes: 3620
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def is_palindrom(S, i, j):
    while i <= j and S[i] == S[j]:
        i += 1
        j -= 1
    return i > j


def solve():
    S = input().strip()
    N = len(S)
    if N == 1 or (is_palindrom(S, 0, N-1) and is_palindrom(S, 0, N//2-1)):
        return 'Yes'
    return 'No'


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 38484
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N; 
  cin >> N; 
long long int A[200010] = {}; 
long long int B[200010] = {}; 
for(int i = 1; i <= N; i++){
cin >> A[i];
B[i] = B[i-1] + A[i]; 
}
sort(B, B+N+1); 
long long int C[200010] = {}; 
C[0] = 1; 
for(int i = 1; i <= N; i++){
if(B[i] == B[i-1]){C[i] = C[i-1] + 1; 
}
else{C[i] = 1;}
}
C[N+1] = 1; 
long long int count = 0; 
for(int i = 0; i <= N; i++){
if(C[i+1] == 1){
count += C[i] * (C[i] - 1)/2;  
}
}
cout << count << endl; 
}

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

using namespace std;

int sum[5050][5050];

void compress(vector<int> &v)
{
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}

int main()
{
  int n, m;
  cin >> n >> m;
  
  int x[5050], y[5050];
  vector<int> xx, yy;
  for(int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
    xx.push_back(x[i]);
    yy.push_back(y[i]);
  }
  
  compress(xx);
  compress(yy);

  for(int i = 0; i < n; i++) {
    x[i] = find(xx.begin(), xx.end(), x[i]) - xx.begin();
    y[i] = find(yy.begin(), yy.end(), y[i]) - yy.begin();
    sum[y[i]+1][x[i]+1]++;
  }

  for(int i = 0; i < yy.size(); i++) {
    for(int j = 0; j < xx.size(); j++) {
      sum[i+1][j+1] += sum[i+1][j] + sum[i][j+1] - sum[i][j];
    }
  }

  for(int i = 0; i < m; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1 = lower_bound(xx.begin(), xx.end(), x1) - xx.begin();
    y1 = lower_bound(yy.begin(), yy.end(), y1) - yy.begin();
    x2 = upper_bound(xx.begin(), xx.end(), x2) - xx.begin();
    y2 = upper_bound(yy.begin(), yy.end(), y2) - yy.begin();
    cout << sum[y2][x2] - sum[y2][x1] - sum[y1][x2] + sum[y1][x1] << endl;
  }
  
  return 0;
}

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

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

    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> A(m);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        A[i] = {b, a};
    }
    sort(A.begin(), A.end());
    for(auto &x : A){
        swap(x.second, x.first);
    }

    int ans = 0, right = -1;
    for(auto x : A){
        if(right < x.first){
            right = x.second - 1;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <string.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX_N 100
using namespace std;

int main(void) {
  int N;
  cin >> N;
  int A[2][MAX_N];
  int SUM[2] = {0, 0};
  rep(i, 2) {
    rep(j, N) {
      cin >> A[i][j];
      SUM[i] += A[i][j];
    }
  }
  SUM[0] += A[1][N - 1];

  int MaxA = SUM[0];
  for (int i = 1; i < N; i ++) {
    SUM[0] -= A[0][N-i];
    SUM[0] += A[1][N-i-1];
    MaxA = max(MaxA, SUM[0]);
  }
  cout << MaxA << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define iof ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pi 3.1415926535897
#define mod 1000000007
#define inf (1ll<<60)
using namespace std;

int main()
{
    iof;
    string s,t; cin>>s>>t;
    ll n1=s.length(),n2=t.length();
    ll dp[n1+1][n2+1];
    for(ll i=0;i<=n1;i++)
        for(ll j=0;j<=n2;j++)
          dp[i][j]=0;
    for(ll i=1;i<=n1;i++)
    {
        for(ll j=1;j<=n2;j++)
        {
            if(s[i-1]==t[j-1])
              dp[i][j]=dp[i-1][j-1]+1;
            else
              dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    //cout<<dp[n1][n2];
    vector<char>v;
    v.clear();
    ll i=n1,j=n2;
    while(i-1>=0 and j-1>=0)
    {
        if(s[i-1]==t[j-1])
        {
            v.push_back(s[i-1]);
            i--;
            j--;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
                i--;
            else
                j--;
        }
    }
    ll n=v.size();
   // cout<<n<<" "<<endl;
    for(ll i=n-1;i>=0;i--)
        {
            cout<<v[i];
        }
}


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

typedef long long ll;


int main () {
	ll N, K;
	int A[200001] = {0};
	int fst[200001] = {0};
	cin >> N >> K;
	for (int i=1; i<=N; i++)
		cin >> A[i];
	int cnt = 1, idx=1;
	fst[1] = 1;
	while (fst[A[idx]]==0) {
		cnt ++;
		fst[A[idx]] = cnt;
		idx = A[idx];
	}
	if (K>=fst[A[idx]]){
		int tmp = ((K-fst[A[idx]]+1) % (cnt-fst[A[idx]]+1)) + fst[A[idx]] - 1;
		idx = 1;
		for (int i=0; i<tmp; i++)
			idx = A[idx];
		cout << idx << endl;
	} else {
		idx = 1;
		for (int i=0; i<K; i++)
			idx = A[idx];
		cout << idx << endl;
	}
	return 0;
}

Measured memory_bytes: 5200
a = []
for _ in range(3):
    a.append(list(map(int , input().split())))
n = int(input())

x = [[0] * 3 for _ in range(3)]

for _ in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if a[i][j] == b:
                x[i][j] = 1

for i in range(3):
    if sum(x[i]) == 3:
        print('Yes')
        exit()
s0 = 0
s1 = 0
s2 = 0
for i in range(3):
    s0 += x[i][0]
    s1 += x[i][1]
    s2 += x[i][2]
if s0 == 3 or s1 == 3 or s2 == 3:
    print('Yes')
    exit()
if x[0][0] + x[1][1] + x[2][2] == 3:
    print('Yes')
    exit()
if x[0][2] + x[1][1] + x[2][0] == 3:
    print('Yes')
    exit()
print('No')






Measured memory_bytes: 3064
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y,z;
    cin >> x >> y >> z;
    print(z,x,y);
    

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
using namespace std;
#define ll int64_t
#define REP(i, n) for (ll i=0; i<n; i++)

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

    ll N;
    cin >> N;
    vector<ll> a(3*N);
    REP (i, 3*N) {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());

    ll ans = 0;
    for (ll i=3*N-2; i>=N; i=i-2) {
        ans += a.at(i);
        // cout << ans << "\n";
    }

    cout << ans << "\n";
}

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

char p1[42000010];
int n,k,bg[21][1<<20|3],cnt,p2[42000010],h1[1<<20|3],h0[1<<20|3],an,ans,f[42000010];
char s[21][1<<20|3];

int main()
{
	h1[0]=-1,h1[1]=0;
	for (int i=2; i<(1<<20); i++) h1[i]=h1[i>>1]+1;
	h0[0]=h0[1]=-1;
	for (int i=2; i<(1<<20); i++)
	{
		h0[i]=-1;
		for (int j=h1[i]; j>=0; j--)
			if (!(i>>j&1)) {h0[i]=j; break;}
	}
	scanf("%d%d",&n,&k),cnt=0;
	for (int i=0; i<=n; i++) scanf("%s",s[i]);
	for (int i=0; i<=n; i++)
		for (int j=0; j<(1<<i); j++)
		{
			bg[i][j]=(++cnt);
			for (int k=cnt; k<=cnt+i; k++) p1[k]=i,p2[k]=j;
			cnt+=i;
		}
	an=0;
	for (int i=cnt; i; i--) 
		if (i!=bg[p1[i]][p2[i]])
		{
			if (i==bg[p1[i]][p2[i]]+p1[i]&&s[p1[i]][p2[i]]=='1') f[i]++;
			int len=i-bg[p1[i]][p2[i]];
			f[bg[p1[i]-len][p2[i]>>len]]+=f[i];
			int p=h1[p2[i]&((1<<len)-1)];
			if (p!=-1) f[bg[p1[i]-(len-1-p)][((p2[i]>>len)<<p+1)|(p2[i]&((1<<p)-1))|(1<<p)]+p]+=f[i];
			if (p!=len-1) p=len-1; else p=h0[p2[i]&((1<<len)-1)];
			if (p!=-1) f[bg[p1[i]-(len-1-p)][((p2[i]>>len)<<p+1)|(p2[i]&((1<<p)-1))]+p]+=f[i];
		} else
		{
			if (f[i]<k) continue;
			if (p1[i]>an) an=p1[i],ans=p2[i]; else
			if (p1[i]==an&&ans>p2[i]) ans=p2[i]; 
		}
	for (int i=an-1; i>=0; i--) putchar((ans>>i&1)+'0');
	return puts(""),0;
}

Measured memory_bytes: 446208
#include <bits/stdc++.h>
#define ll long long int
#define pi 3.1415926535897
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug 0
#define loop(a,b) for(a=0;a<b;a++)
#define test() while(t--)
 
using namespace std;
 

 

int pointer,n;
ll maxm,res;

ll vis[100005];
ll ar[100005];
ll ans[100005];
ll mark[100005];
ll segTree[500005];
ll cost[100006];

vector<int> adj[100005];

void constructTree(int node, int start, int end)
{
    if(start == end)
    {
         segTree[node] = 0;
    }
    else
    {
        int mid = (start + end) / 2;
        constructTree(2*node, start, mid);
        constructTree(2*node+1, mid+1, end);
        segTree[node] = max(segTree[2*node],segTree[2*node+1]);
    }
}


void update(int si, int ss, int se,int pos,ll val)
{
    if (ss>se || pos<ss || pos>se)
        return ;
        
 
   
    if (ss==se)
    {
    	//int old_val=cost[ss];
    	cost[ss]=val;
    	ll new_val=cost[ss];
    	ll old_val=segTree[si];
    	ll diff=new_val-old_val;
        segTree[si]+=diff;
        return;
    }
    
 
    int mid = (ss+se)/2;
    update(si*2, ss, mid,pos,val);
    update(si*2+1, mid+1,se,pos,val);
 
    segTree[si] = max(segTree[si*2],segTree[si*2+1]);
    //return;
}

ll get(int node, int start, int end, int l, int r)
{
	
	if(r < start || end < l)
    {
        return 0;
    }
    if(l <= start && end <= r)
    {
        return segTree[node];
    }
    
    
   
    int mid = (start + end) / 2;
    ll min1 = get(2*node, start, mid, l, r);
    ll min2 = get(2*node+1, mid+1, end, l, r);
    return max(min1,min2);
}

void DFS(int s)
{

	vis[s]=true;
	
	
	vector<int>::iterator it;
	vector<pair<int,ll> >::iterator jt;
	
	int val=ar[s];
	
	ans[s]=val;
//	update(1,1,n,pointer,ans[s]);
	pointer++;
	
	
	for(it=adj[s].begin();it!=adj[s].end();++it)
	{
		if(!vis[*it])
		{
		
		//val=ar[*it];
		mark[*it]=ar[*it]^ans[s];
		res=res^mark[*it];
		
		//cout<<res<<"\n";
		if(res>maxm)
		maxm=res;
		DFS(*it);	
			
		}
		//answ[*it]=dist[*it];
	
		//update(1,1,n,pointer,dist[*it]);
		
			
		
	   }
	
	pointer--;
	res=mark[s];
	
	
}


int main()
{
	int m,a,b,i,j,q,v,home,k,t,n;
	ll w;
	
	cin>>n>>m;
	
	cout<<(n-1)*(m-1);
	return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define int ll

signed main(){
    int n;
    int a[114514],b[114514];
    scanf("%lld",&n);
    REP(i,n) scanf("%lld",&a[i]),b[i] = a[i];

    int ans=0,anz=0;
    if(a[0]<1){
        ans = 1 - a[0];
        a[0] = 1;
    }    
    REP1(i,n-1){
        a[i] += a[i-1];
        if(i%2 && a[i]>=0){
            ans += a[i]+1;
            a[i] = -1;
        } else if(i%2==0 && a[i]<=0){
            ans += abs(a[i])+1;
            a[i] = 1;
        }
    }

    if(b[0]>-1){
        anz = b[0] + 1;
        b[0] = -1;
    }
    REP1(i,n-1){
        b[i] += b[i-1];
        if(i%2 && b[i]<=0){
            anz += 1 - b[i];
            b[i] = 1;
        } else if(i%2==0 && b[i]>=0){
            anz += b[i] + 1;
            b[i] = -1;
        }
    }
    printf("%lld\n",min(ans,anz));
    return 0;
}

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	long long int a, sum = 0; cin >> a;
	sum = a + (a * a) + (a * a * a) ;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
long long ans=-1,a,b,c;
long long tmp1,tmp2,tmp3;
int main()
{
	cin>>a>>b>>c;
	if(a%2==1)
	{
		tmp1=(a/2)*b*c;
		tmp2=((a/2)+1)*b*c;
		ans=abs(tmp1-tmp2);
	}
	else ans=0;
	if(b%2==1)
	{
		tmp1=(b/2)*a*c;
		tmp2=((b/2)+1)*a*c;
		ans=min(ans,abs(tmp1-tmp2));
	}
	else ans=0;
	if(c%2==1)
	{
		tmp1=(c/2)*b*a;
		tmp2=((c/2)+1)*b*a;
		ans=min(ans,abs(tmp1-tmp2));
	}
	else ans=0;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
/*
[m-solutions2019] C - Best-of-(2n-1)
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 100000;
const int MOD = 1e9 + 7;

class gf {
public:
    int n;
    int extgcd(int a, int b, int& x, int& y) {
        int d = a;
        if (b != 0) {
            d = extgcd(b, a % b, y, x);
            y -= (a / b) * x;
        } else {
            x = 1;
            y = 0;
        }
        return d;
    }
    int mod_inv(int a, int m) {
        int x, y;
        extgcd(a, m, x, y);
        return (m + x) % m;
    }
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf inv() { return gf(mod_inv(n, MOD)); }
    gf operator+(gf x) { return gf((n + x.n) % MOD); }
    gf operator-(gf x) { return gf((n - x.n + MOD) % MOD); }
    gf operator*(gf x) { return gf((1LL * n * x.n) % MOD); }
    gf operator/(gf x) { return *this * x.inv(); }
};

int N, A, B, C;
gf pa[2 * MAX_N + 1], pb[2 * MAX_N + 1], ph[2 * MAX_N + 1];
gf fact[2 * MAX_N + 1];

ll solve() {
    fact[0] = fact[1] = 1;
    for (int i = 2; i <= 2 * MAX_N; i++) {
        fact[i] = fact[i - 1] * i;
    }

    pa[0] = 1;
    pb[0] = 1;
    ph[0] = 1;
    for (int i = 1; i <= 2 * N; i++) {
        pa[i] = pa[i - 1] * A;
        pb[i] = pb[i - 1] * B;
        ph[i] = (ph[i - 1] / (100 - C));
    }

    gf ans = 0;
    for (int i = N; i <= 2 * N - 1; i++) {
        gf tmp = fact[i - 1] / (fact[N - 1] * fact[i - N]);
        tmp = tmp * (pa[N] * pb[i - N] + pa[i - N] * pb[N]) * i * 100;
        tmp = tmp * ph[i + 1];
        ans = ans + tmp;
    }

    return ans.n;
}

int main() {
    cin >> N >> A >> B >> C;

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <utility>

u_int getGCD(u_int m, u_int n){
  u_int temp;
  if(m < n)
    std::swap(m,n);
  while(n != 0){
    temp = m % n;
    m = n;
    n = temp;
  }
  return m;
}

inline u_int getLCM(u_int m, u_int n, u_int gcd){
  return m * (n / gcd);
}

int main(){
  u_int a, b, gcd;
  while(std::cin >> a >> b){
    gcd = getGCD(a, b);
    std::cout << gcd << " " << getLCM(a, b, gcd) << std::endl;
  }
  return 0;
}

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

using namespace std;
int slv(string s,string t){
    int ret=0;
    for(int i=0;i<s.size();i++)
        ret+=(s[i]!=t[i]);

    return ret;
}
int main()
{
    ///{}
    string s,t;
    cin>>s>>t;
    int ans=INT_MAX;
    for(int i=0;i+t.size()<=s.size();i++){
        string s2(s.begin()+i,s.begin()+i+t.size());
        ans=min(ans,slv(s2,t));
    }
    cout<<ans<<'\n';
    return 0;
}


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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1e18+1;

signed main() {
	int N;
	cin >> N;
	vector<int> a(N);
	Rep(i, N) cin >> a[i];
	vector<int> b = a;
	sort(All(b));
	int c = b[N/2-1], d = b[N/2];
	Rep(i, N) {
		if ( a[i] <= c ) cout << d << endl;
		else cout << c << endl;
	}
	return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

bool cmp(pii a,pii b)
{
	if(a.S<b.S) return true;
	if(a.S==b.S && a.F<b.F) return true;
	return false;
}

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	vector<pii> v(n);;
	for(auto &i:v) cin>>i.F>>i.S;
	sort(all(v),cmp);
	int now=0,dead=0;
	for(auto &i:v)
	{
		dead=i.S;
		now+=i.F;
		if(now>dead)
		{
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
}















Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<string> s(N);
    int l=0,r=N;
    cout<<l<<endl;
    cin>>s[l];
    if(s[l]=="Vacant") return 0;
    REP(_,20){
        int mid=(l+r)>>1;
        cout<<mid<<endl;
        cin>>s[mid];
        if(s[mid]=="Vacant") break;
        if((s[mid]==s[l])==((mid-l+1)&1)) l=mid;
        else r=mid;
    }
}


Measured memory_bytes: 1620
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, xx, yy, hoge;
	cin >> nn >> xx >> yy;
	int64 memo[nn][nn];
	xx--;yy--;
	for(int64 ii = 0;ii < nn;ii++)
	{
		for(int64 jj = 0;jj < nn;jj++)
		{
			memo[ii][jj] = -1;
		}
	}
	for(int64 ii = 0;ii < nn;ii++)
	{
		queue<int64> qq;
		qq.push(ii);
		memo[ii][ii] = 0;
		while(!qq.empty())
		{
			hoge = qq.front();
			qq.pop();
			vector<int64> nhoge;
			if(hoge > 0)
			{
				nhoge.push_back(hoge - 1);
			}
			if(hoge < nn - 1)
			{
				nhoge.push_back(hoge + 1);
			}
			if(hoge == xx)
			{
				nhoge.push_back(yy);
			}
			if(hoge == yy)
			{
				nhoge.push_back(xx);
			}
			for(vector<int64>::iterator ite = nhoge.begin();ite != nhoge.end();ite++)
			{
				if(memo[ii][*ite] == -1)
				{
					memo[ii][*ite] = memo[ii][hoge] + 1;
					qq.push(*ite);
				}
			}
		}
	}
	int64 ans[nn] = {0};
	for(int64 ii = 0;ii < nn;ii++)
	{
		for(int64 jj = 0;jj < nn;jj++)
		{
			ans[memo[ii][jj]]++;
		}
	}
	for(int64 ii = 1;ii < nn;ii++)
	{
		cout << ans[ii] / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 34828
package main
import (
  "fmt"
  "os"
)
func main() {
  var h,w int64
  fmt.Scan(&h,&w)
  if h%3 == 0 || w%3 == 0 {
    fmt.Println(0)
    os.Exit(0)
  }
  var d,dmin,s1,s2,s3,h1,w1 int64
  dmin = min(h,w)
  h1 = h/3
  w1 = (w+1)/2
  s1 = h1*w
  s2 = (h-h1)*w1
  s3 = (h-h1)*(w-w1)
  d = max(s1,s2,s3)-min(s1,s2,s3)
  dmin = min(dmin,d)
  h1 = (h+2)/3
  w1 = (w+1)/2
  s1 = h1*w
  s2 = (h-h1)*w1
  s3 = (h-h1)*(w-w1)
  d = max(s1,s2,s3)-min(s1,s2,s3)
  dmin = min(dmin,d)
  h1 = (h+1)/2
  w1 = w/3
  s1 = h*w1
  s2 = h1*(w-w1)
  s3 = (h-h1)*(w-w1)
  d = max(s1,s2,s3)-min(s1,s2,s3)
  dmin = min(dmin,d)
  h1 = (h+1)/2
  w1 = (w+2)/3
  s1 = h*w1
  s2 = h1*(w-w1)
  s3 = (h-h1)*(w-w1)
  d = max(s1,s2,s3)-min(s1,s2,s3)
  dmin = min(dmin,d)
  fmt.Println(dmin)
}
func max(n ...int64) int64 {
  var m int64 = n[0]
  for i:=0;i<len(n);i++ {
    if m < n[i] { m = n[i] }
  }
  return m
}
func min(n ...int64) int64 {
  var m int64 = n[0]
  for i:=0;i<len(n);i++ {
    if m > n[i] { m = n[i] }
  }
  return m
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
// #define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const int INF = -1;
ll dp[100005][13];

signed main(void) {
	ll A, B;
	cin >> A >> B;
	if (A < B) {
		ll tmp = A;
		A = B;
		B = tmp;
	}

	ll r = A % B;
	while (r!=0) {
		A = B;
		B = r;
		r = A%B;
	}

	ll ans = 1;
	if (B%2 == 0) {
		B = B/2;
		ans++;
		while (B%2 == 0) {
			B = B/2;
		}
	}
	ll now = 3;
	while (now <= B) {
		bool isDivided = false;
		while (B%now == 0) {
			isDivided = true;
			B = B/now;
		}
		if (isDivided) {
			ans++;
		}
		now += 2;
		if (now <= B && now >= sqrt(B)) {
			ans++;
			break;
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  ll a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  if(t*(v-w)>=abs(a-b)) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
using namespace std;
int main(){
    int a,b,c,d,e;
    cin >> a >> b >> c;
    d = max(max(a,b),c);
    e = min(min(a,b),c);
    cout << d-e << endl;
} 

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Decimal Sequences - Time Limit Exceeded
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int n = parseInt(br.readLine());
		char[] seq = new char[n];

		StringTokenizer st;
		int _i = 0;
		while ((line = br.readLine()) != null && !line.isEmpty()) {
			st = new StringTokenizer(line);
			while (st.hasMoreTokens()) {
				seq[_i] = st.nextToken().charAt(0);
				_i++;
			}
		}

		//solve
		boolean[] nums = new boolean[1_000_000];
		outer:
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				int len = j - i + 1;
				if ((seq[i] == '0' && len > 1) || len > 6) continue outer;
				//
				char[] _seq = Arrays.copyOfRange(seq, i, j + 1);
				nums[parseInt(String.valueOf(_seq))] = true;
			}
		}

		for (int i = 0; i < nums.length; i++) {
			if (!nums[i]) {
				System.out.println(i);
				break;
			}
		}

	} //end main
}

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

#define reint register int
#define coint const int

using namespace std;

typedef long long ll;

coint SIZE = 100000 + 5;

ll li[SIZE], ans[SIZE];

inline int getint(void) {
    reint x = 0, ch = getchar();
    for (; ch < '0' || ch > '9'; ch = getchar());
    for (; ch >= '0' && ch <= '9';
            x = (x << 1) + (x << 3) + (ch - '0'), ch = getchar());
    return x;
}

int main(void) {
    coint n = getint();
    for (reint i = 1; i <= n; ++i) li[i] = getint();
    ll sum = 0;
    for (reint i = 1; i <= n; ++i) sum += li[i];
    sum >>= 1;
    for (reint i = 1; i < n; i += 2) sum -= li[i];
    ans[n] = sum;
    for (reint i = n - 1; i; --i)
        ans[i] = li[i] - ans[i + 1];
    for (reint i = 1; i <= n; ++i)
        printf("%lld%c", ans[i] << 1, " \n"[i == n]);
    return 0;
}



Measured memory_bytes: 2816
while True:
    n,x = map(int,input().split())
    if n == 0 and x == 0:
        break
    an = 0
    for a in range(1,n+1):
        for b in range(1,n+1):
            if b <= a:
                continue
            c = x-(a+b)
            if c > b and c <= n:
                an += 1
    print("%d"%(an))


Measured memory_bytes: 5596
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	static Scanner scanner;

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

	    int A=gi();
	    int B=gi();
	    int x=-1;
	    for (double i=1; i<=1000; i++) {
	    	if((Math.floor(i*0.08) == A) && (Math.floor(i*0.1)==B)) {
	    		x=(int)i;
	    		break;
	    	}
	    }

        System.out.print(x);

//        if (b>c) {
//        	System.out.println(c);
//        }else {
//        	System.out.println(b);
//        }
	}
	
	// ユークリッドの互除法
    public static int uclid(int m, int n) {
    	if (m<n) {
			m^=n;
			n^=m;
			m^=n;
		}

		while(true) {
			int t=m%n;
			if (t==0) {
				return n;
			} else {
				m=n;
				n=t;
			}
		}
    }

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35464
#include "bits/stdc++.h"
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

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

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	int N;
	cin >> N;
	vi a(N + 1, 0);
	for (int i = 0; i < N; i++)
		cin >> a[i + 1];

	int ans = 0;
	int righting = 1;
	while (ans <= N) {
		righting = a[righting];
		ans++;
		if (righting == 2) {
			cout << ans << endl;
			return 0;
		}
	}

	cout << -1 << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string s;
    cin>>s;
    string t="";
    vector<int> idx,xnum;
    idx.reserve(SZ(s));
    int cnt=0;
    int tmp=0;
    FORE(x,s) {
        if(x!='x') {
            t+=x;
            idx.push_back(cnt++);
            xnum.push_back(tmp);
            tmp=0;
        } else {
            tmp++;
        }
    }
    xnum.push_back(tmp);

    REP(i,SZ(t)/2) {
        if(t[i]!=t[SZ(t)-i-1]) {
            cout<<-1<<endl;
            return 0;
        }
    }

    int ans=0;
    REP(i,SZ(xnum)/2) {
        ans+=abs(xnum[i]-xnum[SZ(xnum)-i-1]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2248