akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			int[] tri = new int[3];
			for (int j = 0; j < 3; j++) {
				tri[j] = scan.nextInt();
				tri[j] *= tri[j];
			}
			Arrays.sort(tri);
			if (tri[0] + tri[1] == tri[2]) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
		}
	}

}

Measured memory_bytes: 23380
float a,b,c,d,e,f,g,h,D;main(){for(;~scanf("%f%f%f%f%f%f%f%f",&a,&b,&c,&d,&e,&f,&g,&h);puts(e>0&&f>0&&e+f<1?"YES":"NO"))a-=e,b-=f,c-=e,d-=f,g-=e,h-=f,D=a*d-b*c,e=(g*d-h*c)/D,f=(h*a-g*b)/D;}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
long long n,a,b,x,z;
int main()
{
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x<a||x>=b)z++;
    }
    cout<<z<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    int Children;
    int Candies = 0;
    
    Scanner scanner = new Scanner(System.in);
    Children = scanner.nextInt();
    
    if(Children >= 1 && Children <= 100){
      for(int i = 1; i <= Children; i++){
        Candies += i;
      }
      System.out.println(Candies);
    }
  }
}

Measured memory_bytes: 22612
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

//#define __int64 long long
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

int main(){
	int a,b,h;
	cin >> a >> b >> h;
	cout << h * (a + b) / 2 << endl;
    
    return 0;
}

Measured memory_bytes: 764
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) when x < y -> Node (y, doit l, r)
    | Node (y, l, r) -> Node (y, l, doit r)
  in doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> (f x; doit l; doit r)
  in doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> (doit l; f x; doit r)
  in doit t

let print t =
  let f e = print_string " "; print_int e in
  inorder f t;
  print_newline ();
  preorder f t;
  print_newline ()

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, _, _) when x = y -> true
    | Node (y, l, _) when x < y -> doit l
    | Node (_, _, r) -> doit r
  in doit t

let delete x t =
  let rec dudu = function
    | Nil -> exit 1
    | Node (x, Nil, _) -> x
    | Node (_, l, _) -> dudu l
  and wa = function
    | Nil -> exit 1
    | Node (_, Nil, r) -> r
    | Node (x, l, r) -> Node (x, wa l, r)
  and doit = function
    | Nil -> exit 1
    | Node (y, l, r) when x = y ->
      if l = Nil then r
      else if r = Nil then l
      else Node (dudu r, l, wa r)
    | Node (y, l, r) when x < y -> Node (y, doit l, r)
    | Node (y, l, r) -> Node (y, l, doit r)
  in doit t

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i ->
      let s1 = sub s 0 i in
      doit s1 (sub s (i + 1) (length s - length s1 - 1) :: acc)
  in doit str []

let () =
  let m = read_int () in
  let rec read i t =
    if i < m then begin
      match split (read_line ()) ' ' with
      | ["insert"; n] -> read (i + 1) (insert (int_of_string n) t)
      | ["find"; n] -> (print_endline (if find (int_of_string n) t then "yes" else "no"); read (i + 1) t)
      | ["delete"; n] -> read (i + 1) (delete (int_of_string n) t)
      | _ -> (print t; read (i + 1) t)
    end in
  read 0 (create ())

Measured memory_bytes: 25252
/*
文字列の配列の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
 */
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        n=(n+1)/2;
        if(n>=k)out.println("YES");
        else out.println("NO");
    }
}

Measured memory_bytes: 23764
#include<stdio.h>
#define A 200000

int main(){
    int n, i, maxv, minv;
	int R[A];
	scanf("%d", &n);

    for(i=0; i<n; i++){
		scanf("%d", &R[i]);
    }
	for(i=0; i<n-1;i++){
        if(i==0 || minv>R[i]){
            minv=R[i];
        }
	if(i==0 || maxv<R[i+1]-minv){
		maxv=R[i+1]-minv;
        }
    }

    printf("%d\n", maxv);

    return 0;
}


Measured memory_bytes: 2516
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long X=1000000000+7;

