akhauriyash/Code-Regression huggingface dataset:
N, M, Q = map(int, input().split())
Data = [list(map(lambda x: int(x) - 1, input().split())) for i in range(M)]


class Ruisekiwa2D:
    def __init__(self, h, w):
        self.H = h
        self.W = w
        self.G = [[0] * w for _ in range(h)]

    def load(self, points):
        # 問題によってイメージしやすいよう書き換えてください
        for x, y in points:
            self.G[x][y] += 1

    def load_imos(self, points):
        # pointsは[[左上h, 左上w, 右下h, 右下w], ...]であること
        for i1, j1, i2, j2 in points:
            self.G[i1][j1] += 1  # 左上
            if j2 + 1 < self.W:  # 右上
                self.G[i1][j2+1] -= 1
            if i2 + 1 < self.H:
                self.G[i2+1][j1] -= 1  # 左下
            if j2 + 1 < self.W and i2 + 1 < self.H:  # 右下
                self.G[i2+1][j2+1] += 1

    def calc(self):
        for y in range(self.W):
            for x in range(1, self.H):
                self.G[x][y] += self.G[x-1][y]

        for y in range(1, self.W):
            for x in range(self.H):
                self.G[x][y] += self.G[x][y-1]

    def get(self, i1, j1, i2, j2):
        if i1 > i2 or j1 > j2 or i1 < 0 or j1 < 0 or i2 < 0 or j2 < 0:
            return 0
        elif i1 > 0 and j1 > 0:
            return self.G[i2][j2] - self.G[i1-1][j2] - self.G[i2][j1-1] + self.G[i1-1][j1-1]
        elif i1 <= 0 < j1:
            return self.G[i2][j2] - self.G[i2][j1-1]
        elif j1 <= 0 < i1:
            return self.G[i2][j2] - self.G[i1 - 1][j2]
        else:
            return self.G[i2][j2]


# 二次元累積和( ･´ｰ･｀)
R2D = Ruisekiwa2D(N, N)
R2D.load(Data)
R2D.calc()


# クエリに答えていく
for i in range(Q):
    p, q = map(int, input().split())
    p, q = p - 1, q - 1
    print(R2D.get(p, p, q, q))


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

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

	int64 H, W;
	cin >> H >> W;
	int64 Ch, Cw, Dh, Dw;
	cin >> Ch >> Cw >> Dh >> Dw;
	Ch--; Cw--; Dh--; Dw--;
	vector<string> S(H);
	REP(i, H) cin >> S[i];

	auto dy = vector<int>({-1, 0, 1, 0});
	auto dx = vector<int>({0, -1, 0, 1});

	auto in = [&](int y, int x) {
	  return 0<=y&&y<H&&0<=x&&x<W&&S[y][x]=='.';
	};

	auto d = make_v<int>(H, W);
	fill_v<int>(d, INF);

	d[Ch][Cw] = 0;

	using T = tuple<int, int, int>;
	deque<T> q;
	q.push_back({0, Ch, Cw});

	while (q.size()) {
	  int c, y, x;
	  tie(c, y, x) = q.front(); q.pop_front();
	  if (c > d[y][x]) continue;
	  REP(i, 4) {
	    int yy= y + dy[i], xx = x+ dx[i];
	    if (!in(yy, xx)) continue;
	    if (d[yy][xx] > d[y][x]) {
	      d[yy][xx] = d[y][x];
	      q.emplace_front(d[yy][xx], yy, xx);
	    }
	  }
	  FOR(cy, -2, 3) {
	    FOR(cx, -2, 3) {
	      int yy = y + cy, xx =x + cx;
	      if (!in(yy, xx)) continue;
	      if (d[yy][xx] > d[y][x] + 1) {
	        d[yy][xx] = d[y][x] + 1;
	        q.emplace_back(d[yy][xx], yy, xx);
	      }
	    }
	  }
	}
	if (d[Dh][Dw] == INF) {
	  cout << -1 << endl;
	} else {
	  cout << d[Dh][Dw] << endl;
	}

}


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

int main()
{
    int N, n, f;
    int j = 1;
    f = 0;

    cin >> N;

    while (N / j >= 10)
    {
        j *= 10;
    }

    //  cout << j << endl;

    n = N;
    while (j != 0)
    {
        //      cout << n << endl;
        f += n / j;
        //        cout << f << endl;

        if (n % j == 0)
        {
            break;
        }

        n = n % j;
        j /= 10;
    }

    //  cout << N << endl << n << endl << f << endl;

    if (N % f == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
h,w = map(int,input().split())
t = [list(input()) for i in range(h)]
a = [[0 for i in range(w)] for j in range(h)]
x = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    if t[i][j] == "#":
      x[i][j] = -1
    elif j == 0:
      x[i][j] = 0
    else:
      x[i][j] = x[i][j-1]+1
      a[i][j] += x[i][j]
x = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w-1,-1,-1):
    if t[i][j] == "#":
      x[i][j] = -1
    elif j == w-1:
      x[i][j] += 0
    else:
      x[i][j] = x[i][j+1]+1
      a[i][j] += x[i][j]
x = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    if t[i][j] == "#":
      x[i][j] = -1
    elif i == 0:
      a[i][j] += 0
    else:
      x[i][j] = x[i-1][j]+1
      a[i][j] += x[i][j]
x = [[0 for i in range(w)] for j in range(h)]
for i in range(h-1,-1,-1):
  for j in range(w):
    if t[i][j] == "#":
      x[i][j] = -1
    elif i == h-1:
      a[i][j] += 0
    else:
      x[i][j] = x[i+1][j]+1
      a[i][j] += x[i][j]
print(max(max(a[i]) for i in range(h))+1)

Measured memory_bytes: 347400
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]

