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

##
## C - Vacation
## https://atcoder.jp/contests/dp/tasks/dp_c
##

import sys

def solve(N, tuples):
    xa, xb, xc = 0, 0, 0
    for a, b, c in tuples:
        ya = max(xb, xc) + a
        yb = max(xc, xa) + b
        yc = max(xa, xb) + c
        xa, xb, xc = ya, yb, yc
    return max(xa, xb, xc)

def load(input):
    line = input.readline()
    N = int(line.strip())
    tuples = [ tuple( int(s) for s in line.split() )
                   for line in input ]
    return N, tuples

def main():
    N, tuples = load(sys.stdin)
    result = solve(N, tuples)
    print(result)

main()


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);

    vl a(N+1);
    Rep(i,N) Scll(a[i]);

    ll dp[202020][4] = {};
    Repe(i,N,1){
        fill(dp[i],dp[i]+3,-1e18);
    }
    if( N%2==0 ){
        Rep(i,N/2){
            dp[i+1][0] = max( dp[i+1][0], dp[i][0] + a[i*2]  );
            dp[i+1][1] = max( dp[i+1][1], dp[i][0] + a[i*2+1]);
            dp[i+1][1] = max( dp[i+1][1], dp[i][1] + a[i*2+1]);
        }
    }else{
        Rep(i,N/2){
            dp[i+1][0] = max( dp[i+1][0], dp[i][0] + a[i*2]  );
            dp[i+1][1] = max( dp[i+1][1], dp[i][0] + a[i*2+1]);
            dp[i+1][2] = max( dp[i+1][2], dp[i][0] + a[i*2+2]);
            dp[i+1][1] = max( dp[i+1][1], dp[i][1] + a[i*2+1]);
            dp[i+1][2] = max( dp[i+1][2], dp[i][1] + a[i*2+2]);
            dp[i+1][2] = max( dp[i+1][2], dp[i][2] + a[i*2+2]);
        }
    }

    printf ("%lld\n", max(dp[N/2][0], max( dp[N/2][1], dp[N/2][2]) ) );

    return 0;
}



Measured memory_bytes: 11172
import java.util.Scanner;

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

	for(int i = 0; i < n; i++){
	    String str = sc.next();
	    int l = str.length();
	    String[] a = new String[4*l*l];
	    int p = 0;

	    for(int j = 1; j < l; j++){
		String s1 = str.substring(0, j);
		String s2 = str.substring(j, l);
		String rs1 = reverse(s1);
		String rs2 = reverse(s2);
		
		if(strcomp(s1+s2, a, p)){
		    a[p++] = s1+s2;
		}
		if(strcomp(s1+rs2, a, p)){
		    a[p++] = s1+rs2;
		}
		if(strcomp(rs1+s2, a, p)){
		    a[p++] = rs1+s2;
		}
		if(strcomp(rs1+rs2, a, p)){
		    a[p++] = rs1+rs2;
		}
		if(strcomp(s2+s1, a, p)){
		    a[p++] = s2+s1;
		}
		if(strcomp(s2+rs1, a, p)){
		    a[p++] = s2+rs1;
		}
		if(strcomp(rs2+s1, a, p)){
		    a[p++] = rs2+s1;
		}
		if(strcomp(rs2+rs1, a, p)){
		    a[p++] = rs2+rs1;
		}
	    }
	    System.out.println(Integer.toString(p));
	}
    }

    private boolean strcomp(String str, String[] a, int p){
	for(int i = 0; i < p; i++){
	    if(str.equals(a[i])){
		return false;
	    }
	}

	return true;
    }

    private String reverse(String str){
	String rstr = "";

	for(int i = str.length(); i > 0; i--){
	    rstr += str.substring(i-1, i);
	}

	return rstr;
    }

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

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }

int main()
{
	ll N, H[100000];
	int count = 0;
	int m = 0;

	cin >> N;
	rep(i, N)
		cin >> H[i];

	rep(i, N - 1)
	{
		if (H[i] >= H[i + 1])
			count++;
		else
		{
			m = max(m, count);
			count = 0;
		}
	}
	m = max(m, count);

	cout << m << endl;

	return 0;
}

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

int main() {
    int a,b,res=0;cin>>a>>b;
    rep2(i,a,b+1) {
        string s = to_string(i);
        int sl = s.length();
        res++;
        rep(j,sl/2) {
            if(s[j]!=s[sl-j-1]) {
                res--;
                break;
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;
    if (K== 1)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << N - K << endl;
    }
}


Measured memory_bytes: 256
import scala.collection.mutable.ArrayBuffer

object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val pw = new java.io.PrintWriter(System.out)
	
	val n = sc.nextInt
	
	val c = Array.fill(10)(Array.fill(10)(0))
	
	for (k <- 1 to n) {
		val s = k.toString
		val i = s.head.asDigit
		val j = s.last.asDigit
		c(i)(j) = c(i)(j) + 1 
	}
	
	pw.println((for (i <- 0 to 9; j <- 0 to 9) yield c(i)(j) * c(j)(i)).sum)
	pw.flush()
}

Measured memory_bytes: 35812
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, mod = 1000000007;
    cin >> N;
    int arr[N];
    long long sum = 0, ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> arr[i];
        sum += arr[i];
        sum %= mod;
    }
    for (int i=0; i<N; i++)
    {
        sum -= arr[i];
         if (sum < 0) sum += mod;
        ans += arr[i] * sum;
        ans %= mod;
    }
    cout << ans <<" \n";
    return 0;
}