int main() {
  int x,y,z;
  cin>>x>>y>>z;
  cout<<(x-z)/(y+z)<<endl;
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    k = inp()
    a,b = inpm()
    if (b//k)*k >= a:
        print('OK')
    else:
        print('NG')
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 10844
import math

a, b, x = [int(i) for i in input().split()]

if x < a**2 * b/2:
  xd = 2*x/a/b
  print(math.degrees(math.atan(b/xd)))
else:
  xdd = 2*(b-(x/a**2))
  print(math.degrees(math.atan(xdd/a)))

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

using namespace std;
using ll = long long;

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

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];

  ll sum = 0;
  rep(i, n) {
    if (i & 1)
      sum -= a[i];
    else
      sum += a[i];
  }
  ll ans[n];
  ans[0] = sum;
  rep(i, n) ans[i + 1] = 2 * a[i] - ans[i];
  rep(i, n) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 4704
h, w, k = map(int, input().split())
c = []
for cnt in range(h):
    c.append(input())

black_num = 0
temp_list = []
row_bit = []
line_bit = []

ans = 0

# for cnt_h in range(h):
#     for cnt_w in range(w):
#         if c[cnt_h][cnt_w] == "#":
#             black_num += 1
# if black_num == k:
#     print(1)
if 1 == 2:
    print()
else:
    for i in range(2**h):
        temp_bit = [0] * h

        for j in range(h):
            if((i >> j) & 1):
                temp_bit[h - 1 - j] = 1

        row_bit.append(temp_bit)

    for i in range(2**w):
        temp_bit = [0] * w

        for j in range(w):
            if((i >> j) & 1):
                temp_bit[w - 1 - j] = 1

        line_bit.append(temp_bit)

    # print(row_bit)
    # print(line_bit)

    for cnt_row in range(2**h):
        for cnt_line in range(2**w):
            temp_list = []
            black_num = 0
            for cnt_h in range(h):
                if row_bit[cnt_row][cnt_h] == 0:
                    # temp_list.append(c[cnt_h])
                    for cnt_w in range(w):
                        if line_bit[cnt_line][cnt_w] == 0:
                            # print("this", temp_list[cnt_line][cnt_w])
                            if c[cnt_h][cnt_w] == '#':
                                black_num += 1

            # black_num = 0
            # for cnt_h in range(len(temp_list)):
            #     for cnt_w in range(len(temp_list[cnt_h])):
            #         if temp_list[cnt_h][cnt_w] == "#":
            #             black_num += 1
            if black_num == k:
                ans += 1

    print(ans)



Measured memory_bytes: 9268
h, w, k = map(int, input().split())
f = [input() for _ in range(h)]

ans = 10 ** 18
for i in range(1 << (h-1)):
    possible = True
    x = i
    cut = [0] * (h-1)
    for j in range(h-1):
        cut[j] = x & 1
        x >>= 1
    index = [0] * h
    for j in range(h-1):
        index[j+1] = index[j] + cut[j]
    n = index[h-1] + 1

    s = [0 for _ in range(n)]
    ver = 0
    for j in range(w):
        need = False
        for z in range(h):
            s[index[z]] += int(f[z][j])
            if s[index[z]] > k:
                need = True
        if need:
            ver += 1
            s = [0 for _ in range(n)]
            for z in range(h):
                s[index[z]] += int(f[z][j])
                if s[index[z]] > k:
                    possible = False
    if possible:
        ans = min(ans, sum(cut) + ver)
print(ans)

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

double *h=NULL;
double dp[3001][3001];
double f(double *a,int n,int x)
{
    if(x == 0)
        return 1;
    if(n==0)
        return 0;
    if(dp[n][x] > -0.9)
    {
        return dp[n][x];
    }

    // if on tossing nth coin we get head;
    return dp[n][x] = a[n] * f(a,n-1,x-1) + ((double)1-a[n]) * f(a,n-1,x);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    memset(dp,-1,sizeof(dp));

    int n;
    cin>>n;
    h = new double[n+1];
    for(int i=1;i<=n;++i)
    {
        cin>>h[i];
    }    
    int x = n/2 + 1;
    cout<<fixed<<setprecision(10)<<f(h,n,x);
    return 0;
}

Measured memory_bytes: 70912
#include <iostream>

using namespace std;

int main()
{
	for (int i = 1; i <= 9; i++)
	{
		for (int j = 1; j <= 9; j++)
		{
			cout << i << 'x' << j << '=' << i * j << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1116
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

import itertools
all_pat = list(itertools.permutations(range(1, N+1)))

def index_p(i):
  return all_pat.index(i)+1

print(abs(index_p(P) - index_p(Q)))

Measured memory_bytes: 8052
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
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()))

def err():
    print('No')
    quit()
def ok():
    print('Yes')
    quit()

n = inp()
a = inpl()
a.sort()
c = Counter(a)
now = a[0]
for i in range(1,n):
    now ^= a[i]
if now: err()
if a[0] == a[-1] == 0: ok()
if n == 3:
    x,y,z = a
    if x == 0 and y == z: ok()
if n%3: err()
if len(c.keys()) == 3:
    for x in c.values():
        if x != n//3:
            err()
    x,y,z = c.keys()
    if x^y != z:
        err()
elif len(c.keys()) == 2:
    x,y = sorted(list(c.values()))
    if x != n//3 or y != n//3*2:
        err()
    x,y = sorted(list(c.keys()))
    if x != 0: err()
else: err()
ok() 


Measured memory_bytes: 21756
#include <algorithm>
#include <iostream>
#include <list>
#include <vector>

class TNode
{
	std::list<TNode*> FNexts;
	int  FDistance;
public:
	TNode()
	: FDistance(-1)
	{
	}
	
	int GetDistance()const {return FDistance;}
	
	void Push(TNode* New)
	{
		FNexts.push_back(New);
	}
	
	void Visit(int Distance)
	{
		if(FDistance >= 0 && Distance > FDistance) return;
		FDistance = Distance;
		for(std::list<TNode*>::iterator It = FNexts.begin(); It != FNexts.end(); ++It){
			(*It)->Visit(Distance + 1);
		}
	}
};

class TGraph
{
	std::vector<TNode*> FNodes;
public:
	TGraph(int Count)
	: FNodes(Count + 1)
	{
		for(int i = 1; i < Count + 1; ++i){
			FNodes[i] = new TNode();
		}
	}
	
	~TGraph()
	{
		for(unsigned int i = 1; i < FNodes.size(); ++i){
			delete FNodes[i];
		}
	}
	
	void InputNode()
	{
		int Index;
		std::cin >> Index;
		int BranchCount;
		std::cin >> BranchCount;
		for(int i = 0; i < BranchCount; ++i){
			int Target;
			std::cin >> Target;
			FNodes[Index]->Push(FNodes[Target]);
		}
	}
	
	void BreathFirstSearch()
	{
		FNodes[1]->Visit(0);
	}
	
	int Distance(int Target)const
	{
		return FNodes[Target]->GetDistance();
	}
};

int main()
{
	int Count;
	std::cin >> Count;
	TGraph Graph(Count);
	for(int i = 0; i < Count; ++i){
		Graph.InputNode();
	}
	Graph.BreathFirstSearch();
	
	for(int i = 0; i < Count; ++i){
		std::cout << i + 1 << " " << Graph.Distance(i + 1) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <map>
using namespace std;
int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    int result = 0;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        mp[a]++;
        result++;
        if (mp[a] == a) {
            result -= a;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 7988
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{
    fastt;

    ll n, m, k, i, j, x, y, s=0, h, f=0;
    cin>>n;
    for(i=1; i<=5000000; i++){
        s=(s*10 +7)%n;
        if(s==0){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
    return 0;
}





Measured memory_bytes: 3640
import java.util.*;
 class Main{

    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int a =sc.nextInt();
      int b =sc.nextInt();
      if(a==1 && b==2){
        System.out.println("3");
        return;
      }
      if(a==1 && b==3){
        System.out.println("2");
        return;
      }
      if(a==2 && b==1){
        System.out.println("3");
        return;
      }
      if(a==2 && b==3){
        System.out.println("1");
        return;
      }
      if(a==3 && b==1){
        System.out.println("2");
        return;
      }
      if(a==3 && b==2){
        System.out.println("1");
        return;
      }
    }
}


Measured memory_bytes: 22996
import java.util.*;

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

      Scanner sc = new Scanner(System.in);
      int A = sc.nextInt();
      int B = sc.nextInt();
      int C = sc.nextInt();
      
      if(A == B){
          System.out.println(C);
      } else if(A == C) {
          System.out.println(B);
      } else {
          System.out.println(A);
      }

      sc.close();
    }
}


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

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

#ifdef __WIN32
#define LLFORMAT "I64"
#define Rand() ((rand() << 15) + rand())
#else
#define LLFORMAT "ll"
#define Rand() (rand())
#endif

using namespace std;

const int maxn = 2e5 + 10;

map<long long, int> m;

int main(int argc, char *argv[]) {
#ifdef DEBUG
	freopen(argv[1], "r", stdin);
	freopen(argv[2], "w", stdout);
#endif
	int n;
	scanf("%d", &n);
	m[0] = 1;
	long long s = 0, ans = 0;
	while(n--) {
		int x;
		scanf("%d", &x);
		long long t = s + x;
		if(m.find(t) != m.end()) {
			ans += m[t];
			++m[t];
		}
		else {
			m[t] = 1;
		}
		s = t;
	}
	printf("%lld\n", ans);
	return 0;
}



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

int main() {

    string s;
    int n;
    cin >> s >> n;

    deque<char> d;
    for(auto c : s){
        d.push_back(c);
    }
    int on = 0;
    rep(i, n){
        int t;
        cin >> t;
        if(t == 1){
            on ^= 1;
        }
        else{
            int f; 
            char c;
            cin >> f >> c;
            if(on ^ (f == 1)){
                d.push_front(c);
            }
            else{
                d.push_back(c);
            }
        }
    }

    string ans;
    for(auto tmp : d){
        ans.push_back(tmp);
    }
    if(on){
        reverse(all(ans));
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;


string s;

int counting(char c) {
    int counter = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == c) {
            counter++;
        }
    }
    return counter;
}

int main() {
    cin >> s;
    int x = counting('R');
    if(x == 0 || x == 1 || x == 3) {
        cout << x << "\n";
    } else {
        if(s[1] == 'S') {
            cout << 1 << "\n";
        } else {
            cout << 2 << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 3564
//template by Aetius
//interactive comments ahead! : for the love of CP <3
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define repn(i,a,n) for(i=n;i>a;i--)
#define all(x) (x).begin(),(x).end()
#define PI (atan(1)*4)
#define INF (int)1e+9

#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
//typedef vec vector<ll>
typedef long long ll;
typedef long double ld;
typedef long int li;

using namespace std;

int main()
{
	
	string s;
	cin>>s;
	ll i,n=s.length(),cnt=0;

	for(i=1;i<n;i++)
	{
		if(s[i]==s[i-1])
		{
			++cnt;
			s[i]=s[i]=='0'?'1':'0';
		}
	}

	cout<<cnt<<"\n";
	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 300010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a[maxn];
int n;
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	int last=1;
	for(int i=1;i<=n;i++)
		if(a[i]==i){
			if(i==1||a[i-1]==i-1||a[i+1]==i+1)last=i+1;
		}
		else{
			if(i==last){
				if(a[i+1]!=i+1||a[i+2]==i+2){
					puts("No"); return 0;
				}
			}
			else if(a[i+1]!=i+1||a[i+2]==i+2){
				for(int j=last;j<=i;j++)
					if(a[j]<last||a[j]>i){
						puts("No"); return 0;
					}
				last=i+1;
			}
		}
	int val1=0,val2=0;
	for(int i=1;i<=n;i++)
		if(i<a[i]){
			if(a[i]<val1){
				puts("No"); return 0;
			}
			val1=a[i];
		}
		else if(i>a[i]){
			if(a[i]<val2){
				puts("No"); return 0;
			}
			val2=a[i];
		}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <set>
#include <cmath>
#include <iomanip>
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define FORR(i, m, n) for(int i=m; i>=n; i--)
#define INF 999999999
#define ll long long
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
0 0 0 1
)");
#define cin input
#endif

int main()
{
	int x1, y1, x2, y2, x3, y3, x4, y4;
	cin >> x1 >> y1 >> x2 >> y2;
	x3 = x4 = y3 = y4 = 0;

	x4 = -(y2-y1) + x1;
	y4 = (x2-x1) + y1;
	x3 = (x4-x1) + (x2-x1) + x1;
	y3 = (y4-y1) + (y2-y1) + y1;

	cout << x3 << " "<< y3 << " "<<  x4 << " "<< y4 << endl;
}



Measured memory_bytes: 256
import sys
from fractions import gcd

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print(*a, **dict(file=sys.stderr, **kw))

N = ini()


def solve():
    p = q = 1
    for i in range(N):
        x, y = inm()
        k = max(p // x, q // y, 1)
        while True:
            if x * k >= p and y * k >= q:
                p = x * k
                q = y * k
                break
            k += 1
    return p + q


print(solve())


Measured memory_bytes: 10400
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int x, y;
  cin>>x>>y;
  if((y - 2 * x) % 2 != 0){
    cout << "No" << endl;
    return 0;
  }
  int a = (4 * x - y) / 2;
  int b = (y - 2 * x) / 2;
  if(a < 0 || a > x || b < 0 || b > x){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 3680
from collections import Counter


s = input()

n = len(s)
DP = [0] * (n + 1)

for i in range(n)[::-1]:
    DP[i] = (DP[i + 1] + int(s[i]) * pow(10, n - i - 1, 2019)) % 2019

COUNTS = Counter(DP)

print(sum(count * (count - 1) // 2 for count in COUNTS.values()))


Measured memory_bytes: 16584
import sys
import math

def main():
    S = input()
    lenS = len(S)
    ch = [0]*lenS

    tmpLR = 0
    last = ''
    for i, s in enumerate(S):
        if s == last:
            tmpLR += 1
        else:
            if last == 'R':
                ch[i-1] = tmpLR
            elif last == 'L':
                ch[i-tmpLR] = tmpLR

            tmpLR = 1
            last = s
    
    ch[-tmpLR] = tmpLR

    for i,c in enumerate(ch):
        if c == 0 or S[i] == 'L':
            continue
        if S[i] == 'R':
            rch = c
            lch = ch[i+1]
            rleft = math.ceil(rch/2)
            lleft = math.ceil(lch/2)
            ch[i] = rleft + lch - lleft
            ch[i+1] = lleft + rch - rleft

    print(*ch)

if __name__=='__main__':
    main()

Measured memory_bytes: 6400
// 2018.09.05 1min

#include <iostream>

using namespace std;

int main() {
    string str;
    cin >> str;

    int v = 0;
    for(int i = 0; i<4;i++){
        if(str.at(i)=='+') v+=1;
        else v-=1;
    }
    cout << v << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
//    cout << fixed << setprecision(10);
    
    int A, B;
    cin >> A >> B;
    cout << A * B;

    return 0;
}


Measured memory_bytes: 3620
sss = [i for i in input()]
check = ["A","C","G","T"]
ans = 0 
temp_ans = 0
for s in sss:
  if s in check:
    temp_ans += 1
  else:
    if ans < temp_ans:
      ans = temp_ans
    temp_ans = 0
if ans < temp_ans:
  ans = temp_ans
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
		
	int km[10],v1,v2; char a;
    double leng;
	while(1){
	   for(int i = 0; i < 10; i++)
        		cin >> km[i] >> a;
        
        if(!cin)    break;
        cin >> v1 >> a >> v2;
 
	leng = 0.0;
	for(int k =0;k<10;k++)
	leng += km[k]; 
	double length = leng * v1 / (v1 +v2); 
	leng = 0.0;  
	for(int k=0;k<10;k++){
	leng +=  km[k];
	if(leng >= length ){
	
	cout << k+1 <<endl; break;
	}
	}	
	}
}

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

//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pii = pair<int, int>; // これ以降 pii という型名はpair<int, int> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

 
int main(){
    int n,q;
    cin>>n;
    vi A(n);
    rep(i,n)cin>>A.at(i);
    cin>>q;
    vi m(q);
     rep(i,q)cin>>m.at(i);
    
    
    rep(k,q){
        bool dp[n+1][m.at(k)+1];
        memset(dp, 0, sizeof(dp));   // 一旦すべて false に
          dp[0][0] = true;             // dp[0][0] だけ true に
        
          for (int i = 0; i < n; ++i) {
            for (int j = 0; j <= m.at(k); ++j) {
              dp[i+1][j] |= dp[i][j];
              if (j >= A[i]) dp[i+1][j] |= dp[i][j-A[i]];
            }
          }
        
          if (dp[n][m.at(k)]) cout << "yes" << endl;
          else cout << "no" << endl;
        
    }
}
  




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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b; cin>>a>>b;
    if (a>b){
        cout<<"a > b\n";
    }else if(a<b){
        cout<<"a < b\n";
    }else{
        cout<<"a == b\n";
    }
    return 0;
}



Measured memory_bytes: 3212
void main() {
	auto N = ri;
	auto a = readAs!(int[]);
	ulong cnt;
	foreach(i; a) {
		while(!(i & 1)) {
			i /= 2;
			cnt++;
		}
	}
	cnt.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 2684
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll cost[1000][1000];
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll p[n]={0};
        for(int x=0;x<n;x++)
        cin>>a[x];
        for(int x=0;x<1000;x++)
            for(int y=0;y<1000;y++)
            {   if(x!=y)
                cost[x][y]=10000000000000000;
                else
                    cost[x][y]=0;
            }
            p[0]=a[0];
        for(int x=1;x<n;x++)
        p[x]=a[x]+p[x-1];
    for(int x=2;x<=n;x++)
    {
       for(int y=0;y<=n-x;y++)
       {
           for(int z=y;z<=y+x-2;z++)
           {
                cost[y][y+x-1]=min(cost[y][z]+cost[z+1][y+x-1]+p[z]-p[y]+a[y]+p[y+x-1]-p[z+1]+a[z+1],cost[y][y+x-1]);
           }
       }
    }
    cout<<cost[0][n-1];
}


Measured memory_bytes: 8064
package main

import (
	"fmt"
)

func main() {
	var H, N int
	fmt.Scan(&H, &N)

	for i := 0; i < N; i++ {
		var A int
		fmt.Scan(&A)

		H -= A
		if H <= 0 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


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

using namespace std;
using ll = long long;


int main()
{
    int h, w, n; cin >> h >> w >> n;
    vector<vector<int>> hs(h);
    map<int,int> mp;
    multiset<int> mst;
    for(int i = 0; i < n; i++) {
        int a, b; cin >> a >> b; a--, b--;
        hs[a].push_back(b);
        mp[b]++;
    }
    for(auto i : mp)mst.insert(i.second);

    int nax = 0;

    for(int i = 0; i < h; i++) {
        for(auto p : hs[i]) {
            mst.erase(mst.lower_bound(mp[p]));
            mst.insert(mp[p]-1);
        }
        nax = max(nax, *mst.rbegin() + (int)hs[i].size());
        for(auto p : hs[i]) {
            mst.erase(mst.lower_bound(mp[p]-1));
            mst.insert(mp[p]);
        }
    }

    cout << nax << endl;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////
#define pii pair<int,int>
#define mkp make_pair

int N;
vector<int> rvs[202020];
int nxt[202020];
int mk[202020],m[202020],i,j;
int ct[202020],ct2[202020],ct3[202020],ans[202020];
queue<int> q;

void dfs1(int a,int mm)
{
    mk[a] = 1;
    m[a] = mm;
    mm = mm > a ? mm : a;
    for (int i = 0; i < rvs[a].size();i++)
    {
        if(mk[rvs[a][i]]!=1){
            nxt[rvs[a][i]] = a;
            dfs1(rvs[a][i],mm);
        }
    }
}

void ts(){
    fornum(i,2,N+1){
        ct[i] = rvs[i].size() - 1;
        if(ct[i]==0){
            q.push(i);
        }
    }
    while(!q.empty()){
        int qa = q.front();
        q.pop();
        int qb = nxt[qa];
        int qc = m[qa];
        //printf("%d,%d,%d,%d\n", qa,qc, ct2[qa],ct3[qa]);
        if(qc<qa){
            ct2[qa]++;
            //printf("%d,%d,%d,%d\n", qa,qb, ct2[qa],ct3[qa]);
            if(qb==1)
                continue;
        }else{
            if(qb!=qc){
                ct2[qb] += ct2[qa] + 1;
                 ct3[qb] +=(m[qc]<qa?ct2[qa]+1:ct3[qa]);
                ct2[qa] = 0;
               
                ct3[qa] = 0;
            }else if(m[qc] > qa){
                    ct2[qb] += ct2[qa] - ct3[qa]+1;
                    ct2[qa] = ct3[qa];
            }else{
                ct2[qa]++;
            }
            //printf("%d,%d,%d,%d\n", qa,qb, ct2[qa],ct3[qa]);
        }
        ct[qb]--;
        if(ct[qb]==0){
            q.push(qb);
        }
    }
}
void dfs2(int a,int c){
    mk[a] = 2;
    ans[a] = ct2[a] + c;
    for (int i = 0; i < rvs[a].size();i++){
        if(mk[rvs[a][i]]!=2){
            dfs2(rvs[a][i], ans[a]);
        }
    }
}

int main(){
    scanf("%d", &N);
    fornum(i,1,N){
        int a, b;
        scanf("%d%d",&a,&b);
        rvs[a].push_back(b);
        rvs[b].push_back(a);
    }
    dfs1(1,0);
    ts();
    dfs2(1,0);
    fornum(i,1,N){
        printf("%d ", ans[i + 1]);
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

signed main() {
    string s;
    ll k;
    cin >> s >> k;
    k--;

    int ans;
    for (int i = 0; i < s.size(); ++i) {
        int num = s[i] - '0';
        if (k == i || num != 1) {
            ans = num;
            break;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
ans = [0]*n
for i in range(1,n//2+1):
    ans[2*i] = ans[2*i-2]+(a[2*i-1]-a[2*i-2])*2
ans[1] = ans[n-1]+(a[0]-a[n-1])*2
for i in range(1,(n-2)//2+1):
    ans[2*i+1] = ans[2*i-1]+(a[2*i]-a[2*i-1])*2

x = a[0]-((ans[0]+ans[1])//2)
for i in range(len(ans)):
    ans[i] += x
print(*ans)

Measured memory_bytes: 14384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int D; //365
    cin >> D;
    int c[26];
    rep(i, 0, 26) {
        cin >> c[i];
    }
    int s[D][26];
    rep(i, 0, D) {
        rep(j, 0, 26) {
            cin >> s[i][j];
        }
    }

    int t[D];
    rep(i, 0, D) {
        srand(time(NULL));
        t[i] = rand() % 26;
    }

    ll mx_score = -1;
    int cnt = 10;
    while (cnt--) {
        srand(time(NULL));
        int d = rand() % 365;
        int q = rand() % 26;
        int old = t[d];
        t[d] = q;

        ll score[D] = {};
        vector<int> last_day(26, -1);
        rep(i, 0, D) {
            if (i != 0) score[i] = score[i - 1];
            score[i] += s[i][t[i]];
            last_day[t[i]] = i;
            int decrease = 0;
            rep(j, 0, 26) {
                decrease += c[j] * (i - last_day[j]);
            }
            score[i] -= decrease;
        }
        if (mx_score > score[D - 1]) {
            t[d] = old;
        } else {
            mx_score = score[D - 1];
        }
    }

    rep(i, 0, D) cout << t[i] << endl;

    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  long int a,b; cin >> a >> b;
  long int k=(a+b)/2;
  long int ans = abs(a-k);
  if(abs(b-k)==ans){
      cout << k << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <memory>

//#define int long long

//#define ENABLE_TRACE
#ifdef ENABLE_TRACE
#define TRACE cout << __func__ << "()" << endl;
#define TRACE1(a) cout << __func__ << "(" << a << ")" << endl;
#define TRACE2(a, b) cout << __func__ << "(" << a << ", " << b << ")" << endl;
#else
#define TRACE
#define TRACE1(a)
#define TRACE2(a, b)
#endif  // #ifdef ENABLE_TRACE

using namespace std;

// Greatest Common Divisor
int Gcd(int a, int b) {
	TRACE2(a, b);
	if (a % b == 0) return b;
	return Gcd(b, a % b);
}

void Main()
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n, 0);
	for (int i = 0; i < k; i++) {
		int d;
		cin >> d;
		for (int j = 0; j < d; j++) {
			int aj = 0;
			cin >> aj;
			a[aj - 1]++;
		}
	}

	int ans = 0;
	for (const auto& ai : a) {
		if (ai == 0) {
			ans++;
		}
	}

	cout << ans << endl;
}

int32_t main()
{
	Main();
	return 0;
}



Measured memory_bytes: 3632
n, Y = map(int, input().split())
ntx = n * 10000
nty = n * 5000
ntz = n * 1000
ans = []
if Y > ntx or ntz > Y:
    ans = [-1, -1, -1]
elif ntx == Y:
    ans = [n, 0, 0]
elif nty == Y:
    ans = [0, n, 0]
elif ntz == Y:
    ans = [0, 0, n]
elif ntx > Y > nty:
    x = 0
    y = n
    z = 0
    for i in range(1, n+1):
        y = n - i
        x = i
        for j in range(0, i+1):
            x = j
            z = i - j
            if 10000*x + 5000*y + 1000*z == Y:
                ans = [x, y, z]
elif nty > Y > ntz:
    x = 0
    y = 0
    z = n
    for i in range(1, n+1):
        z = n - i
        x = i
        for j in range(0, i+1):
            x = j
            y = i - j
            if 10000*x + 5000*y + 1000*z == Y:
                ans = [x, y, z]
if len(ans) == 0:
    ans = [-1, -1, -1]
print(' '.join(map(str, ans)))


Measured memory_bytes: 3064
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
    int n;
    cin >> n;
    int ans = 0;
    unordered_map<int, int> hash;
    vector<int> v(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    for (int i = 1; i <= n; i++) {
        ans += hash[v[i] - i];
        hash[-i - v[i]]++;
    }
    cout << ans << endl;
}
int32_t main() {
    BOLT;
    solve();
}


Measured memory_bytes: 20116
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

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

    int n;
    cin>>n;
    vi in(n);
    rep(i,n){
        int a;cin>>a;a--;
        in[n-1-a]=i;
    }
    int out=0;
    set<int>se;
    se.insert(-2);
    se.insert(-1);
    se.insert(n);
    se.insert(n+1);
    rep(i,n){
        auto it=se.lower_bound(in[i]);
        int a,b,c,d;
        c=*it;
        it++;
        d=*it;
        it--;it--;
        b=*it;
        it--;
        a=*it;

        cmax(a,-1ll);
        cmin(d,n);
        out+=(n-i)*(b-a)*(c-in[i])+(n-i)*(in[i]-b)*(d-c);
        se.insert(in[i]);
    }
    cout<<out<<endl;
}


Measured memory_bytes: 5760
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  
  for(i=0;i<=VMAX;i++)C[i]=0;
  
  for(j=0;j<n;j++){
    C[A[j]]++;
  }
  for(i=1;i<=VMAX;i++){
    C[i]=C[i-1]+C[i];
  }
  for(j=n;j>=0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++)if(n==i)printf("%d",B[i]);else printf("%d ",B[i]);
  printf("\n");
  return 0;
}



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

public class Main {
	public static void main(String[] age)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb = new StringBuffer();

		int a = 0;

		while(true){
			String[] input = br.readLine().split(" ");
			int n = Integer.parseInt(input[0]);
			int x = Integer.parseInt(input[1]);

			if( n==0 && x==0 ) break;

			for(int i=1 ; i<=n ; i++ ){
				for(int j=i+1 ; j<=n ; j++ ){
					for(int k=j+1 ; k<=n ; k++ ){
						if( (i+k+j)==x ) a++;
					}
				}
			}
			sb.append(Integer.toString(a)).append("\n");
			a = 0;
		}

		System.out.print(sb);
	}
}

Measured memory_bytes: 24480
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

int d[100010];

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
        d[a[i]]++;
    }
    int cnt = 0;
    int ans = 0;
    int f = 0;
    rep(i, 0, 100010){
        if(d[i] != 0){
            ans++;
            if(d[i] % 2 == 0) cnt++;
        }
    }
    if(!(cnt % 2 == 0)) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    a -= 2
    b -= 2
    a %= 13
    b %= 13
    if a > b:
        print("Alice")
    elif a < b:
        print("Bob")
    else:
        print("Draw")
    return

#B
def B():
    n, m = LI()
    a = SR(n)
    b = SR(m)
    if a == b:
        print("Yes")
        return
    for y in range(n - m):
        for x in range(n - m):
            if a[y][x] == b[0][0]:
                flg = 0
                for yi in range(m):
                    for xi in range(m):
                        if b[yi][xi] == a[y + yi][x + xi]:
                            continue
                        flg = 1
                        break
                    if flg:
                        break
                if flg:
                    continue
                print("Yes")
                return
    print("No")
    return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 38772
#include <iostream>
using namespace std;
int main() {
   int A,B,C,k;
   cin>>A>>B>>C>>k;
   while(k--)
   {
       if(B<=A)
       B*=2;
       else if(C<=B)
       C*=2;
   }
   //cout<<A<<B<<C<<endl;
   if(B>A&&C>B)
   cout<<"Yes";
   else
   cout<<"No";
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

int n;
vector<int> a;

int main() {
    cin >> n;
    a.resize(n);
    unordered_map<int, int> count;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        count[a[i]]++;
        if (count[a[i]] > 1) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 9288
# -*- coding: utf-8 -*-
# Input
list = []
for _ in range(4):
    list += [int(input())]

count = 0
for ii in range(list[0] + 1):
    for jj in range(list[1] + 1):
        for kk in range(list[2] + 1):
            if list[3] == 500 * ii + 100 * jj + 50 * kk:
                count += 1

print(count)


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

#define INF 1000000007

using namespace std;

int mini(int i, int pr, vector<int> &mn, int n)
{
    if (i==mn.size()){
        if (pr>=n) return pr;
        return INF;
    }
    return min(mini(i+1, pr, mn, n), mini(i+1, pr*mn[i], mn, n));
}

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

    int gcd = 1;
    int m_s = m;
    vector<int> mn;
    for (int i=2; i*i<m_s; i++){
        if (m_s%i==0){
            m_s/=i;
            mn.push_back(i);
            i--;
        }

    }
    if (m_s!=1) mn.push_back(m_s);

    if (mn.size()<=20){
        gcd = m/mini(0, 1, mn, n);
    }
    else{
        for (int i=n; i<=m; i++){
            if (m%i==0){
                gcd = m/i;
                break;
            }
            //cout << i << " " << m << " " << m%i << endl;
        }
    }

    cout << gcd << endl;
}


Measured memory_bytes: 256
def main():
    N, *LR = map(int, open(0).read().split())
    L, R = LR[::2], LR[1::2]

    max_l = max(L)
    min_r = min(R)

    ab = [(max(0, r - max_l + 1), -max(0, min_r - l + 1)) for l, r in zip(L, R)]
    ab.sort()

    mi = float("inf")
    ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, min_r - max_l + 1)
    for i in range(N - 1):
        mi = min(mi, -ab[i][1])
        ma = max(ma, mi + ab[i + 1][0])

    print(ma)

main()


Measured memory_bytes: 26512
def resolve():
    (N, K) = list(map(int, input().split(" ")))
    srps = [0] * (K+1)
    # srps[n]: Kで割った余りがnである数が1~Nの間にいくつ存在するか
    for i in range(1, N+1):
        srps[i%K] += 1
    cnt = 0

    for a in range(K):
        b = (K-a) % K
        c = (K-a) % K
        if (b+c)%K != 0:
            continue
        cnt += (srps[a] * srps[b] * srps[c])
    
    print(cnt)

        

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 40176