akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int h,w; cin>>h>>w;
    vector<string> s;
    int hh=h;
    rep(i,h){
        string ss; cin>>ss;
        bool flg=1;
        for(char c:ss){
            if(c=='#') flg=0;
        }
        if(flg){
            hh--;
        }else{
            s.push_back(ss);
        }
    }
    vector<int> wnum;
    rep(i,w){
        bool flg=1;
        rep(j,hh){
            if(s[j][i]=='#') flg=0;
        }
        if(!flg){
            wnum.push_back(i);
        }
    }
    rep(i,hh){
        for(auto j:wnum){
            cout<<s[i][j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
h, w, m = map(int, input().split())
hw = set()
hh = [0]*h
ww = [0]*w
for _ in range(m):
    h, w = map(int, input().split())
    h-=1
    w-=1
    hw.add(h*10**6+w)
    hh[h] += 1
    ww[w] += 1
mxh = max(hh)
mxw = max(ww)
mh = [i for i, j in enumerate(hh) if j==mxh]
mw = [i for i, j in enumerate(ww) if j==mxw]
for i in mh:
    for j in mw:
        if i*10**6+j not in hw:
            print(mxh+mxw)
            exit(0)
print(mxh+mxw-1)

Measured memory_bytes: 169192
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007


constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 

 
int main() {
    int N,M;
    cin >>N>>M;

    int count=0;
    int now =-1;
    pair<int,int>A[M];

    FOR(i,0,M-1){
        cin>>A[i].second>>A[i].first;
    }
    sort(A, A+M);



    FOR(i,0,M-1){
        if(now<A[i].second){
            count++;
            now=A[i].first-1;
        }
    }
    cout<<count<<endl;
  return 0;
}


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

int main() {
  int N, D; cin >> N >> D;
  int X[N], Y[N]; for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];
  int c = 0;
  for (int i = 0; i < N; i++) {
    c += ((long)X[i] * X[i] + (long)Y[i] * Y[i] <= (long)D * D);
  }
  cout << c << endl;
}

Measured memory_bytes: 5184
#include<bits/stdc++.h>
using namespace std;
#define  ll  long long
const int N=2e5+3;
ll a[N],b[N],c[N];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll i,j,n,m,l,r,s=0;
    cin>>n;
    for(i=0; i<n; i++){
        cin>>b[i];
        a[b[i]]++;
    }
    for(i=1; i<=n; i++){
        l=a[i];
        l=(l*(l-1))/2;
        r=a[i]-1;
        r=(r*(r-1))/2;
        s+=l;
        c[i]=r-l;
    }
    for(i=0; i<n; i++){
        cout<<(s+c[b[i]])<<"\n";
    }
    return 0;
}

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

int N, K;
vector<int> A;

bool valid(int x)
{
    int cnt = 0;
    for (int i = 0; i < N; i++)
    {
        cnt += (A.at(i) - 1) / x;
        if (cnt > K)
            return false;
    }
    return true;
}

void solve()
{
    int l = 0, r = 1e9;
    while (l + 1 < r)
    {
        int m = (l + r) / 2;
        if (valid(m))
            r = m;
        else
            l = m;
    }
    cout << r << endl;
}

int main()
{
    cin >> N >> K;
    A = vector<int>(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    solve();
    return 0;
}


Measured memory_bytes: 3944
using System;
using System.Collections.Generic;
using System.Linq;
 
class Btest {
    static void Main(string[] args) {
        int abc = int.Parse(System.Console.ReadLine());
        int[] aList = Console.ReadLine().Trim().Split(' ').Select(a => int.Parse(a)).ToArray();
        bool rtn = true;
        for (int i = 0; i < abc; i++){
            if (aList[i] % 2 == 0) {
                if (aList[i] % 3 != 0 && aList[i] % 5 != 0) {
                    rtn = false;
                }
            }
        }
        if (rtn) {
            System.Console.WriteLine("APPROVED");
        } else {
            System.Console.WriteLine("DENIED");
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>

using namespace std;

#define ISEQUAL(i,a,b,c) Data[a][i] == Data[b][i] && Data[b][i] == Data[c][i] && Data[a][i] != 0

int main(){
	int RowNum = 0;//行数
	int* Data[5];//数値データ[列][行]
	int Points = 0;//ポイント
	bool IsComprete = false;//ルーチン終了判定用
	bool Checker[5] = { false };//行ごと消去判定用
	bool IsFall = true;//落下判定
	int FirstZeroPos = 0;//落下判定時ゼロ位置保持用

	while(1){
		cin >> RowNum;
		if (RowNum == 0)break;
		//データ代入
		for (int i = 0; i < 5; ++i){
			Data[i] = new int[RowNum];
		}
		for (int i = 0; i < RowNum; ++i){
			for (int j = 0; j < 5; ++j){
				cin >> Data[j][i];
			}
		}

		Points = 0;
		IsComprete = false;

		//ゲームルーチン
		while (!IsComprete){
			IsComprete = true;
			for (int i = 0; i < RowNum; ++i){//上から行ごとに
				for (int j = 0; j < 5; ++j){//判定用変数初期化
					Checker[j] = false;
				}
				for (int j = 0; j < 3; ++j){//消滅判定
					if (ISEQUAL(i, j, j + 1, j + 2)){
						Checker[j] = true; Checker[j + 1] = true;
						Checker[j + 2] = true;
						IsComprete = false;//消滅判定時未終了と判断
					}
				}
				for (int j = 0; j < 5; ++j){//消滅処理
					if (Checker[j]){
						Points += Data[j][i];
						Data[j][i] = 0;
					}
				}
			}
			//落下処理
			for (int j = 0; j < 5; ++j){//列ごとに
				IsFall = true;
				while (IsFall){
					FirstZeroPos = -1; IsFall = false;
					for (int i = RowNum - 1; i >= 0; --i){//下から
						if (FirstZeroPos == -1){
							if (Data[j][i] == 0)FirstZeroPos = i;
						} else {
							if (Data[j][i] != 0){
								Data[j][FirstZeroPos] = Data[j][i];
								Data[j][i] = 0;
								IsFall = true;
								break;
							}
						}
					}
				}
			}
		}

		cout << Points << endl;

		for (int i = 0; i < 5; ++i){
			delete[] Data[i];
		}

	}
	return 0;
}

Measured memory_bytes: 1196
N = int(input())
S = input()
assert len(S) == N

wr = [0] * (N+1)
bl = [0] * (N+1)

def solve():
    bc = 0
    for i in range(N):
        bl[i] = bc
        if S[i] == '#':
            bc += 1
    bl[N] = bc
    wc = 0
    for i in range(N-1, -1, -1):
        if S[i] == '.':
            wc += 1
        wr[i] = wc
    wr[N] = 0
    minval = N + 100
    mini = None
    for i in range(N+1):
        cost = bl[i] + wr[i]
        if minval > cost:
            minval = cost
            mini = i
    return minval

print(solve())

Measured memory_bytes: 43616
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[100001],f[100001],d[100001],ans=1,t=0;
int main() {
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=n;++i)
		scanf("%d",&a[i]);
    ans=1;
    t=0;
    for(i=1;i<=n;i++) {
        f[i]=1;
        for(j=t;j>0;j--)
            if(a[i]<=a[d[j]]) {
                f[i]=f[d[j]]+1;
                break;
            }
        t=max(t,f[i]);
        d[f[i]]=i;
        ans=max(ans,f[i]);
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1408
S=input()
T=input()
tmp_str=[]
flag=False
for i in range(len(S)-1):
    if S==T:
        flag=True
        break;
    
    tmp=list(S)
    tmp_char=tmp.pop()
    tmp.insert(0,tmp_char)
    
    S=''.join(tmp)
    if S==T:
        flag=True
        break;

if flag:
    print('Yes')
else:
    print('No')
    


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

int main(){

    int N;
    cin >> N;
    vector<int64_t> P(N);
    for (int i = 0; i < N; i++) {
        cin >> P.at(i);
    }

    int64_t cnt = 1;
    int minV = P.at(0);

    for(int i=1; i < N; i++) {
        if(P.at(i) > minV){
            continue;
        }
        minV = P.at(i);
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1792
/*
 *  author : Atul Anand   
 *  created on : Wed Apr 01 2020
 */

import java.io.*;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int H = in.nextInt();
        int A = in.nextInt();
        println((int) Math.ceil((H * 1.0)/A));
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static void read(int arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextInt(); 
    	} 
    }
    
    static void read(long arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.nextLong(); 
    	} 
    }
    
    static void read(String arr[], int N) throws IOException { 
    	for(int i = 0; i < N; i++){ 
    		arr[i] = in.next(); 
    	} 
    }
    
    static void print(Object O) {  
    	out.print(O); 
    }
    
    static void println(Object O) { 
    	out.println(O); 
    }
    
    static void println(int arr[]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		print(arr[i]+" "); 
    	} 
    	println(""); 
    }

    static void println(int arr[][]) { 
    	for(int i = 0; i < arr.length; i++){ 
    		println(arr[i]); 
    	}
    }
    
    static void debug(Object O) { 
    	System.out.println(O); 
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 20692
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　RedcoderになるためAtCoderを巡る旅をしてます。

　　　 　＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　   ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

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

    string s;
    cin >> s;
    string ele[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    int ans = 0;
    rep(i, 7) {
        if(ele[i] == s) ans = 7 - i;
    }
    COUT(ans);
}


Measured memory_bytes: 256
module Main where
import qualified Data.Set as S

main :: IO ()
main = do
    n <- fmap read getLine :: IO Int
    a <- getLine
    b <- getLine
    c <- getLine
    let ans = sum $ zipWith3 f a b c
        f x y z = d - 1
            where
            d = S.size $ S.fromList [x,y,z]
    print ans


Measured memory_bytes: 508
#include <iostream>
#include <cstdio>

constexpr int MAX_SIZE = 250 + 1;
int heap[MAX_SIZE];

int parent(int i) {return i / 2;}
int left(int i) {return 2 * i;}
int right(int i) {return 2 * i + 1;}

int main() {
    int n;
    std::cin >> n;
    for (int i = 1; i <= n; i++) {
        std::cin >> heap[i];
    }

    for(int i = 1; i <= n; i++) {
        std::printf("node %d: key = %d, ", i, heap[i]);
        if (parent(i) > 0) std::printf("parent key = %d, ", heap[parent(i)]);
        if (left(i) <= n) std::printf("left key = %d, ", heap[left(i)]);
        if (right(i) <= n) std::printf("right key = %d, ", heap[right(i)]);
        std::cout << std::endl;
    }


}


Measured memory_bytes: 3228
from collections import defaultdict

n, m = map(int, input().split())
a = list(map(int, input().split()))

a_cs = [0] * (n+1)
for i in range(n):
    a_cs[i+1] = (a_cs[i] + a[i]) % m

d = defaultdict(int)
for i in range(1, n+1):
    d[a_cs[i]] += 1

ans = 0
for k, v in d.items():
    if k == 0:
        ans += v * (v+1) // 2
    else:
        if d[k] > 1:
            ans += (v-1) * v // 2

print(ans)


Measured memory_bytes: 16524
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import itertools
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def warshall_floyd(n):
    for i in range(n):  # 経由する頂点
        for j in range(n):  # 開始頂点
            for k in range(n):  # 終端
                graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k])


N, M, R = MI()
r = LI()
road = [LI() for _ in range(M)]
graph = [[INF] * N for _ in range(N)]
# pprint(graph, width=30)

for a, b, c in road:
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c
for i in range(N):
    graph[i][i] = 0

# pprint(graph, width=30)
warshall_floyd(N)
# pprint(graph, width=30)

# for i in range(N):
#     for j in range(N):
#         if i != j and graph[i][j] != INF:
#             # i == jの場合は始点と終点が同じ
#             # INFはそもそも繋がっていない
#             print(str(i+1)+' ~ '+str(j+1)+' ===== '+str(graph[i][j]))

ans = INF 
for permutation in itertools.permutations(r):
    # print(permutation)
    tmp = 0
    for i in range(R-1):
        tmp += graph[permutation[i]-1][permutation[i+1]-1]
    ans = min(ans, tmp)
print(ans)


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

pair<int, int>v0_counts[100010];
pair<int, int>v1_counts[100010];

int main() {
	int n;
	cin >> n;
	int v;
	vector<int> v0, v1;
	for (int i = 0; i < n; i++) {
		cin >> v;
		if (i % 2 == 0) {
			v0.push_back(v);
		}
		else {
			v1.push_back(v);
		}
	}
	int v0_index = 0;
	sort(v0.begin(), v0.end());
	sort(v1.begin(), v1.end());
	int count = 1;

	for (int i = 1; i < v0.size(); i++) {
		if (v0[i] == v0[i - 1]) {
			count++;
		}
		else {
			v0_counts[v0_index].first = count;
			v0_counts[v0_index].second = v0[i - 1];
			count = 1;
			v0_index++;
		}
		if (i == v0.size() - 1) {
			v0_counts[v0_index].first = count;
			v0_counts[v0_index].second = v0[i];
			count = 1;
		}
	}
	int v1_index = 0; 
	for (int i = 1; i < v1.size(); i++) {
		if (v1[i] == v1[i - 1]) {
			count++;
		}
		else {
			v1_counts[v1_index].first = count;
			v1_counts[v1_index].second = v1[i - 1];
			count = 1;
			v1_index++;
		}
		if (i == v1.size() - 1) {
			v1_counts[v1_index].first = count;
			v1_counts[v1_index].second = v1[i];
			count = 1;
		}
	}
	sort(v0_counts, v0_counts + v0_index + 1, greater<pair<int, int>>());
	sort(v1_counts, v1_counts + v1_index + 1, greater<pair<int, int>>());
	int minus;
	if (v1_counts[0].second != v0_counts[0].second) {
		cout << v0.size() - v0_counts[0].first + v1.size() - v1_counts[0].first << endl;
	}
	else {
		if (v0_counts[1].first <= v1_counts[1].first) {
			minus = v1_counts[1].first + v0_counts[0].first;
		}
		else{
			minus = v1_counts[0].first + v0_counts[1].first;
		}
		cout << v0.size() + v1.size() - minus << endl;
	}
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <limits>
#include <algorithm>

int main()
{
    int n, min_times{std::numeric_limits<int>::max()};
    std::cin >> n;
    for (auto i = 0; i < n; ++i)
    {
        int a;
        std::cin >> a;
        int times{};
        while (a % 2 == 0 && (a /= 2) > 0)
            ++times;
        min_times = std::min(times, min_times);
    }
    std::cout << min_times << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main()
{
  int x,y,z;
  string str;
  stack<int> a;
  while(cin >> str){
    if(str == "+"){
      x = a.top();
      a.pop();
      y = a.top();
      a.pop();
      z = x + y;
      a.push(z);
    }
    else if(str == "-"){
      x = a.top();
      a.pop();
      y = a.top();
      a.pop();
      z = y - x;
      a.push(z);
    }
    else if(str =="*"){
      x = a.top();
      a.pop();
      y = a.top();
      a.pop();
      z = x * y;
      a.push(z);
    }
    else{
      a.push(stoi(str));
    }
  }
  cout << a.top() << endl;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;
template<class T> inline bool chmax(T& a,T b)
{if (a < b) {a = b; return true;} return false;}
template<class T> inline bool chmin(T& a,T b)
{if (a > b) {a = b; return true;} return false;}
const long long INF = 1e12;

vector<long long> dijkstra(const Graph &G, int s){
    using Pi = pair<long long, int>;
// 最終的に最短経路を保持する配列, INFで初期化
    vector<long long> dist(G.size(), INF); 
// そこまでの距離, 頂点を保持する優先度付きキュー
    priority_queue<Pi, vector<Pi>, greater<Pi>> que;
    dist[s] = 0; que.emplace(dist[s], s);
// キューが空になるまで(max V 回)
    while(!que.empty()){
        long long sum_dist; int node;
// キューから取り出された時点で頂点が確定
        tie(sum_dist, node) = que.top(); que.pop();
// それより短い経路が分かっているときはcontinue(枝刈り)
        if (dist[node] < sum_dist) continue;
// 確定した頂点から到達できる頂点を探索
        for (auto &e : G[node]) {
            int next_node; long long dis;
            tie(next_node, dis) = e;
// 最短距離が更新されたときだけキューに追加
            if (chmin(dist[next_node], dist[node] + dis)) {
                que.emplace(dist[next_node], next_node);
            }
        }
    }
    return dist;
}

int main(){
    int N, K, Case;
    Graph G;
    vector<vector<long long>> dist;
    while(true){
        cin >> N >> K; if(N == 0 && K == 0)break;
        
        G.assign(N, vector<edge>());
        dist.assign(N, vector<long long>(N, INF));
        
        for (int i = 0; i < K; i++) {
            cin >> Case;
            if (Case == 0) {
                int s, g; cin >> s >> g; s--; g--;
                dist[s] = dijkstra(G, s);
                long long ans = dist[s][g];
                if (ans == INF) ans = -1;
                cout << ans << endl;
            } else {
                int a, b; long long c;
                cin >> a >> b >> c; a--; b--;
                G[a].push_back(make_pair(b, c));
                G[b].push_back(make_pair(a, c));
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3208
#!/usr/bin/env ruby
n = gets.chomp.to_i
s = gets.chomp

hash = Hash.new(0)
hash['R'] = 0
hash['G'] = 0
hash['B'] = 0

s.chars.each do |s_i|
  hash[s_i] += 1
end

ans = 0
1.upto(n - 2) do |i|
  (i + 1).upto(n - 1) do |j|
    k = 2 * j - i
    next if k > n
    if s[i - 1] != s[j - 1] && s[j - 1] != s[k - 1] && s[k - 1] != s[i - 1]
      ans += 1
    end
  end
end

puts hash['R'] * hash['G'] * hash['B'] - ans


Measured memory_bytes: 14544
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		int a = input.nextInt();
		int b = input.nextInt();
		
		if (a>b) {
			System.out.println("a > b");
		} else if ( a<b) {
			System.out.println("a < b");
		} else {
			System.out.println("a == b");
		}
		input.close();
	}

}

Measured memory_bytes: 26132
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int N,M;
int neighbor[50][50];
int ans=0;
int passed[50]={0};
void search(int x){
  passed[x]=1;
  for(int i=0;i<N;i++){
    if(neighbor[x][i]==1&&passed[i]==0) search(i);
  }
  return;
}
int main(){
  
  cin>>N>>M;
  vector<int> a(M),b(M);
  for(int i=0;i<M;i++){
    cin>>a[i]>>b[i];
    neighbor[a[i]-1][b[i]-1]=1;
    neighbor[b[i]-1][a[i]-1]=1;
  }

  for(int i=0;i<M;i++){
    neighbor[a[i]-1][b[i]-1]=0; neighbor[b[i]-1][a[i]-1]=0;
    for(int j=0;j<N;j++) passed[j]=0;
    search(0);
    int check=0;
    for(int j=0;j<N;j++){
      if(passed[j]==0){
        check=1; break;
      }
    }
    if(check==1) ans++;
    neighbor[a[i]-1][b[i]-1]=1; neighbor[b[i]-1][a[i]-1]=1;
  }

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

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    llint n, a, b;
    cin >> n >> a >> b;

    vector<int> x(n);
    for(int in=0;in<n;in++) {
        cin >> x.at(in);
    }

    vector<llint> teleport(n-1);
    llint telenum = 0;
    for(int in=0;in<n-1;in++) {
        if((x.at(in+1)-x.at(in))*a>b) {
            teleport.at(in) = 1;
            telenum++;
        }
    }

    llint ans = 0;
    for(int in=0;in<n-1;in++) {
        if(teleport.at(in)==1) continue;
        ans += a*(x.at(in+1) - x.at(in));
    }
    ans += b * telenum;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4560
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define INF 1<<30
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;



int main(){
    int64 n , k; cin >> n >> k;
    vector<int64> h(n);
    rep(i ,n) cin >> h[i];
    vector<int64> dp(n,INF);
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;++i){
        for(int j=1;j<=k;++j){
            if(i-j<0) break;
            dp[i]=min(dp[i-j]+abs(h[i-j]-h[i]),dp[i]);
        }
    }
    cout << dp[n-1] << endl;
}

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

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> c(n);
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++)cin >> a[i][j];
    }
    int ans = 12345678;
    int all = 1<<n;
    for(int mask = 0; mask < all; mask++){
        vector<int> level(m);
        int cost = 0;
        for(int i = 0; i < n; i++){
            if((mask>>i)&1){
                cost += c[i];
                for(int j = 0; j < m; j++){
                    level[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for(int j = 0; j < m; j++){
            if(level[j] < x) ok = false;
        }
        if(ok) ans = min(ans,cost);
    }
    if(ans == 12345678) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main(){
    string s;
    cin >> s;
    
    int count = 0;
    int tmp = 0;
    for(int i = 0; i < s.size(); i++){
        if(i%2 == 0){
            if(s[i] == '0'){
                count++;
            }
        }else{
            if(s[i] == '1'){
                count++;
            }
        }
    }
    
    for(int i = 0; i < s.size(); i++){
        if(i%2 == 0){
            if(s[i] == '1'){
                tmp++;
            }
        }else{
            if(s[i] == '0'){
                tmp++;
            }
        }
    }
    
    cout << min(count, tmp) << endl;
}


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

H, N = list(map(int, input().split()))

AB = [tuple(list(map(int, input().split()))) for _ in range(N)]

DP = [1 << 32-1] * (H+10**4 + 10**4)
DP[0] = 0

for i in range(H+10**4):
    for a, b in AB:
        DP[i + a] = min(DP[i+a], DP[i] + b)

print(min(DP[H:]))


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

int main(){
    vector<int> a(3);
    int i,go,shiti;
    cin >> a.at(0) >> a.at(1) >> a.at(2);
    go = 0;
    shiti = 0;
    for(i=0;i<3;i++){
        if(a.at(i) == 5){
            go++;
        }
        else if(a.at(i) == 7){
            shiti++;
        }
    }

    if((go == 2)&&(shiti == 1)){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" <<endl;
    }

    return 0;
}

Measured memory_bytes: 256
var nodeList = Array<Treee?>(100000) { null }

fun main(args: Array<String>) {

    val nodeCount = readLine()!!.toLong()

    for (i in 1..nodeCount) {

        var inputs = readLine()!!.split(" ")
        val left = inputs[1].toInt()
        val right = inputs[2].toInt()
        val id = inputs[0].toInt()

        // 自身を作る
        if (nodeList[id] == null) {
            nodeList[id] = Treee(id, -1)
        }

        // 子供を記録
        if (left != -1) {
            val childLeftNode = nodeList[left] ?: Treee(left)
            childLeftNode.parent = id
            nodeList[left] = childLeftNode

            nodeList[id]!!.left = left
        }

        if (right != -1) {
            val childRightNode = nodeList[right] ?: Treee(right)
            childRightNode.parent = id
            nodeList[right] = childRightNode

            nodeList[id]!!.right = right
        }
    }

    val rootNode = nodeList.filter {
        it?.parent == -1
    }[0]!!


    println("Preorder")
    printByPreorder(rootNode.id)
    println()
    println("Inorder")
    printByInorder(rootNode.id)
    println()
    println("Postorder")
    printByPostorder(rootNode.id)
    println()

}


fun printByPreorder(index: Int) {

    print(" $index")

    if (nodeList[index]!!.left != -1) {
        printByPreorder(nodeList[index]!!.left)
    }


    if (nodeList[index]!!.right != -1) {
        printByPreorder(nodeList[index]!!.right)
    }
}


fun printByInorder(index: Int) {

    if (nodeList[index]!!.left != -1) {
        printByInorder(nodeList[index]!!.left)
    }

    print(" $index")

    if (nodeList[index]!!.right != -1) {
        printByInorder(nodeList[index]!!.right)
    }
}


fun printByPostorder(index: Int) {

    if (nodeList[index]!!.left != -1) {
        printByPostorder(nodeList[index]!!.left)
    }

    if (nodeList[index]!!.right != -1) {
        printByPostorder(nodeList[index]!!.right)
    }

    print(" $index")
}

class Treee(
    var id: Int,
    var parent: Int = -1,
    var left: Int = -1,
    var right: Int = -1,
    var depth: Int? = null,
    var height: Int? = null
) {

    fun print() {
        println("node $id: parent = $parent, sibling = ${getSibling()}, degree = ${getDegree()}, depth = $depth, height = $height, ${type()}")
    }

    fun type(): String {
        if (parent == -1) {
            return "root"
        }

        if (left == -1 && right == -1) {
            return "leaf"
        }

        return "internal node"
    }

    fun getSibling(): Int {
        if (parent == -1) {
            return -1
        }
        if (nodeList[parent]!!.right != id) {
            return nodeList[parent]!!.right
        }
        if (nodeList[parent]!!.left != id) {
            return nodeList[parent]!!.left
        }
        return -1
    }

    fun getDegree(): Int {
        var count = 0
        if (right != -1) {
            count++
        }
        if (left != -1) {
            count++
        }

        return count
    }
}



Measured memory_bytes: 32136
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(x => Number(x));
  const a = s[0];
  const b = s[1];
  const x = s[2];

  const ans = (a <= x && x <= (a + b)) ? 'YES' : 'NO';
  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:usize = read();
    let v:Vec<i32> = (0..n).map(|_| read()).collect();
    let c:Vec<i32> = (0..n).map(|_| read()).collect();

    let mut ans:i32 = 0;
    for i in 0..n {
        if v[i]-c[i] > 0 {ans+=v[i]-c[i]}
    }

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


Measured memory_bytes: 4352
let () = Scanf.scanf "%d %d" @@ fun a b ->
  Printf.printf "%d\n" @@
  try
    List.find (fun i -> 2 * i / 25 = a && i / 10 = b) @@
    Array.to_list @@
    Array.init 20000 @@ fun i -> i
  with Not_found -> -1

Measured memory_bytes: 4480
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <iomanip>
#include <functional>
//#pragma optimize GCC("O3")
typedef long long ll;
typedef long double ld;
using namespace std;

class query
{
public:
	int l, r, i;
};
bool cmp(const query &a, const query &b)
{
	return a.r < b.r;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, q;
	cin >> n >> q;
	vector<int> c(n);
	for (int i = 0; i < n; i++)
	{
		cin >> c[i];
		c[i]--;
	}
	vector<int> ans(q);
	int sqrtn = int(ceil(sqrt((ld)n))) + 7;
	vector<query> *b = new vector<query>[sqrtn];
	for (int i=0;i<q;i++)
	{
		query a;
		cin >> a.l >> a.r;
		a.l--;
		a.r--;
		a.i = i;
		b[a.l / sqrtn].push_back(a);
	}
	vector<int> f(n, 0);
	for (int i = 0; i < sqrtn; i++)
	{
		if (b[i].empty()) continue;
		sort(b[i].begin(), b[i].end(), cmp);
		int rc = 0;
		int minl = b[i][0].l;
		for (int j = b[i][0].l; j <= b[i][0].r; j++)
		{
			if (f[c[j]] == 0)
				rc++;
			f[c[j]]++;
		}
		int cl = b[i][0].l;
		int cr = b[i][0].r;
		for (int j = 0; j < b[i].size(); j++)
		{
			if (b[i][j].l < cl) // treba pridat par farieb
			{
				cl--;
				for (; cl >= b[i][j].l; cl--)
				{
					if (f[c[cl]] == 0)
						rc++;
					f[c[cl]]++;
				}
			}
			else
			{
				for (; cl < b[i][j].l; cl++)
				{
					f[c[cl]]--;
					if (f[c[cl]] == 0)
						rc--;
				}
			}
			cl = b[i][j].l;
			if (b[i][j].r > cr)
			{
				cr++;
				for (; cr <= b[i][j].r; cr++)
				{
					if (f[c[cr]] == 0)
						rc++;
					f[c[cr]]++;
				}
			}
			cr = b[i][j].r;
			ans[b[i][j].i] = rc;
			minl = min(cl, minl);
		}
		for (int j = minl; j <= b[i].back().r; j++)
			f[c[j]] = 0;
	}
	for (int i = 0; i < q; i++)
		cout << ans[i] << "\n";
	return 0;
}

Measured memory_bytes: 18552
N = int(input())
A = list(map(int,input().split()))

minval = 0
ans = 1000

for i in range(1, N):
  if A[i] > A[minval]:
    pstock = ans // A[minval]
    ans = ans%A[minval] + A[i]*pstock
  minval = i

print(ans)

Measured memory_bytes: 61696
s = input()
chk = [0, 0, 0, 0]
for c in s:
    if c == 'N':
        chk[0] += 1
    elif c == 'S':
        chk[1] += 1
    elif c == 'W':
        chk[2] += 1
    else:
        chk[3] += 1

if chk[0] > 0:
    if chk[1] == 0:
        print("No")
        exit()
if chk[1] > 0:
    if chk[0] == 0:
        print("No")
        exit()
if chk[2] > 0:
    if chk[3] == 0:
        print("No")
        exit()
if chk[3] > 0:
    if chk[2] == 0:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N = iin()

edges = [[] for _ in range(N)]

for _ in range(N-1):
    u,v,w = imn()
    u -= 1
    v -= 1
    edges[u].append((v,w))
    edges[v].append((u,w))

colors = [None] * (N)

def set_color(vertex, color):
    colors[vertex] = color
    for v, w in edges[vertex]:
        if colors[v] == None:
            next_color = color
            if w % 2 == 1:
                next_color = (next_color+1)%2
            set_color(v, next_color)
set_color(0, 0)

for c in colors:
    print(c)


Measured memory_bytes: 81392
#include<stdio.h>

int main()
{
    int x,y;

    while(1) {
      scanf("%d %d", &x, &y);
      if(x==0 && y==0)  break;
      if(x>y) printf("%d %d\n", y, x);
      else    printf("%d %d\n", x, y);
    }

    return 0;
}



Measured memory_bytes: 2104
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
//素因数
void func(int a,long int list[],int listnum[],int strt) {
	if(strt==0){}else{
		for (int m = strt; m <= a; m++) {
			if (a%m == 0) {
				list[listnum[0]] = m;
				listnum[0]++;
				func(a / m, list, listnum, m);
				break;
			}
		}
	}
	
}

int main(void) {
	long int x;
	long int y;
	scanf("%ld %ld", &x, &y);
	long int listX[100];	int listXnum[1] = { 0 };
	long int listY[100];	int listYnum[1] = { 0 };
	//素因数挽回
	func(x, listX, listXnum, 2);
	func(y, listY, listYnum, 2);
	long int ans = 1;
	for (int k = 0; k < listXnum[0]; k++) {
		for (int m = 0; m < listYnum[0]; m++) {
			if (listX[k] == listY[m]) {
				ans*=listX[k];
				listX[k] = 1;
				listY[m] = 1;

			}

		}

	}
	for (int k = 0; k < listXnum[0]; k++) {
		ans *= listX[k];

	}
	for (int m = 0; m < listYnum[0]; m++) {
		ans *= listY[m];
	}
	printf("%ld", ans);
}

Measured memory_bytes: 128
N = int(input())
SP = []
for i in range(1, N + 1):
    s, p = input().split()
    p = int(p)
    SP.append((s, p, i))

sorted_SP = sorted(SP, key=lambda x: (x[0], -x[1]))
for *i, j in sorted_SP:
    print(j)


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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string S,T;
    cin >> S >> T;
    int total=0;
    for(int i = 0; i<S.size(); ++i) if (S[i]!=T[i]) ++total;
    cout << total;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define int long long
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)
using namespace std;
const int N = 10010;
inline int read()
{
	register char cc = getchar(); register int cn(0), flus(1);
	while(cc < '0' || cc > '9') {if(cc == '-') flus = - flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - '0'; cc = getchar();}
	return cn * flus;
}
int n,h,a;
signed main()
{
	h = read(), n = read();
	while(n--)
	{
		a = read();
		h-=a;
	}
	if(h<=0)puts("Yes");
	else puts("No");
	return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define forup(i,a,b) for(int i=(a); i<(b); ++i)
#define fordn(i,a,b) for(int i=(a); i>(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)

#define gi(x) scanf("%d",&x)
#define gl(x) cin>>x
#define gd(x) scanf("%lf",&x)
#define gs(x) scanf(" %s",x)

#define D(x) cout << #x << " : " << x << endl

#define fs first
#define sc second

#define pb push_back
#define mp make_pair

const int inf=numeric_limits<int>::max();
const LL linf=numeric_limits<LL>::max();

const int max_n=100001;

int n, k, a[max_n], dp[max_n];

int main() {
    int mn;
    gl(n>>k);
    rep(i, n){
        gl(a[i]);
    }

    dp[n-1] = 0;
    dp[n-2] = abs(a[n-1]-a[n-2]);

    fordn(i, n-3, -1){
        mn = inf;
        forup(j,1,k+1){
            if(j+i == n) break;
            mn = min(abs(a[i+j]-a[i])+dp[i+j], mn);
        }
        dp[i] = mn;
    }

    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 1024
using System;

namespace Tenka_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().ToCharArray();
            if (a.Length==3)
            {
                Array.Reverse(a);
            }
            foreach (var s in a)
            {
                Console.Write(s);
            }
            Console.WriteLine();
        }
    }
}


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

const int mod = 1e9 + 7, N = 1e5 + 10;

ll pw(ll a, ll b) {
    ll r = 1;
    for( ; b ; b >>= 1, a = a * a % mod) {
        if(b & 1) {
            r = r * a % mod;
        }
    }
    return r;
}

ll getinv(ll n) {
    return pw(n, mod - 2);
}

int n;
ll x[N], y[N];
int fa[N];
int get(int x) { return x == fa[x] ? x : fa[x] = get(fa[x]); }
int sol(ll p, ll q) {
	if(p == 0 && q == 0) return n;
	for(int i = 1 ; i <= n ; ++ i) {
		fa[i] = i;
	}
	for(int i = 1 ; i <= n ; ++ i) {
		for(int j = 1 ; j <= n ; ++ j) {
			if(i != j && x[i] + p == x[j] && y[i] + q == y[j]) {
				fa[get(i)] = get(j);
			}
		}
	}
	int res = 0;
	for(int i = 1 ; i <= n ; ++ i) {
		if(get(i) == i) {
			++ res;
		}
	}
	return res;
}

int main() {
	scanf("%d", &n);
	for(int i = 1 ; i <= n ; ++ i) {
		scanf("%lld%lld", &x[i], &y[i]);
	}
	int ans = n;
	for(int i = 1 ; i <= n ; ++ i) {
		for(int j = 1 ; j <= n ; ++ j) {
			if(i != j) {
				ll p = x[i] - x[j];
				ll q = y[i] - y[j];
				ans = min(ans, sol(p, q));
			}
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>

using namespace std;

#define ABS(a) ((a>0)?a:-(a))
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a<b)?(b):(a))
#define FOR(i,a,n) for (int i=(a);i<(n);++i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define pnt pair <int, int>
#define mp make_pair
#define PI 3.1415926535897
#define MEMS(a,b) memset(a,b,sizeof(a))
#define LL long long
#define U unsigned

int minL[310][4];
int maxL[310][4];

int dp[301][301][301];
int n,m;

int mod = 1000000007;

int r(int p, int v1, int v2) {
	bool ok = true;
	if (p) {
		int p1 = (v1 == n) ? (-1) : v1;
		int p2 = (v2 == n) ? (-1) : v2;
		int p3 = p - 1;
		FOR(i, 0, 3) {
			if (minL[p - 1][i] == -1) {
				continue;
			}
			int cnt1 = (p1 >= minL[p - 1][i]);
			cnt1 += (p2 >= minL[p - 1][i]);
			cnt1 += (p3 >= minL[p - 1][i]);
			if (cnt1 != i + 1) {
				ok = false;
			}
			int cnt2 = (p1 >= maxL[p - 1][i]);
			cnt2 += (p2 >= maxL[p - 1][i]);
			cnt2 += (p3 >= maxL[p - 1][i]);
			if (cnt2 != i + 1) {
				ok = false;
			}
		}
	}
	if (!ok) {
		return 0;
	}
	if (p == n) {
		return 1;
	}
	if (dp[p][v1][v2] != -1) {
		return dp[p][v1][v2];
	}
	int res = r(p + 1, v1, v2);
	res += r(p + 1, p - 1, v2);
	if (res >= mod) {
		res -= mod;
	}
	res += r(p + 1, v1, p - 1);
	if (res >= mod) {
		res -= mod;
	}
	return dp[p][v1][v2] = res;
}

int main()
{
#ifdef Fcdkbear
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	double beg = clock();
#endif

	MEMS(dp, -1);
	MEMS(minL, -1);
	MEMS(maxL, -1);
	cin >> n >> m;
	FOR(i, 0, m) {
		int l, r, x;
		cin >> l >> r >> x;
		l--;
		r--;
		x--;
		if (minL[r][x] == -1) {
			minL[r][x] = l;
			maxL[r][x] = l;
		}
		else {
			minL[r][x] = min(minL[r][x],l);
			maxL[r][x] = max(maxL[r][x], l);
		}
	}
	LL res = r(1, n, n);
	res *= 3;
	res %= mod;
	cout << res << endl;

#ifdef Fcdkbear
	double end = clock();
	fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 106880
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std; 
const int N=100010;
ll n,num,m,x; 
ll a[N],f[N],s[N]; 
void solve(ll x,ll k){
	if (x<a[1]){
		s[x]+=k;
		return;
	}
	ll l=1,r=num,y;
	while (l<=r){
		ll mid=(l+r)/2;
		if (a[mid]<=x){
			y=mid;
			l=mid+1;
		}else r=mid-1;
	}
	f[y]+=k*(x/a[y]);
	x=x%a[y];
	if (x) solve(x,k);
}
int main(){
	scanf("%lld%lld",&n,&m);
	num=1;
	a[1]=n;
	for (ll i=1; i<=m; i++){
		scanf("%lld",&x);
		while (x<=a[num]&&num)
			--num;
		num++;
		a[num]=x;
	}
	f[num]=1;
	for (ll i=num-1; i>=1; i--){
		f[i]+=f[i+1]*(a[i+1]/a[i]);
		solve(a[i+1]%a[i],f[i+1]);
	}
	for (ll i=a[1]; i>=1; i--)
		s[i]+=s[i+1];
	for (ll i=1; i<=a[1]; i++)
		s[i]+=f[1];
	for (ll i=1; i<=n; i++)
		printf("%lld\n",s[i]);
	return 0;
}

Measured memory_bytes: 5500
def solve():
    r1, c1, r2, c2 = map(int, input().split())

    MOD = 10**9+7
    n = r2+c2+2
    fac = [1]*(n+1)
    rev = [1]*(n+1)
    
    for i in range(1,n+1):
      fac[i] = i*fac[i-1]%MOD
      rev[i] = pow(fac[i], MOD-2, MOD)
    
    comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD
    f = lambda r,c:comb(r+c+2, c+1)

    ans = (f(r2, c2)-f(r2, c1-1)-f(r1-1, c2)+f(r1-1, c1-1))%MOD
    print(ans)


if __name__ == "__main__":
    solve()


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

long long GCD(long long a, long long b){
  if (b == 0) return a;
  else return GCD(b, a % b);
}

ll num(ll n, ll c, ll d){
  ll L = c / GCD(c, d) * d;
  return n - (n / c + n / d - n / L);
}
  

int main(){
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll ans = num(B, C, D) - num(A-1, C, D); 
  cout << ans << endl;
}


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

int main() {
    int A , B , C , X ;
    cin >> A >> B >> C >> X ;
    
    //A枚の中からa枚使って払えるのかを考える
    int score=0 ;
    
    for( int a=0 ; a<=A ; a++ ){
        for( int b=0 ; b<=B ; b++ ){
            for( int c=0 ; c<=C ; c++ ){
                int sum = 500*a + 100*b + 50*c ;
                    
                    if( sum==X ){
                        score++ ;
                    }
            }
        }
    }
    
    cout << score << endl;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>  // pairはutilityヘッダにあり、mapヘッダから読み込まれる
using namespace std;

bool compare_by_b(pair<string, int> a, pair<string, int> b) {
    if(a.first == b.first){
        return a.second > b.second;
    }else{
        return a.first < b.first;
    }
}

int main() {
  int N;
  cin >> N;

  vector<string> shi(N),shi_copy(N);
  vector<int> ten(N),ten_copy(N);


  for(int i=0;i<N;i++){
    cin >> shi.at(i) >> ten.at(i);
  }

  for(int i=0;i<N;i++){
    shi_copy.at(i)=shi.at(i);
    ten_copy.at(i)=ten.at(i);    
  }

  vector<pair<string,int>> pairs(N),pairs_copy(N);

  for (int i = 0; i < N; i++) {
    pairs.at(i) = make_pair(shi_copy.at(i), ten_copy.at(i));
    pairs_copy.at(i) = make_pair(shi_copy.at(i), ten_copy.at(i));
  }

   sort(pairs.begin(), pairs.end(),compare_by_b);

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(pairs.at(i)==pairs_copy.at(j)){
              cout << j+1 << endl;
      break;
      }
    }
  }



  /*for(int i=0;i<N;i++){
    cout << shi.at(i) << ten.at(i) << endl;
  }*/




}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(ll)(n);i++)
typedef pair<int,long long> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int n;cin>>n;
  int m;cin>>m;
  int a[n];
  rep(i,n)a[i]=0;
  rep(i,m){
    int x,y;cin>>x>>y;
    x--;y--;
    if(x==0)a[y]++;
    if(y==n-1)a[x]++;
    }
  rep(i,n){
    if(a[i]==2){
      cout<<"POSSIBLE"<<endl;
      return 0;
      }
    }
  cout<<"IMPOSSIBLE"<<endl;
  return 0;
  }

Measured memory_bytes: 1024
import java.util.*;
public class Main{
  static Scanner sc = new Scanner(System.in);
  static char[][] map;
  static int[] dx = {0, -1, 0, 1}, dy = {1, 0, -1, 0};
  static int bombed_x, bombed_y;

  public static void main(String [] args){
    int loop = sc.nextInt();
    for(int i = 0;i < loop;i++){
      solve(i+1);
    }
  }

  static void solve(int index){
    readMap();
    int bomb_x = sc.nextInt() -1;
    int bomb_y = sc.nextInt() -1;
    dfs(bomb_x, bomb_y);
    System.out.println("Data " + String.valueOf(index) + ":");
    for(char[] ans_row: map){
      System.out.println(String.valueOf(ans_row));
    }
    return;
  }

  static void readMap(){
    map = new char[8][8];
    for(int i = 0; i < 8;i++){
      map[i] = sc.next().toCharArray();
    }
    return;
  }
static void dfs(int bomb_x, int bomb_y){
    map[bomb_y][bomb_x] = '0';
    for(int i = 0; i < 4;i++){
      for(int j = 1; j <= 3;j++){
        bombed_x = bomb_x + dx[i] * j;
        bombed_y = bomb_y + dy[i] * j;
        if(0 > bombed_x || bombed_x > 7 || 0 > bombed_y || bombed_y > 7)break;
        if(map[bombed_y][bombed_x] == '1'){
          dfs(bombed_x, bombed_y);
        }
      }
    }
    return;
  }
}

Measured memory_bytes: 17208
n=int(input())
w=list(map(int,input().split()))
ruiwa=[]
ruiwa.append(w[0])
sa=[]
for i in range(1,n):
  ruiwa.append(ruiwa[i-1]+w[i])
for i in range(n-1):
  sa.append(abs(ruiwa[n-1]-2*ruiwa[i]))

print(min(sa))

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

	public static void main(String[] args) {
	Scanner cin = new Scanner(System.in);
	double h=0,l=0;
	while(true){
		if(!cin.hasNext()){
			break;
		}
		double x;
		x=cin.nextDouble();
		if(l==0){
			l=x;
		}
		if(x>=h){
			h=x;
		}
		else if(l>=x){
			l=x;
		}
	}
	System.out.println(h-l);
	}
}

Measured memory_bytes: 18620