sortAB = sorted(AB, key = lambda x: (x[1]))
t = 0
for a, b in sortAB:
  t += a
  if t > b:
    print("No")
    break
else:
  print("Yes")

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換

int main() {
    string s;
    cin >> s;
    int n = s.size() - 1;
    for (int bit = 0; bit < (1 << n); ++bit) {
        string S = s;
        for (int i = 0; i < n; i++) {
            int g = 2 * (i + 1) - 1;
            if (bit & (1 << i)) {
                S.insert(g, "+");
            } else {
                S.insert(g, "-");
            }
        }
        int count=0;
        bool flag=true;
        for(int i=0;i<S.size();i++){
            if(S[i]=='+'){
                flag=true;
            }else if(S[i]=='-'){
                flag=false;
            }else
            {
                if(flag){
                    count+=S[i]-'0';
                }else
                {
                    count-=S[i]-'0';
                }
                
            }
        }
        if(count==7){
            cout<<S<<"=7"<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3604
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from math import gcd
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7

n=I()
flg=[0]*n
for i in range(n):
    d,e=LI()
    if d==e:
        flg[i]=1

for j in range(n-2):
    if flg[j] and flg[j+1] and flg[j+2]:
        print("Yes")
        exit()

print("No")


Measured memory_bytes: 76716
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

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

		String s = br.readLine();
		String[] array = s.split(" ");
		int a = Integer.parseInt(array[0]);
		String op = array[1];
		int b = Integer.parseInt(array[2]);

		if (op.equals("+")) {
			System.out.println(a + b);
		} else {
			System.out.println(a - b);
		}
	}
}


Measured memory_bytes: 22740
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


int main()
{ios_base::sync_with_stdio(false);
ld r;
cin>>r;
ld ans=acos(-1)*2*r;
cout<<fixed<<setprecision(20)<<ans;
return 0;
}



Measured memory_bytes: 3804
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 8000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

int main() 
{
    FAST;
    ll a,b,m;
    cin>>a>>b>>m;
    ll r[a+1],mi[b+1];
    ll x,y,c;
    ll mi1=C,mi2=C,ans=0;
    for(int i=1;i<=a;i++)
    {
        cin>>r[i];
        mi1=min(mi1,r[i]);
    }
    for(int i=1;i<=b;i++)
    {
        cin>>mi[i];
        mi2=min(mi2,mi[i]);
    }
    ans=mi1+mi2;
    for(int i=0;i<m;i++)
    {
        cin>>x>>y>>c;
        ans=min(ans,r[x]+mi[y]-c);
    }
    cout<<ans;
    subt;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int n, d;
Int a[216000];
Int sums[216000];
Int difs[216000];
Int res;
int main(){
  cin >> n >> d;
  for(int i = 0;i < n;i++){
    cin >> a[i];
    sums[i] = a[i] + i * d;
    difs[i] = a[i] - i * d;
    res += 2 * a[i];
  }
  res += (n-1)*d;
  res -= a[0] + a[n-1];
  for(int i = 1;i < n;i++)difs[i] = min(difs[i], difs[i-1]);
  for(int i = n-2;i >= 0;i--)sums[i] = min(sums[i], sums[i+1]);
  for(int i = 1;i < n-1;i++){
    //    cout << difs[i] << " " << sums[i] << endl;
    Int ltmp = -a[i] + i*d + difs[i];
    Int rtmp = -a[i] - i*d + sums[i];
    //    cout << ltmp << " " << rtmp << endl;
    res += min(ltmp, rtmp);
  }

  cout << res << endl; 
  return 0;
}

Measured memory_bytes: 5752
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    int N;
    cin >> N;
    cout << (1000 - N%1000)%1000 << endl;
}

Measured memory_bytes: 3632
# include <bits/stdc++.h>
using namespace std;
 
int main () {
  int A, B;
  char op;
  cin >> A >> op >> B;
  
  if (op == '+') {
    cout << A + B << endl;
  }
  if (op == '-') {
    cout << A - B << endl;
  }
}
 

Measured memory_bytes: 384
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    X, Y, _ = list(map(int, input().split()))
    uf.union(X-1,Y-1)
print(uf.group_count())

Measured memory_bytes: 69208
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <functional>

int main() {
  int N;
  std::string S;
  std::cin >> N >> S;

  // 累積和
  std::vector<int> vW(N+1, 0), vE(N+1, 0);
  for (int i = 0; i < N; ++i) {
    vW[i+1] += vW[i];
    if (S[i] == 'W') vW[i+1] += 1;

    vE[i+1] += vE[i];
    if (S[i] == 'E') vE[i+1] += 1;
  }

  int res = N + 1;
  for (int i = 0; i < N; ++i) {
    int switch_count = 0;
    switch_count += vW[i] + (vE[N] - vE[i + 1]);
    res = std::min(res, switch_count);
  }
  std::cout << res << "\n";
  return 0;
}


Measured memory_bytes: 2948
#include<iostream>                                        
using namespace  std;                                     
                                                          
int main(){                                               
  int n;                                                  
  cin >> n;                                               
  char egara;                                             
  int moji;                                               
  int i,j;                                                
  int card[4][13] = {                                     
    {1,2,3,4,5,6,7,8,9,10,11,12,13},                      
    {1,2,3,4,5,6,7,8,9,10,11,12,13},                      
    {1,2,3,4,5,6,7,8,9,10,11,12,13},                      
    {1,2,3,4,5,6,7,8,9,10,11,12,13}                       
  };                                                      
  int card2[4][13] = {};                                  
                                                          
  for(j=0;j<n;j++){                                       
    cin >> egara >> moji;                                 
    for(i=1;i<=13;i++){                                   
      if(egara == 'S'){                                   
        if(moji == i){                                    
          card2[0][i-1] = i;                              
        }                                                 
      } else if (egara == 'H'){                           
        if(moji == i){                                    
          card2[1][i-1] = i;                              
        }                                                 
      } else if (egara == 'C'){                           
        if(moji == i){                                    
          card2[2][i-1] = i;                              
        }                                                 
      } else {                                            
        if(moji == i){                                    
          card2[3][i-1] = i;                              
        }                                                 
      }                                                   
    }                                                     
  }     
                                   
for(i=0;i<4;i++){                                       
    for(j=0;j<13;j++){                                    
      if(card[i][j] != card2[i][j]){                      
        if(i==0) cout << 'S';                             
        else if(i==1) cout << 'H';                        
        else if(i==2) cout << 'C';                        
        else cout << 'D';                                 
        cout << " " << card[i][j] << endl;                
      }                                                   
    }                                                     
  }                                                       
                                                          
  return 0;                                               
}   

Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int cards[5], i, j, t, r, fl, fl2;
	char c, str[8][11] = {"null", "one pair", "two pair", "three card", "straight", "full house", "four card"};
	while (cin >> cards[0] >> c >> cards[1] >> c >> cards[2] >> c >> cards[3] >> c >> cards[4])
	{
		r = 1;
		sort(cards, cards+5);
		int n[13] = {0};
		for (i = 0; i < 5; i++)
			n[cards[i]-1]++;
		for (i = fl = t = 0; i < 13; i++)
			if (n[i] == 2)	t++;
		if (t == 1)	r = 2;
		if (t == 2)	r = 3;
		for (i = fl = 0; i < 13 && !fl; i++)
			if (n[i] == 3)	r = 4, fl = 1;
		for (i = fl = 0; i < 9 && !fl; i++)
		{
			for (j = 0, fl2 = 1; j < 5 && fl2; j++)
				if (n[i+j] != 1)	fl2 = 0;
			if (fl2)	r = 5, fl2 = 1;
		}
		if (!fl)
		{
			for (i = 9, fl = 0; i < 13 && !fl; i++)
				if (n[i] != 1)	fl = 1;
			if (!fl && n[0])	r = 5;
		}
		for (i = fl = fl2 = 0; i < 13; i++)
		{
			if (n[i] == 2)	fl = 1;
			if (n[i] == 3)	fl2 = 1;
		}
		if (fl && fl2)	r = 6;
		for (i = fl = 0; i < 13 && !fl; i++)
			if (n[i] == 4)
				r = 7, fl = 1;
		cout << str[r-1] << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define MAX 110
#define inf 1<<28
#define f first
#define s second
#define mp make_pair
using namespace std;

int w,h,n,si,sj,gi,gj;
bool grid[MAX][MAX]={};
int Y[4]={1,0,-1,0};
int X[4]={0,1,0,-1};

int bfs(){
  int d[MAX][MAX];
  for(int i=0;i<MAX;i++){
    for(int j=0;j<MAX;j++)d[i][j]=inf;
  }
  d[si][sj]=0;
  queue<pair<int,int> > q;
  q.push(mp(si,sj));

  while(q.size()){
    pair<int,int> u=q.front();
    q.pop();
    if(u.f==gi && u.s==gj)return d[gi][gj];

    for(int k=0;k<4;k++){
      int a=u.f+Y[k],b=u.s+X[k];
      if(grid[a][b])continue;
      a+=Y[k];
      b+=X[k];
      if(d[u.f][u.s]+1<d[a][b]){
	d[a][b]=d[u.f][u.s]+1;
	q.push(mp(a,b));
      }
    }
  }
  return -1;
}

int main()
{
  int a,b,c,d;
 
  cin>>w>>h>>n;

  for(int i=0;i<=h*2;i++)grid[i][0]=grid[i][w*2]=true;
  for(int i=0;i<=w*2;i++)grid[0][i]=grid[h*2][i]=true;

  for(int i=0;i<n;i++){
    cin>>a>>b>>c>>d;
    for(int j=min(a,c)*2;j<=max(a,c)*2;j++){
      for(int k=min(b,d)*2;k<=max(b,d)*2;k++)grid[k][j]=true;
    }
  }
  cin>>sj>>si>>gj>>gi;
  si=si*2+1;
  sj=sj*2+1;
  gi=gi*2+1;
  gj=gj*2+1;

  int dis=bfs(),ans=0;

  for(int i=2;i<=h*2-2;i+=2){
    for(int j=1;j<=w*2-1;j+=2){
      if(grid[i][j])continue;
      grid[i][j]=true;
      ans=max(bfs()-dis,ans);
      grid[i][j]=false;
    }
  }
  for(int i=1;i<=h*2-1;i+=2){
    for(int j=2;j<=w*2-2;j+=2){
      if(grid[i][j])continue;
      grid[i][j]=true;
      ans=max(bfs()-dis,ans);
      grid[i][j]=false;
    }
  }
  cout<<ans<<endl;  

  return 0;
}

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

int main(){
  int N,K;
  cin>>N>>K;
  vector<double> sum(N+1);
  sum.at(0)=0;
  for(int i=0;i<N;i++){
    double p;
    cin>>p;
    sum.at(i+1)=(p+1.0)/2.0+sum.at(i);
  }
  
  double ans=0;
  for(int i=0;i<N-K+1;i++){
    ans=max(ans,sum.at(i+K)-sum.at(i));
  }
  
  printf("%lf\n",ans);
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<algorithm>
#define ll long long
using namespace std;
ll dp[50][1<<17];
const ll mod=1e9+7;
int n,x,y,z;
int main()
{
scanf("%d%d%d%d",&n,&x,&y,&z);
memset(dp,0,sizeof(dp));
dp[0][0]=1;
ll ans=1;
int base=((1<<(x+y+z-1))|(1<<(y+z-1))|(1<<(z-1)));
for(int i=1;i<=n;i++)
    ans=ans*10%mod;
    int sta=(1<<(x+y+z))-1;
    for(int i=1;i<=n;i++)
    {
        for(int s=0;s<=sta;s++)
        {if(dp[i-1][s]==0)
        continue;
            for(int k=1;k<=10;k++)
            {
                int now=s<<k|(1<<k-1);
                now&=sta;
                if((now&base)!=base)
                    dp[i][now]=(dp[i][now]+dp[i-1][s])%mod;
            }
        }
    }
        for(int i=0;i<=sta;i++)
            ans=(ans-dp[n][i]+mod)%mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 51456
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string day[8] = {"", "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};
    string s;
    cin >> s;
    int ans;
    for (int i = 0; i < 8; i++)
    {
        if (s == day[i])
        {
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
let cost = Array.get [| 2; 5; 5; 4; 5; 6; 3; 7; 6 |]

let () = Scanf.scanf "%d %d" @@ fun n m ->
  let as_ = Array.init m @@ fun m -> Scanf.scanf "%c%d" @@ fun _ a -> a in
  let dp = Array.make (n + 10) (0, []) in
  Array.iter (fun a ->
    dp.(cost (a - 1)) <- max dp.(cost (a - 1)) (1, [a])) as_;
  for i = 0 to n - 1 do
    Array.iter (fun a ->
      if 0 < fst dp.(i) then
        dp.(i + cost (a - 1)) <-
          max dp.(i + cost (a - 1)) @@ (fst dp.(i) + 1, a :: snd dp.(i))) as_
  done;
  List.iter print_int (snd dp.(n));
  print_newline ()


Measured memory_bytes: 5120
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;


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

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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main()
{
   V a(3);rep(i,3)cin >>a[i];
   sort(all(a));
   bool flg=false;
   if(a[2]==a[1]+a[0])flg=true;
   if(flg)puts("Yes");
   else puts("No");
    return 0;
}


Measured memory_bytes: 256
def my_print():
    print("{}".format("".join(str[command[1]: command[2]])))

def replace():
    command[3] = list(command[3])
    str[command[1]: command[2]] = command[3]

def reverse():
    str[command[1]: command[2]] = reversed(str[command[1]: command[2]])

str = list(input())
q = int(input())
for i in range(q):
    command = input().split()
    command[1], command[2] = int(command[1]), int(command[2]) + 1
    if command[0] == "print":
        my_print()
    elif command[0] == "replace":
        replace()
    else:
        reverse()



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

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        ll x = i + 1;
        if (x % 15 == 0 || x % 3 == 0 || x % 5 == 0) {
            continue;
        } else {
            ans += x;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
#define REP(i, d, n) for(int i=(d); i<(n); i++)
typedef long long ll;
const int mod = 1e9 + 7;

int n, m;
int g[50][50] = {};

void dfs(vector<bool> &visit, int num){
    if(visit[num]){
        return;
    }

    visit[num] = true;
    rep(i, n){
        if(g[num][i] == 1){
            dfs(visit, i);
        }
    }
}

int main() {

    cin >> n >> m;

    int a[50], b[50];
    rep(i, m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        g[a[i]][b[i]] = 1;
        g[b[i]][a[i]] = 1;
    }

    int ans = 0;
    rep(i, m){
        vector<bool> visit(n, false);
        
        g[a[i]][b[i]] = g[b[i]][a[i]] = 0;
        dfs(visit, 0);

        rep(k, n){
            if(!visit[k]){
                ans++;
                break;
            }
        }
        g[a[i]][b[i]] = g[b[i]][a[i]] = 1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem{

    void Solve() {
        UL N; cin >> N;
        vector<pair<int, int>> M(N);
        rep(i, N) {
            string S; cin >> S;
            for (char c : S) {
                if (c == '(') M[i].second++;
                else {
                    if (M[i].second > 0) M[i].second--;
                    else M[i].first++;
                }
            }
        }
        {
            int L, R; L = R = 0;
            rep(i, N) { L += M[i].first; R += M[i].second; }
            if (L != R) { cout << "No" << endl; return; }
        }

        rep(t, 2) {
            sort(M.begin(), M.end());
            int R = 0;
            priority_queue<int> Q;
            UL p = 0;
            while (true) {
                while (true) {
                    if (p >= N) break;
                    if (M[p].first > R) break;
                    Q.push(M[p].second - M[p].first);
                    p++;
                }
                if (Q.empty()) break;
                int d = Q.top(); Q.pop();
                R += d;
                if (R < 0) { cout << "No" << endl; return; }
            }
            if (p < N) { cout << "No" << endl; return; }
            rep(i, N) swap(M[i].first, M[i].second);
        }
        cout << "Yes" << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}


Measured memory_bytes: 18916
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)


  int main(){
    int a,b,c;
    string s,t;
    cin >> s >> t;
    string ans="";
    rep(i,s.size()){
      ans+=s[i];
      if (i < t.size()) ans+=t[i];
    }
    cout << ans << endl;
   
    return 0;
  }


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

using namespace std;

const int MAX_N = 22, MOD = 1e9 + 7;

int n;
int a[MAX_N][MAX_N];
int memo[MAX_N][1 << MAX_N];

inline void selfAdd (int& a, int b) { a = (a + b) % MOD; }

int dp (int pos, int mask) {
  if (pos == n) return 1;
  int& ret = memo[pos][mask];
  if (~ret) return ret;
  ret = 0;
  for (int j = 0; j < n; j++) {
    if (a[pos][j] and (mask >> j) & 1) selfAdd(ret, dp(pos + 1, mask & (~(1 << j))));
  }
  return ret;
}


int main () {
  cin >> n;
  for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j];
  memset(memo, -1, sizeof memo);
  cout << dp(0, (1 << n) - 1) << endl;
  return (0);
}


Measured memory_bytes: 360704
#include<bits/stdc++.h>
#define ri register int
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define fi first
#define se second
const int rlen=1<<18|1;
char buf[rlen],*ib=buf,*ob=buf;
#define gc() (((ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)),ib==ob)?-1:*ib++)
inline int read() {
  int ans=0;
  bool f=1;
  char ch=gc();
  while(!isdigit(ch)) f^=ch=='-',ch=gc();
  while(isdigit(ch)) ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
  return f?ans:-ans;
}
namespace modular {
  const int mod=1e9+7;
  inline int add(int a,int b) { return a+b<mod?a+b:a+b-mod; }
  inline int dec(int a,int b) { return a<b?a-b+mod:a-b; }
  inline int mul(int a,int b) { return (ll)a*b%mod; }
  inline void Add(int&a,int b) { a=a+b<mod?a+b:a+b-mod; }
  inline void Dec(int&a,int b) { a=a<b?a-b+mod:a-b; }
  inline void Mul(int&a,int b) { a=(ll)a*b%mod; }
  inline int ksm(int a,int p) { int ret=1;for(;p;p>>=1,Mul(a,a)) (p&1)&&(Mul(ret,a),1);return ret; }
  inline int Inv(int a) { return ksm(a,mod-2); }
}
using namespace modular;
const int N=2e5+5;
int n,a[N<<1],b[N<<1],ta[N<<1],tb[N<<1],_ta[N<<1];
bool ok[N<<1];
const int bas=37;
int main() {
  #ifdef ldxcaicai
  freopen("lx.in","r",stdin);
  #endif
  n=read();
  for(ri i=1;i<=n;++i) a[i]=read();
  for(ri i=1;i<=n;++i) b[i]=read();
  for(ri i=0;i<n;++i) ok[i]=1;
  for(ri t=30;~t;--t) {
    for(ri i=1;i<=n;++i) ta[i]=ta[i+n]=a[i]>>t&1,tb[i]=b[i]>>t&1,_ta[i]=_ta[i+n]=ta[i]^1;
    int ss=0,pw=1,sss=0,_sss=0;
    for(ri i=1;i<=n;++i) ss=add(add(ss,ss),tb[i]),(i>1)&&(pw=add(pw,pw),1),sss=add(add(sss,sss),ta[i]),_sss=add(add(_sss,_sss),_ta[i]);
    for(ri i=1;i<=n;++i) {
      if(ss!=sss&&ss!=_sss) ok[i-1]=0;
      Dec(sss,mul(pw,ta[i]));
      sss=add(add(sss,sss),ta[i+n]);
      Dec(_sss,mul(pw,_ta[i]));
      _sss=add(add(_sss,_sss),_ta[i+n]);
    }
  }
  for(ri i=0;i<n;++i) if(ok[i]) cout<<i<<' '<<(a[1+i>n?1+i-n:1+i]^b[1])<<'\n';
  return 0;
}

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

int main()
{
    ll s, c;
    cin >> s >> c;

    ll c2 = 2*s;
    if (c2 > c) {
        cout << min(c/2, s);
        return 0;
    }

    c -= c2;

    cout << s + (c / 4);
}


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

int main() {
  
  	int N,A,B;
  	cin >> N >> A >> B;
  	
  	int Fee;
  	if(A*N<=B){
    	Fee=A*N;
    }
  	else{
    	Fee=B;
    }
  	
  	cout << Fee << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str1 = sc.next();
        String str2 = sc.next();
        
        char s[] = str1.toCharArray();
        char t[] = str2.toCharArray();
        int n = s.length;
        int m = t.length;
        
        // set: 英小文字の出現位置
        TreeSet[] set = new TreeSet[26];
        for (int i = 0; i < 26; i++) {
            set[i] = new TreeSet<Integer>();
        }
        
        // 2周分覚える
        // contestcontest -> set[c] = {0, 7}
        for (int i = 0; i < n; i++) {
            char c = s[i];
            set[c - 'a'].add(i);
        }
        for (int i = 0; i < n; i++) {
            char c = s[i];
            set[c - 'a'].add(i + n);
        }
        
        // ans: 文字列tの各文字の文字列sにおける出現位置を足したもの
        // ex. (s, t) = (contest, son) => ans = 6 + 3 + 1 = 10
        long ans = 0;
        int now = -1;   // startは-1文字目から
        for (int i = 0; i < m; i++) {
            char c = t[i];
            if (set[c - 'a'].size() == 0) {
                System.out.println(-1);
                return;
            }
            
            // 文字cのnow文字目以降で最も早い出現位置を代入
            // 進んだ距離を足す
            int next = (int)set[c - 'a'].higher(now);
            ans += (next - now);
            
            // 次の周に行く場合無駄にn多くなるので減算
            if (next >= n) {
                next -= n;
            }
            now = next;
        }
        System.out.println(ans);
    }
}


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


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

  int d = a + b + c;
  if (d >= 22){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
}


Measured memory_bytes: 256
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]

import sys
import math

a.sort()
f.sort(reverse=True)

def cond(score):
    _max = 0
    count = 0
    for i in range(n):
        if a[i] * f[i] <= score:
            continue
        target = (score // f[i])
        count += a[i] - target
        if count > k:
            return False, -1
        _max = max(_max, target * f[i])
    if count <= k:
        return True, _max

def binary_search(start, end, result):
    middle = math.ceil((start + end) / 2)
    if middle == end:
        if result[start]:
            return start
        else:
            return end
    is_ok, score = cond(middle)
    result[middle] = is_ok
    if is_ok:
        return binary_search(start, min(middle, score), result)
    else:
        return binary_search(middle, end, result)

# 0
if sum(a) <= k:
    print(0)
    sys.exit(0)

max_score = 0
for i in range(n):
    max_score = max(max_score, a[i] * f[i])

# max
if k == 0:
    print(max_score)
    sys.exit(0)

# 1 - max
if cond(1)[0]:
    print(1)
    sys.exit(0)

result = {1: False, max_score: True}
print(binary_search(1, max_score, result))


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

signed main(){
 double N, K; cin >> N >> K;
 vector<double> data(N);
 for(int i = 0; i < N; i++){
   double x; cin >> x;
   data[i] = (x + 1.0) / 2.0;
 }
 double ans = 0, ans1 = 0;
 for(int i = 0; i < K; i++) ans1 += data[i];
 ans = max(ans, ans1);
 for(int i = K; i < N; i++){
   ans1 += data[i] - data[i - K];
   ans = max(ans, ans1);
 }
 cout << setprecision(10) << ans << endl;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys
MOD = 1000000007  

def solve(N: int, K: int, a: "List[int]", b: "List[int]"):
    matrix = [[] for _ in range(N+1)]
    for i in range(N-1):
        matrix[a[i]].append(b[i])
        matrix[b[i]].append(a[i])
    
    visited = [0]*(N+1)

    from collections import deque
    queue = deque()
    visited[1]=1
    answer = K
    num = K-1
    for node in matrix[1]:
        answer *= num
        answer %= MOD

        num -= 1
        queue.append(node)

    while queue:
        q = queue.popleft()
        if visited[q] != 0:
            continue
        visited[q] = 1

        num = K-2
        for child_node in matrix[q]:
            if visited[child_node] == 0:
                answer *= num
                answer %= MOD
                num -= 1
                queue.append(child_node)
        answer %= MOD

    print(answer%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, K, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 25396
#include <bits/stdc++.h>
#include <algorithm>
#include <set>
using namespace std;
int main(){
	int N; cin >> N; long long int A[100010] = {}; 
	long long int B[100010] = {}; 
	for(int i = 0; i <= N; i++) cin >> A[i]; 
	for(int i = 0; i < N; i++) cin >> B[i]; 
	long long int L[100010] = {};  
	long long int R[100010] = {}; 
	L[0] = min(A[0], B[0]); 
	R[0] = min(A[1], max(B[0] - L[0], 0LL)); 
	for(int i = 1; i < N; i++){
		L[i] = min(max(A[i] - R[i-1], 0LL), B[i]); 
		R[i] = min(max(B[i] - L[i], 0LL), A[i+1]); 
	}
	long long int ans = 0; 
	for(int i = 0; i <= N; i++){
		ans += L[i]; ans += R[i]; 
	}
	cout << ans << endl; 
}

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


Measured memory_bytes: 4404
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define double long double
using namespace std;
typedef pair<int, int>P;
void pyes() { cout << "Yay!" << endl; }
void pno() { cout << ":(" << endl; }
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
//繰り返し二乗法
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
//xCy
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int f(int x) {
	int ans = 1;
	for (int i = 1; i <= x; i++) {
		ans *= i;
		ans %= mod;
	}
	return ans;
}
struct edge { int to, cost; };
int k[10], q[10];
int m[10];
int memo[114514];
signed main() {
	int n, p = 0, ans = 0;
	string s;
	cin >> n >> s;
	for (int i = n - 1; i >= 1; i--) {
		m[s[i] - '0']++;
		for (int j = 0; j <= 9; j++) {
			if (m[j])p++;
		}
		memo[i - 1] = p;
		p = 0;
	}
	for (int i = 0; i < n - 2; i++) {
		fill(k, k + 10, 0);
		if (q[s[i] - '0'] == 0) {
			for (int j = i + 1; j < n; j++) {
				if (k[s[j] - '0'] == 0) {
					ans += memo[j];
					k[s[j] - '0'] = 1;
				}
			}
			q[s[i] - '0'] = 1;
		}
	}
	cout << ans << endl;
	ggr
}


Measured memory_bytes: 512
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

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

    map<int, int> pre, suf;
    rep(i, n) { ++suf[-a[i] + i]; }

    ll ans = 0;
    rep(i, n) {
        --suf[-a[i] + i];
        ans += pre[a[i] - i] + suf[a[i] + i];
        ++pre[-a[i] - i];
    }
    cout << ans / 2 << "\n";
    return 0;
}


Measured memory_bytes: 38028
#include <stdio.h>

int main(void)
{
    int N, d[100];
    int i, j, tmp, ans;
    scanf("%d", &N);
    for (i=0; i<N; i++)
    {
        scanf("%d", &d[i]);
    }
    for (i=N-2; i>=0; i--)
    {
        for(j=0; j<=i; j++)
        {
            if (d[j]>d[j+1]) {
                tmp = d[j+1];
                d[j+1] = d[j];
                d[j] = tmp;
            }
        }
    }
    ans = 1;
    for (i=0; i<N-1; i++)
    {
        if (d[i] != d[i+1]) {
            ans ++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
m,d = map(int,input().split())
ans = 0
for i in range(1,m+1):
    for j in range(10,d+1):
        k = str(j)
        if int(k[0]) >= 2 and int(k[1]) >= 2:
            if i == int(k[0])*int(k[1]):
                ans += 1
print(ans)

Measured memory_bytes: 3060
input();a,b=[set(map(int,input().split()))for j in[0]*2];c=1;N=M=0;x=max(a)
for k in range(x,0,-1):
 A=k in a;B=k in b
 if A and B:M+=1;N+=1
 elif A:c*=M;N+=1
 elif B:c*=N;M+=1
 else:c*=M*N-x+k
 c%=10**9+7
print(c)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

bool is_valid(ll price, vll d) {
    str s = to_string(price);
    UNIQ(s);
    for(auto &c:s) {
        ll f = c - '0';
        for(auto &e:d) {
            if(f == e) {
                return false;
            }
        }
    }
    return true;
}

void solve() {
    ll N,K;
    cin >> N >> K;
    vll D(K);
            
    for(auto &a:D) {
        cin >> a;
    }
    for (ll ans = N; ans <= 10 * N; ans++)
    {
        if(is_valid(ans, D)) {
            cout << ans << endl;
            return;
        }
    }
    
}

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


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int main() {
    int n, m;
    double a[100];
    cin >> n >> m;
    double sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a + n, greater<double>());

    for (int i = 0; i < m; ++i) {
        if (a[i] < sum / (4 * m)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
main = readAndDo

readAndDo = do
  line <- getLine
  if line == "0 0" then return ()
  else do
    let [a, b] = input line
    solve [0..a-1] b
    putStrLn ""
    readAndDo

-- 入力
input :: String -> [Int]
input = (map read) . words

-- 解答
solve [] b = return ()
solve (a:xs) b = do
  putStrLn $ foldr (++) "" $ map (flip a) $ [0..b-1]
  solve xs b
  where
    flip y x | y `mod` 2 == 0 && x `mod` 2 == 0 = "#"
             | y `mod` 2 == 0 && x `mod` 2 == 1 = "."
             | y `mod` 2 == 1 && x `mod` 2 == 0 = "."
             | y `mod` 2 == 1 && x `mod` 2 == 1 = "#"




Measured memory_bytes: 4160
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        System.out.println(Math.min(A, B) + " " + Math.max(0, A + B - N));
    }
}


Measured memory_bytes: 22612
//一次元リバーシ

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    string s;cin>>s;
    int n = s.size();
    s.pb(s[n-1]);
    int ans = 0;
    char a = s[0];
    rep(i,0,n){
        if(a!=s[i]){
            ans++;
            a=s[i];
        }
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main () {
	string s;
	int ans=0, mx=0; 
	cin >> s;
	for(int i=0; i<s.size(); i++){
	    if(i==s.size()-1 and (s[i]=='A' or s[i]=='C' or s[i]=='G' or s[i]=='T')){
	    	ans++;
	    	mx=max(ans, mx);
		}
		if(s[i]=='A' or s[i]=='C' or s[i]=='G' or s[i]=='T'){
					ans++;		
		}
		else{
			mx=max(ans, mx);
		     ans=0; 
		}
	}
	cout<<mx;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int ans = 0;
      	for(int i=1;i<4;i++){
          ans += Math.pow(n,i);
        }
      System.out.println(ans);	
	}
}

Measured memory_bytes: 26992
#include<stdio.h>
#include<stdlib.h>
#define MAX 100001

main()
{
  short *A, change, x;
  int i, j, r, n, p=0, kakko;

  scanf("%d", &n);
  A = malloc(sizeof(short)*n + 1);

  for(i=0; i<n; i++)
    {
      scanf("%hu", &A[i]);
    }

  r = i-1;
  x = A[r];
  i = p - 1;
  for(j=p; j<r; j++)
    {
      if(A[j] <= x)
	{
	  i = i + 1;
	  change = A[j];
	  A[j] = A[i];
	  A[i] = change;
	}
    }
  change = A[r];
  A[r] = A[i+1];
  A[i+1] = change;
  kakko = i+1;

  for(i=0; i<n; i++)
    {
      if(i == kakko)
	{
	  printf("[%d] ", A[i]);
	  continue;
	}

      printf("%d", A[i]);
      if(i != n-1)
	{
	  printf(" ");
	}
    }
  printf("\n");

  return 0;
}

Measured memory_bytes: 804
list_ = sorted(list(map(int,input().split())))

A,B,C = list_[0],list_[1],list_[2]

ans = 0
while A < B:
  A += 2
  ans += 1
if B < A:
  B += 1
  C += 1
  ans += 1
while B < C:
  B += 1
  ans += 1
  
print(ans)

Measured memory_bytes: 3064
fn get_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().to_string()
}

fn reads<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().split(' ').map(|x| x.parse().unwrap()).collect()
}

fn readln<T>() -> T
    where
        T: std::str::FromStr,
        <T as std::str::FromStr>::Err: std::fmt::Debug {
    get_line().parse().unwrap()
}

fn main() {
    let n = readln();

    let mut xs:Vec<i64> = reads();
    xs.reverse();

    let mut res = vec![0; n];

    let mut flag = true;
    let mut i = 0;
    for c in xs.into_iter() {
        if flag {
            res[i] = c;
        }
        else {
            res[n - i - 1] = c;
            i += 1;
        }
        flag = !flag;
    }

    for (i, c) in res.into_iter().enumerate() {
        if i == n - 1 {
            println!("{}", c);
        }
        else {
            print!("{} ", c);
        }
    }
}


Measured memory_bytes: 9204
#include <cstdio>
long long dp[305][305][305], MOD;
int main()
{
	// freopen("AGC024-E.in", "r", stdin); 
	int n, k;
	scanf("%d%d%lld", &n, &k, &MOD); 
	dp[0][0][0] = 1; 
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j < k; j++)
		{
			for (int x = i; x >= 0; x--)
			{
				if (x)
					(dp[i][j][x - 1] += dp[i][j][x]) %= MOD; 
				else
					(dp[i][j + 1][i] += dp[i][j][x]) %= MOD;
				(dp[i + 1][j][x] += dp[i][j][x] * (x + 1)) %= MOD; 
			}
		}
	}
	printf("%lld\n", dp[n][k][n]);
	return 0; 
}


Measured memory_bytes: 221312
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

int main(){
    int c[10];
    for(int i=0;i<9;++i) std::cin>>c[i];

    int z1=c[0]-c[6];
    int z2=c[1]-c[7];
    int z3=c[2]-c[8];

    if(!(z1==z2&&z2==z3)){
        std::cout<<"No"<<std::endl;
        return 0;
    }

    for(int i=0;i<=100;++i){
        for(int j=0;j<=100;++j){
            if(i-j==z1){
                int b1=c[0]-i;
                int b2=c[1]-i;
                int b3=c[2]-i;
                int a2=c[3]-b1;
                if(b1>=0&&b1<=100&&b2>=0&&b2<=100&&b3>=0&&b3<=100&&a2>=0&&a2<=100&&a2+b1==c[3]&&a2+b2==c[4]&&a2+b3==c[5]
                &&i+b1==c[0]&&i+b2==c[1]&&i+b3==c[2]&&j+b1==c[6]&&j+b2==c[7]&&j+b3==c[8]){
                    std::cout<<"Yes"<<std::endl;
                    return 0;
                }
            }

        }

    }
    std::cout<<"No"<<std::endl;
}

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



int main() {
	

	long long N,K,temp,x;
	cin >> N>>K;
	
	for (int i = 0; true; i++)
	{

		x = 1;

		if (N > K)
		{
			x = N / K;
		}

		temp = abs(N - x*K);
		if (N >= temp)
		{
			N = temp;
		}
		else
			break;
		
	}


	
	cout << N << endl;


	return 0;
}




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

int n,k,x,y;
string s,t;

int main() {
  cin >> n;
  cout << (n&1 ? n/2 : n/2-1) << endl;
}

Measured memory_bytes: 256