Measured memory_bytes: 4348
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  n = int(sqrt(n));
  cout << n * n << endl;
  return 0;
}

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

int main() {
	int a, b, k, num;
	bool check = false;
	cin >> a >> b >> k;
	for (int i = 0; i < k; i++) {
		if (i + 1 < k) {
			num = a + i;
		}
		if (a + i > b) {
			check = true;
			break;
		}
		cout << a + i << endl;
	}
	for (int i = k - 1; i >= 0; i--) {
		if (check == true) {
			break;
		}
		if (b - i - 1 > num) {
			cout << b - i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b,c,r=3;
  scanf("%d%d%d",&a,&b,&c);
  if(a==b)r--;
  if(a==c)r--;
  if(b==c)r--;
  if(r==0)r++;
  printf("%d",r);
  return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)

int main(){
    ll N;
    ll i;
    vector<long long int> A;
    cin >> N;
    for(i=0;i<N;i++){
        ll ai;
        cin >> ai;
        A.push_back(ai);
    }

    ll count = 0;
    ll gap;
    ll ni, nii;
    nii = A[0];
    for(i=1;i<N;i++){
        ni = A[i];
        gap = nii - ni;
        if(gap > 0){
            count += gap;
            nii = ni + gap;
        }
        else{nii = ni;}
    }
    cout << count << endl;
    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;

    if(a>b){
        for(int i=0;i<a;i++){
            cout << b;
        }
        cout << endl;
    }else{
        for(int i=0;i<b;i++){
            cout << a;
        }
        cout << endl;
    }
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> A(n + 1);
    for (int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        A[l - 1]++;
        A[r]--;
    }

    int ans = 0;
    for (int i = 0; i < n; i++){
        A[i + 1] += A[i];
        if (A[i] == m)
            ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld;
#define has_bit(bit_mask, x) ((bit_mask) & (1Uint << (x)))
#define turn_on_bit(bit_mask, x) (bit_mask |= (1Uint << (x)))
#define turn_off_bit(bit_mask, x) (bit_mask &= (~(1Uint << (x))))
#define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define all(x) x.begin(), x.end()
#define mapfind(mp, x) (mp.find(x) != mp.end())
#define removeDuplicates(vec) sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define int ll
#define double ld
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
#define MOD 1000000007

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    if (n&1) cout << "0\n";
    else
    {
        int ans = 0;
        n /= 2;
        for (int i = 5; i <= n; i *= 5) ans += (n/i);
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);

	string s;
	int m, h;
	while(true) {
		cin >> s >> m;
		if (s == "-") {
			break;
		}
		for (int i=0; i < m; i++) {
			cin >> h;
			string substr = s.substr(h);
			s.erase(h, s.length()-1);
			s.insert(0, substr);
		}
		cout << s << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>

using namespace std;

void Diverta2019_2C()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (auto& x : A)
	{
		cin >> x;
	}

	if (N == 2)
	{
		auto x = max(A[0], A[1]);
		auto y = min(A[0], A[1]);
		cout << x - y << endl;
		cout << x << ' ' << y << endl;
		return;
	}

	vector<int> B = A;
	sort(B.begin(), B.end());
	auto pZero = lower_bound(B.cbegin(), B.cend(), 0);
	if (pZero == B.cbegin())
	{
		// B >= 0
		auto sum = accumulate(B.cbegin() + 1, B.cend(), 0);
		sum -= B.front();
		cout << sum << endl;
		auto x0 = B[0];
		auto x1 = B[1];
		for (int i = 2; i < N; ++i)
		{
			auto x2 = B[i];
			cout << x0 << ' ' << x2 << endl;
			x0 -= x2;
		}
		cout << x1 << ' ' << x0 << endl;
		return;
	}
	if (pZero == B.cend())
	{
		// B < 0
		auto sum = accumulate(B.crbegin() + 1, B.crend(), 0);
		sum -= B.back();
		cout << -sum << endl;
		auto x0 = B[N-1];
		for (int i = 1; i < N; ++i)
		{
			auto x1 = B[N - i - 1];
			cout << x0 << ' ' << x1 << endl;
			x0 -= x1;
		}
		return;
	}

	int nm = distance(B.cbegin(), pZero);
	int np = N - nm;

	auto sum = accumulate(B.cbegin() + nm, B.cend(), 0) - accumulate(B.cbegin(), B.cbegin() + nm, 0);
	cout << sum << endl;
	if (np == 1)
	{
		auto x0 = B.back();
		for (int i = 0; i < N - 1; ++i)
		{
			auto x1 = B[i];
			cout << x0 << ' ' << x1 << endl;
			x0 -= x1;
		}
		return;
	}
	auto x0 = B.front();
	for (int i = nm; i < N - 1; ++i)
	{
		auto x1 = B[i];
		cout << x0 << ' ' << x1 << endl;
		x0 -= x1;
	}
	cout << B.back() << ' ' << x0 << endl;
	x0 = B.back() - x0;
	for (int i = 1; i < nm; ++i)
	{
		auto x1 = B[i];
		cout << x0 << ' ' << x1 << endl;
		x0 -= x1;
	}
}

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

Measured memory_bytes: 2688
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    ll A[200];
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll sum = 0;
    while(true){
        bool flag = false;
        for(int i = 0; i < N ; i++) {
            if(A[i] % 2 != 0) {
                flag = true;
            }
        }
        if(flag){
            break;
        }
        for(int i = 0; i < N; i++) {
            A[i] /= 2;
        }
        sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,t,i;
	while(1){
	scanf("%d",&a);
	if(a==0){
		break;
	}
	for(i=0;i<9;i++)
	{
		scanf("%d",&b);
		a-=b;
	}
	printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 1728
package main

import (
	"fmt"
)

func gcd(a int64, b int64) int64 {
	if a < 0 {
		a = -a
	}
	if b < 0 {
		b = -b
	}
	if b > a {
		return gcd(b, a)
	}
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	var N int
	var X int64
	fmt.Scanf("%d", &N)
	fmt.Scanf("%d", &X)
	var g int64
	for i := 0; i < N; i++ {
		var x int64
		fmt.Scanf("%d", &x)
		x -= X
		if x < 0 {
			x = -x
		}
		if i == 0 {
			g = x
		} else {
			g = gcd(g, x)
		}
	}
	fmt.Println(g)
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  
  int a,b,c;
  
  cin>>a>>b>>c;
  
  if(a+b+c<22)
    cout<<"win"<<endl;
  else
    cout<<"bust"<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n;
  scanf("%d", &n);
  
  if (n == 1)
  {
    printf("1");
    return 0;
  }
  
  int ans = 2;
  while (ans <= n)
  {
    ans *= 2;
  }
  if (ans != n)
  {
    ans /= 2;
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 128
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();
		int rgb = a*100 + b*10 + c;
		if (rgb%4 == 0) {
		     System.out.println("YES");
                } else {
                     System.out.println("NO");
                }
	}
}

Measured memory_bytes: 23252
# N = int(sys.stdin.readline())
import sys,bisect,math
sys.setrecursionlimit(15000)

N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]

def isPrime(n):
  if n == 2:
    return True
  for i in range(2,math.ceil(pow(n,0.5))+1):
    if n % i == 0:
      return False
  return True

print(sum(1 for e in A if isPrime(e)))


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


int main(void) {

	int i,a,b;
	int cnt = 0;

	string w;
	cin >> w;

	a = w.size();
	

	for (i = 0; i < a; i++) {
		if (w[i] >= 65 && w[i] <= 90)
			w[i] = w[i] + 32;
	}

	while(1){

		string t;
		cin >> t;

		b = t.size();

		if (t == "END_OF_TEXT") break;


		if (a != b)
		 continue;

		for (i = 0; i < a; i++) {

			if (t[i] >= 65 && t[i] <= 90)
				t[i] = t[i] + 32;
			
				if (t[i] != w[i])
					break;
				if (i == a -1)
					cnt++;	
		}		
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#define ll long long
#define INF 100000000000000000
#define MAX 100010
using namespace std;

struct edge{
  int to;
  ll cost;
};

typedef pair<ll, int> p;
vector<edge> graph[MAX];
vector<ll> dist;

bool bellman_ford(int n, int s){ //n???????????°???s???????§???????
  dist = vector<ll>(n, INF); //dist???INF??§?????????
  dist[s] = 0;
  for(int i = 0; i < n; i++){
    for(int v = 0; v < n; v++){
      for(int k = 0; k < graph[v].size(); k++){
        edge e = graph[v][k];
        if(dist[v] != INF && dist[e.to] > dist[v] + e.cost){
          dist[e.to] = dist[v] + e.cost;
          if(i == n - 1) return true; // ????????????????????¨
        }
      }
    }
  }
  return false;
}

int main(){
  int v, e, r, s, t;
  ll d;
  cin >> v >> e >> r;
  for(int i = 0; i < e; i++){
    cin >> s >> t >> d;
    graph[s].push_back((edge){t, d});
  }
  bool check = bellman_ford(v, r);
  if(check){
    cout << "NEGATIVE CYCLE" << endl;
  }else{
    for(int i = 0; i < v; i++){
      if(dist[i] == INF) cout << "INF" << endl;
      else cout << dist[i] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 5552
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  char s[100];
  scanf("%s",s);
  char t[]="AKIHABARA";
  bool F=1;
  int i,j;
  for(i=0,j=0;s[i]||t[j];){
    if(s[i]==t[j]){
      i++;
      j++;
    }
    else if(t[j]=='A'){
      j++;
    }
    else{
      F=0;
      break;
    }
  }
  puts(F&&!s[i]&&!t[j]?"YES":"NO");
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static final boolean matched(int a, int b, int arr[]) {
        boolean hasA = false;
        boolean hasB = false;
        for (int i : arr) {
            if (a != i) {
                continue;
            }
            hasA = true;
            break;
        }
        for (int i : arr) {
            if (b != i) {
                continue;
            }
            hasB = true;
            break;
        }
        return hasA && hasB;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] groupsA = {1, 3, 5, 7, 8, 10, 12};
        int[] groupsB = {4, 6, 9, 11};
        int[] groupsC = {2};

        if (matched(x, y, groupsA) || matched(x, y, groupsB) || matched(x, y, groupsC)) {
            System.out.println("Yes");
            return;
        }
        System.out.println("No");
    }

}


Measured memory_bytes: 21844
//BISMILLAHIR RAHMANIR RAHIM
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <list>
#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 mem(a, b) (memset(a, b, sizeof(a)))
#define read (freopen("input.txt", "r", stdin))
#define write (freopen("output.txt", "w", stdout))
#define fastIO (ios::sync_with_stdio(0), cin.tie(0), cout.tie(0));
#define dis(x1, y1, x2, y2) ((x1-x2) * (x1-x2)) + ((y1-y2) * (y1-y2))
#define debug (printf("PINK FLOYD:)\n"))
#define iosflags (cout<<setiosflags(ios::fixed)<<setprecision(8))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define EPS 1e-8
#define MOD 1000000007
#define MAX 100005
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

const int inf = 1<<28;
int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int dx[] = { -1, 1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };
int fx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
int fy[] = { -1,  1, -2,  2, -2,  2, -1,  1 };

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int main()
{
	fastIO;
	int n;

	cin>>n;

	cout<<3 * n * n<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using lint = long long;

int main()
{

    lint h, w, a, b;

    scanf("%lld", &h);
    scanf("%lld", &w);
    scanf("%lld", &a);
    scanf("%lld", &b);

    for (int i = 0; i < h; ++i)
    {
        if (i < h - b)
            printf("%s\n", (std::string((w - a), '1') + std::string(a, '0')).c_str());
        else
            printf("%s\n", (std::string((w - a), '0') + std::string(a, '1')).c_str());
    }
    return 0;
}


Measured memory_bytes: 1280
H,W = map(int,input().split())
grid = []
ans = "Yes"

for _ in range(H):
  grid_i = input().split()
  grid.append(grid_i[0])

for i in range(H):
  for j in range(W):
    if grid[i][j] == "#":
      X = "NG"
      if (i-1 >= 0 and grid[i-1][j] == ".") or i < 1:
        None
      else:
        X = "OK"
      if (j-1 >= 0 and grid[i][j-1] == ".") or j < 1:
        None
      else:
        X = "OK"
      if (i+1 < H and grid[i+1][j] == ".") or i+1 >= H:
        None
      else:
        X = "OK"
      if (j+1 < W and grid[i][j+1] == ".") or j+1 >= W:
        None
      else:
        X = "OK"
      if X == "NG":
        ans = "No"

print(ans)

Measured memory_bytes: 9252
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{ return firstElof.second < secondElof.second; }
//**Snippetリスト**//
//rep, vin, all//
//gcdlcm, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; 
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = INF;
vl flag, color; vll path; vl D;
//***********//
int main() {
	ll A, B, C;
	cin >> N >> A >> B >> C;
	vl L(N);
	for (i = 0; i < N; i++) {
		cin >> L[i];
	}
	for (k = 0; k < pow(4,N); k++) {
		ll p = k;
		ll a = 0, b = 0, c = 0;
		ll pre = 10 * (N - 3);
		for (i = 0; i < N; i++) {
			if (p % 4 == 0)a += L[i];
			else if (p % 4 == 1) b += L[i];
			else if (p % 4 == 2) c += L[i];
			else pre-=10;
			p /= 4;
		}
		if (a == 0 || b == 0 || c == 0) continue;
		pre += abs(A - a) + abs(B - b) + abs(C - c);
		ans = min(ans, pre);
	}
	cout << ans;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double sum = 0.0d;
        for (int i = 0; i < n; i++) {
            sum += 1.0d / sc.nextInt();
        }
        System.out.println(1.0d /  sum);
    }
}


Measured memory_bytes: 21844
#!/usr/bin/env python3

import numpy as np


n = int(input())
x = list(map(int, input().split()))

median = np.median(x)
x_sorted = sorted(x)

index = len(x)//2-1

for i in x:
    if i == median:
        print(i)
    elif i < median:
        print(x_sorted[index+1])
    else:
        print(x_sorted[index])


Measured memory_bytes: 50100
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b) {
  return *(long *)a - *(long *)b;
}

struct bctyp {int b; long c;};

int asbc(const void *x, const void *y) {
  return (*(struct bctyp *)y).c - (*(struct bctyp *)x).c;
}

int main(){
   int i,j,k,n,m;
   long a[100000],s;
   struct bctyp bc[100000];
    
   scanf("%d %d",&n,&m);
   for (i=0;i<n;i++) scanf("%ld",&a[i]);
   for (i=0;i<m;i++) scanf("%d %ld",&(bc[i].b),&(bc[i].c));
   qsort(bc,m,sizeof(struct bctyp),asbc);
   qsort(a,n,sizeof(long),asc);
   for (k=i=0;i<m && k<n;i++) {
      for (j=0;j<bc[i].b;j++)
         if (a[k]<bc[i].c) {
            a[k++]=bc[i].c;
            if (k==n) break;
         } else break;
   }
   s=0;
   for (i=0;i<n;i++) s+=a[i];
   printf("%ld\n",s);
   return 0;
}


Measured memory_bytes: 4092
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	vector<int> a(n + 1);
	for (int i = 2; i <= n; i++) {
		if (a[i] == 0) {
			for (int j = i * 2; j <= n; j += i) { a[j]++; }
		}
	}
	map<int, int> mp;
	for (int i = 2; i < n + 1; i++) {
		if (a[i] == 0) {
			int p = n, k = 0;
			while (p) {
				p /= i;
				k += p;
			}
			mp[i] = k;
		}
	}
	vector<int> cnt(5);
	for (auto k : mp) {
		int p = k.second;
		if (p >= 74) cnt[0]++;
		if (p >= 24) cnt[1]++;
		if (p >= 14) cnt[2]++;
		if (p >= 4) cnt[3]++;
		if (p >= 2) cnt[4]++;
	}
	int ans = cnt[0] + cnt[1] * (cnt[4] - 1) + cnt[2] * (cnt[3] - 1) + cnt[3] * (cnt[3] - 1) / 2 * (cnt[4] - 2);
	printf("%d\n", ans);
	return 0;
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long
// #define pow mypow

typedef pair<int,int> pii;
const int N = 1e2+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int n;
int a[N];
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++){
		if (a[i]%2==0 && a[i]%3 != 0 && a[i]%5 != 0) return 0*puts("DENIED");
	}
	puts("APPROVED");
	return 0;
}


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

using namespace std;

int main()	{
  	string s;
  	cin >> s;
  	int x = -1, y = -1;
	for (int i = 1; s[i] != '\0'; i++)	{
      	if (s[i] == s[i - 1])	{
          	x = i - 1;
          	y = i;
          	cout << x + 1 << " " << y + 1 << endl;
          	return 0;
        }
    }
  	for (int i = 0; i < s.length() - 2; i++)	{
    	if (s[i + 2] == s[i])	{
			x = i;
          	y = i + 2;
          	cout << x + 1 << " " << y + 1 << endl;
          	return 0;
        }
    }
	cout << -1 << " " << -1 << endl;
  	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
int inf = 1e9;

int main() {
  int n, w; cin >> n >> w;
  vector<int> c(n);
  vector<int> v(n);
  for(int i=0; i<n; i++) {
    cin >> c[i] >> v[i];
  }
  vector< vector<long long int> > dp(n+1, vector<long long int> (w+10000, 0));

  for(int i=1; i<=n; i++) {
    for(int j=0; j<=w; j++) {
      if(j-c[i-1] >= 0) {
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-c[i-1]] + v[i-1]);
      } else {
        dp[i][j] = dp[i-1][j];
      }
    }
  }

  cout << dp[n][w] << endl;

  return 0;
}



//EOF


Measured memory_bytes: 87936
'use strict';
var data = '';
process.stdin.on('end', function() {
    var inputs = data.toString().trim().split('\n');
    var params = inputs[1].split(' ').map(Number);
    var sum = params.reduce(function(a,b) {
      return a + b;
    });
    var min = params[0];
    var max = params[0];
    for (var i = 0; i < params.length; i++) {
      min = Math.min(min,params[i]);
      max = Math.max(max,params[i]);
    }
 
    console.log(min, max, sum);
 
});
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  data += chunk;
});

Measured memory_bytes: 17484
antenna = []
far_antenna = 0
for i in range(5):
    antenna.append(int(input()))

k = int(input())
for i in range(1, 5):
    for j in range(i):
        if (antenna[i] - antenna[j]) > k:
            far_antenna += 1
            break
        else:
            continue
if far_antenna != 0:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>
#include <stack>
#include <cstdlib>
#include <utility> //pair

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

typedef long long ll;

using namespace std;

int main() {
    
    int a,b;
    cin >> a >>b;
    
    if((a<=8)&&(b<=8)){
        cout << "Yay!" <<endl;
    }else{
        cout << ":(" <<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>  
    #include<vector>  
    #include<queue>  
    #include<string>  
    #include<map>  
    #include<iostream>  
    #include<cstring>  
    #include<algorithm>  
    using namespace std;  
    typedef long long LL;  
    const int INF = 0x7FFFFFFF;  
    const int maxn = 1e5 + 10;  
       
    #define MAX_W 100  
    #define MAX_H 100  
    char farm[MAX_W][MAX_H];  
    int W, H;  
    const int direction[4][2] = {  
      { -1, 0 },  
      { 1, 0 },  
      { 0, -1 },  
      { 0, 1 },  
    };  
       
    void dfs(int x, int y, char tree)  
    {  
      farm[x][y] = 'x';  
      for (int i = 0; i < 4; ++i)  
      {  
        int nx = x + direction[i][0];  
        int ny = y + direction[i][1];  
        if (nx >= 0 && nx < W && ny >= 0 && ny < H && farm[nx][ny] == tree)  
        {  
          dfs(nx, ny, tree);  
        }  
      }  
    }  
       
    int main()  
    {  
       
      while (cin >> H >> W, W > 0)  
      {  
        int res = 0;  
        int x, y;  
        for (y = 0; y < H; ++y)  
        {  
          for (x = 0; x < W; ++x)  
          {  
            cin >> farm[x][y];  
          }  
        }  
       
        for (y = 0; y < H; ++y)  
        {  
          for (x = 0; x < W; ++x)  
          {  
            if (farm[x][y] != 'x')  
            {  
              dfs(x, y, farm[x][y]);  
              ++res;  
            }  
          }  
        }  
        cout << res << endl;  
      }  
      return 0;  
    }  

Measured memory_bytes: 3576
program count_order
    implicit none
    integer(4):: n, i
    integer(4), allocatable:: p(:), q(:)
    integer(4), parameter:: bi(8) = [1, 2, 6, 24, 120, 720, 5040, 40320]

    read*, n
    allocate(p(n), q(n))
    read*, p(:)
    read*, q(:)

    do i = 1, n-1
        where(p(i+1:) > p(i))
            p(i+1:) = p(i+1:) - 1
        end where
        where( q(i+1:) > q(i))
            q(i+1:) = q(i+1:) - 1
        end where
        p(i) = p(i) * bi(n-i)
        q(i) = q(i) * bi(n-i)
    end do

    print*, abs(sum(p-q))
end program count_order

Measured memory_bytes: 512
from collections import Counter
import sys
input = sys.stdin.buffer.readline

N = int(input())

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

def make(a, b):
    if a == b == 0:
        return (0, 0, 0)
    if a == 0:
        return (0, 1, 0)
    if b == 0:
        return (1, 0, 0)

    s = 1 if a * b > 0 else -1
    a, b = abs(a), abs(b)

    g = gcd(a, b)
    a //= g
    b //= g

    return (a, b, s)

ABS = Counter([make(*map(int, input().split())) for _ in range(N)])

ans = 1
MOD = 10**9 + 7

for a, b, s in list(ABS.keys()):
    if a == b == 0:
        continue
    p = ABS[(a, b, s)]
    n = ABS[(b, a, -s)]

    ABS[(a, b, s)] = 0
    ABS[(b, a, -s)] = 0

    cnt = pow(2, p, MOD) + pow(2, n, MOD) - 1
    ans = (ans * cnt) % MOD

ans += ABS[(0, 0, 0)]

print((ans - 1) % MOD)


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

int main() {

    int N,M;
    cin >>N>>M;
    vector<int> L(M),R(M);
    int sum,mini=100000,max1 =0;

    for (int i = 0; i < M; ++i) {
        cin>>L[i]>>R[i];
        max1=max(max1, L[i]);
        mini=min(mini, R[i]);
    }

    if(mini>=max1){
        sum = mini-max1+1;
    }else{
        sum = 0;
    }
    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

ll c[101][101];

void init() {
	c[0][0] = 1;
	for (int i = 0; i <= 100; ++i) {
		for (int j = 0; j <= i; ++j) {
			c[i + 1][j] += c[i][j];
			c[i + 1][j + 1] += c[i][j];
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	init();
	int n, a, b;
	cin >> n >> a >> b;
	vector<ll> v(n);
	rep(i, n) cin >> v[i];
	sort(rall(v));
	ll sum = 0;
	rep(i, a) sum += v[i];
	double ans1 = sum / (double)a;
	int cnt1 = 0, cnt2 = 0;
	rep(i, n) {
		if (v[i] == v[a - 1]) {
			cnt1++;
			if (i < a) cnt2++;
		}
	}
	ll ans2 = 0;
	if (cnt2 == a) {
		for (int i = a; i <= b; ++i) {
			ans2 += c[cnt1][i];
		}
	}
	else {
		ans2 += c[cnt1][cnt2];
	}
	cout.precision(10);
	cout << fixed << ans1 << endl;
	cout << ans2 << endl;
	return 0;
}


Measured memory_bytes: 384
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]
s.sort()
ans = 0
count = 1
for i in range(1,n):
    if s[i] != s[i-1]:
        ans += count * (count-1) //2
        count = 1
    else:
        count+=1
ans +=count*(count-1)//2
print(ans)

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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  int t = b - a;
  int n1 = t * (t - 1) / 2, n2 = t * (t + 1) / 2;
  cout << n1 - a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;
vector<vi> g;

pii dfs(int u, int p) {
    pii ans = pii(1, 1);
    for (int v : g[u]) {
        if (v != p) {
            pii res = dfs(v, u);
            ans.first = (ll)ans.first * (res.first + res.second) % MOD;
            ans.second = (ll)ans.second * res.first % MOD;
        }
    }
    return ans;
}

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n){
        g = vector<vi>(n);
        REP(i, n-1) {
            int u, v;
            cin >> u >> v;- u--; v--;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        pii ans = dfs(0, -1);
        cout << (ans.first + ans.second) % MOD << endl;
    }
    return 0;
}


Measured memory_bytes: 12672
/* 
   AOJ 1149
   Cut the Cake

*/

#include<stdio.h>
#include<stdlib.h>

#define MAX_CAKE 102

typedef struct cake
{
  int w, d, area;
}cake;

int cake_num = 1;
cake cake_arr[MAX_CAKE];



int comp(const void *a, const void *b)
{
  cake cake_a = *(cake *)a;
  cake cake_b = *(cake *)b;

  if(cake_a.area < cake_b.area)
    return -1;
  else
    return 1;
}

void new(int w, int d)
{
  cake_arr[cake_num].w = w;
  cake_arr[cake_num].d = d;
  cake_arr[cake_num].area = w * d;
}

void update_cake_num(int p)
{
  int i;
  cake tmp;
  for(i = p + 1; i <= cake_num; i++)
    cake_arr[i - 1] = cake_arr[i];
}

void cut(cake cutted_cake, int s)
{
  int w = cutted_cake.w, d = cutted_cake.d;
  cake cake_0, cake_1;
  s = s % (2 * (w + d));
  if(s <= w)
    {
      cake_0.w = s, cake_0.d = d;
      cake_1.w = w - s, cake_1.d = d;
    }
  else if(s <= w + d)
    {
      cake_0.w = w, cake_0.d = s - w;
      cake_1.w = w, cake_1.d = w + d - s;
    }
  else if(s <= 2 * w + d)
    {
      cake_0.w = s - (w + d), cake_0.d = d;
      cake_1.w = 2 * w + d - s, cake_1.d = d;
    }
  else
    {
      cake_0.w = w, cake_0.d = s - (2 * w + d);
      cake_1.w = w, cake_1.d = 2 * (w + d) - s;
    }

  cake_0.area = cake_0.w * cake_0.d, cake_1.area = cake_1.w * cake_1.d;

  if(cake_0.area == 0)
    cake_arr[cake_num] = cake_1;
  else if(cake_1.area == 0)
    cake_arr[cake_num] = cake_0;
  else if(cake_0.area < cake_1.area)
    {
      cake_arr[cake_num++] = cake_0;
      cake_arr[cake_num] = cake_1;
    }
  else
    {
      cake_arr[cake_num++] = cake_1;
      cake_arr[cake_num] = cake_0;
    }
}

/* 
   --test-case--
   3 5 6
   1 18
   2 19
   1 2
   ------------
*/


void init(void)
{
  int i;
  for(i = 1; i <=cake_num; i++)
    cake_arr[i].w = 0, cake_arr[i].d = 0, cake_arr[i].area = 0;

  cake_num = 1;
}


int main(void)
{
  int n, w, d, i, p, s;

  while(scanf("%d %d %d", &n, &w, &d), (n + w + d))
    {

      new(w, d);
      for(i = 0; i < n; i++)
	{
	  scanf("%d %d", &p, &s);
	  cake cutted_cake = cake_arr[p];
	  update_cake_num(p);
	  cut(cutted_cake, s);
	}
      qsort((void *)(cake_arr + 1), n + 1, sizeof(cake), comp);
      for(i = 1; i <= cake_num; i++)
	{
	  if(i == cake_num)
	    printf("%d\n", cake_arr[i].area);
	  else
	    printf("%d ", cake_arr[i].area);	  
	}
      init();
    }
  return 0;
}

Measured memory_bytes: 644
while True:
	H, W = map(int, input().split())
	if H == 0 and W == 0:
		break
	for i in range(H):
		for j in range(W):
			if (i + j) % 2 == 0:
				print("#", end = '')
			else:
				print(".", end = '')
		print()
	print()



Measured memory_bytes: 7004
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

point = {'r': R, 's': S, 'p': P}
win_point = {'r': P, 's': R, 'p': S}
win_result = {'r': 'p', 's': 'r', 'p': 's'}

total = 0

my_result = [] # 勝ち:1, それ以外:0
# K回目までは自由に出せるので勝てる手を出す
for i in range(K):
  # print(T[i], win_point[T[i]])
  total += win_point[T[i]]
  my_result.append(1)

# K回目からは勝てるときだけ勝てる手を出す
for i in range(K, N):
  #print(T[i-K], T[i], my_result[i-K])
  win_te = win_result[T[i]]
  # K個前の手と異なるのであれば勝てる手を出す
  if T[i-K] != T[i]:
    total += point[win_te]
    my_result.append(1)
  # K個前と同じ手でも、勝てる手を出してないのであれば勝てる手を出す
  elif my_result[i-K] == 0:
    total += point[win_te]
    my_result.append(1)
  else:
    my_result.append(0)

print(total)

Measured memory_bytes: 4212
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n, k;
    cin >> n >> k;
    int res = 0;
    int mx = 0;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        mx = max(mx, x);
        res = (res ? __gcd(res, x) : x);
    }
    cout << (k % res == 0 && k <= mx ? "POSSIBLE" : "IMPOSSIBLE");
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    r,c,rr,cc=map(int,input().split())
    def COMinit(n,MOD):
        fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1)
        fac[0]=fac[1]=1
        finv[0]=finv[1]=1
        inv[1]=1
        for i in range(2,(n+1)):
            fac[i]=fac[i-1]*i%MOD
            inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
            finv[i]=finv[i-1]*inv[i]%MOD
        return fac,finv,inv
    
    fac,finv,inv=COMinit(rr+cc+10,MOD)
    
    def COM(n, k, MOD=MOD):
        if n<k or n<0 or k<0:
            return 0
        return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
    
    ans=COM(rr+cc+2,rr+1)-COM(rr+c+1,c)-COM(r+cc+1,r)+COM(r+c,r)
    ans%=MOD
    print(ans)

if __name__ == '__main__':
    main()


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

int n;
long long ans;
int a[200000], b[200000];

bool dfs(int i) {
    if (b[(i + n - 1) % n] + b[(i + 1) % n] <= b[i] - a[i]) {
        int x = (b[i] - a[i]) / (b[(i + n - 1) % n] + b[(i + 1) % n]);
        b[i] -= x * (b[(i + n - 1) % n] + b[(i + 1) % n]);
        ans += x;
        dfs((i + 1) % n);
        dfs((i + n - 1) % n);
        return true;
    } else {
        return false;
    }
}

int main(void) {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &b[i]);
    }

    bool end = false;
    while (!end) {
        end = true;
        bool found = false;
        for (int i = 0; i < n; i++) {
            if (b[i] < a[i]) {
                puts("-1");
                return 0;
            }
            found |= dfs(i);
            end &= b[i] == a[i];
        }
        if (!end && !found) {
            puts("-1");
            return 0;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt();
		int p = 0;
		for(int i = 1; i < B; i++) {
			if(A * i % B == C) {
				System.out.println("YES"); 
				p = 1; 
				break;
			}
		}
		if(p == 0)System.out.println("NO");
	}

}


Measured memory_bytes: 23636
'use strict';
(function(stdin) {

  var inputs  = stdin.toString().trim().split('\n');
  var cols = inputs[0].split(' ');
  var a = parseInt(cols[0], 10);
  var b = parseInt(cols[1], 10);
  var c = parseInt(cols[2], 10);

function f(a,b,c){
  if(a < b && b < c){
    return 'Yes';
}else{
  return 'No';
}}
  console.log(f(a,b,c));
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15520
#include <bits/stdc++.h>
#define m mob[i]
#define test_output for (int i = 1; i <= n; ++i) cout << m.range_left << ' ' << m.range_right << ' ' << m.hp << '\n'
using namespace std;

struct monster
{
    int range_left, range_right, hp;
};

monster mob[200001];
int n, d, fin, a, b[200001], j = 2;
long long s, nr_bombs;

bool cmp(monster a, monster b)
{
    return a.range_left < b.range_left;
}

int main()
{
    cin >> n >> d >> a;
    for (int i = 1; i <= n; ++i)
    {
        cin >> m.range_left >> m.hp;
        m.range_right = 2 * d + m.range_left;
    }
    sort(mob + 1, mob + n + 1, &cmp);
    ///test_output;
    for (int i = 1; i <= n; ++i)
    {
        b[i] += b[i - 1];
        m.hp += b[i];
        if (m.hp > 0)
        {
            nr_bombs = m.hp / a + 1;
            if (m.hp % a == 0) nr_bombs--;
            s += nr_bombs;
            b[i] -= nr_bombs * a;
            fin = m.range_right;
            m.hp = 0;
            while (mob[j].range_left <= fin && j <= n)
                j++;
            b[j] += nr_bombs * a;
        }
    }
    cout << s;
    return 0;
}


Measured memory_bytes: 3328
def main():
    a, b, c, d, e, f = map(int, input().split())
    a *= 100
    b *= 100
    m = (-1, 0, 0)
    for i in range(f // a + 1):
        for j in range((f - (a * i)) // b + 1):
            ma = a * i + b * j
            if ma == 0:
                continue
            for k in range((f - ma) // c + 1):
                if 100 * c * k > ma * e:
                    break
                for l in range((f - (ma + c * k)) // d + 1):
                    mb = c * k + d * l
                    if 100 * mb > ma * e:
                        break
                    dab = mb / (ma + mb)
                    if dab > m[0]:
                        m = (dab, ma + mb, mb)
    print(m[1], m[2])


if __name__ == '__main__':
    main()


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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

int c[20];
int a[20][20];

int main(){
	setIO();
	int n, m, x, mn=INF;
	cin>>n>>m>>x;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	}
	for(int i=0;i<(1<<n);i++){
		int tp[20]={}, sum=0;
		bool vld=true;
		for(int j=1,l=1;l<=i;l<<=1,j++){
			if(l&i){
				sum+=c[j];
				for(int k=1;k<=m;k++)
					tp[k]+=a[j][k];
			}
		}
		for(int j=1;j<=m;j++){
			if(tp[j]<x) vld=false;
		}
		if(vld) mn=min(mn, sum);
	}
	if(mn==INF) cout<<"-1\n";
	else cout<<mn<<endl;
}

Measured memory_bytes: 3644
#include<iostream>
#include<string.h>
using namespace std;
int main(){
int a=0,b=0,c=0,d=0;
  int n;
  cin>>n;
  string q;
  while(n){
  
  cin>>q;
  if (q=="AC")
    a++;
  else if(q=="WA")
    b++;
  else if(q=="TLE")
    c++;
  else if (q=="RE")
    d++;
  n--;
  }

cout<<"AC x "<<a<<endl;
cout<<"WA x "<<b<<endl;
cout<<"TLE x "<<c<<endl;
cout<<"RE x "<<d<<endl;
return 0;
}


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

using namespace std;

int main(){
  int N;
  long long K;
  while(cin >> N >> K){
    vector< vector<int> > cnt(41, vector<int>(2, 0));
      long long A;
      for (int j = 0; j < N;j++){
      cin >> A;
        for (int i = 0; i < 41; i++)
          cnt[i][(A >> i) & 1]++;
      }
      long long res = 0LL;
      long long sum = 0LL;
      for (int i = 40; i >= 0;i--){
        if(K&(1LL<<i)){
          long long cur = sum;
          cur += cnt[i][1] * (1LL << i);
          for (int j = i - 1; j >= 0;j--){
            cur += max(cnt[j][0], cnt[j][1]) * (1LL << j);
          }
          res = max(res, cur);
        }
        sum += cnt[i][1 - (K >> i) % 2] * (1LL << i);
      }
      cout << max(sum, res) << endl;
    }
}

Measured memory_bytes: 256