akhauriyash/Code-Regression huggingface dataset:
import itertools

N = int(input())
red = [tuple(map(int,input().split(" ")))  for _ in range(N)]
blue = [tuple(map(int,input().split(" ")))  for _ in range(N)]
blue = sorted(blue,key=lambda x: (x[0],x[1] ) )
red= sorted(red,key=lambda x: (-x[1],x[0] ) )

ans = 0
for b in blue:
    bx,by = b
    for i,r in enumerate(red):
        rx,ry = r
        if bx > rx and by > ry:
            ans += 1
            red.pop(i)
            break


print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main() {
  int n, m, l, i, j, k;
  int a[101][101], b[101][101];
  long long c[101][101] = {};

  scanf("%d %d %d", &n, &m, &l);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < l; j++) {
      scanf("%d", &b[i][j]);
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      for (k = 0; k < m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }

  for (i = 0; i < n; i++) {
    for (j = 0; j < l; j++) {
      if(j) printf(" ");
      printf("%ld",c[i][j]);
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 2100
N = int(input())
A = [int(i) for i in input().split()]
pn = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443,
      449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
lcm = dict()
mod = 10**9+7
for a in A:
    i = 0
    while a != 1 and i < len(pn):
        c = 0
        n = pn[i]
        while a % n == 0:
            a //= n
            c += 1
        if not n in lcm:
            lcm[n] = 0
        lcm[n] = max(lcm[n], c)
        i += 1
    if a != 1:
        if not a in lcm:
            lcm[a] = 1
l = 1
for n in lcm.keys():
    l *= pow(n, lcm[n], mod)
    l %= mod
ans = 0
for a in A:
    p = pow(a, mod-2, mod)
    ans += (l*p)
    ans %= mod
print(ans)


Measured memory_bytes: 48988
#include<stdio.h>
int R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
//挿入関数
void hin(int a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}

int main(){
  int n,m,i,c,b[100010],d[100010],j;
  long long a,s=0;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    scanf("%lld",&a);
    hin(-a);
  }
  for(i=0;i<n;i++)d[i]=-N[hout()];
  for(i=0;i<n;i++)s+=d[i];
  // printf("%lld\n",s);
  R=C=1;
  for(i=0;i<m;i++){
    scanf("%d %d",&b[R],&c);
    hin(c);
  }
  for(i=a=0;i<m;i++){
    c=hout();
    for(j=0;j<b[c];j++){
      if(d[a]<N[c])s+=N[c]-d[a];
      else goto END;
      a++;
      if(a==n)goto END;
    }
  }
 END:;
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 5376
#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;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

using Edge = pair<int, long long>;
using Graph = vector<vector<Edge> >;

int N;
Graph G;

vector<int> dir;
void dfs(int v, int p, int c) {
    dir[v] = c;
    for (auto e : G[v]) {
        if (e.first == p) continue;
        if (e.second & 1) dfs(e.first, v, 1-c);
        else dfs(e.first, v, c);
    }
}

int main() {
    while (cin >> N) {
        G.assign(N, vector<Edge>());
        for (int i = 0; i < N-1; ++i) {
            int u, v;
            long long w;
            cin >> u >> v >> w;
            --u, --v;
            G[u].push_back(Edge(v, w));
            G[v].push_back(Edge(u, w));
        }
        dir.assign(N, 0);
        dfs(0, -1, 1);
        for (auto v : dir) cout << v << endl;
    }
}


Measured memory_bytes: 10496
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };


int main() {
	int A,B,C;
	scanf("%d%d%d", &A,&B,&C);

	if (B + C <= A)printf("0");
	else printf("%d", C-(A-B));




}

/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
	long n,a[100000],i,fhelp,thelp;
	long long help;
	while(~scanf("%ld",&n))
	{
		for(i=0,fhelp=thelp=0;i<n;i++) 
		{
			scanf("%ld",&a[i]);
			if(a[i]%4==0) fhelp++;
			else if(a[i]%2==0) thelp++;
		}
		if(thelp>1) help=fhelp*2+thelp;
		else help=fhelp*2+1;
		printf(help>=n?"Yes\n":"No\n");
	}
} 

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  set<int> A;
  int a, c;
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> a;
  	A.insert(a);
  }
  c = A.size();
  if (c < N) {
    cout << "NO" << endl;
  }
  else {
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 9600
#include <stdio.h>

int main (){


    int z,x,y;
    int flag = 0;
    scanf("%d", &z);
    scanf("%d %d", &x, &y);

    for(int i=x; i<=y; i++){
        if(i%z==0){
          flag = 1;
        }
    }
    if(flag == 1){
        printf("OK\n");
    } else {
        printf("NG\n");
    }
        return 0;
}

Measured memory_bytes: 1608
#選ぶ場合の、数、じゃなくて選ぶ、場合の数、かよ！また読みづらい問題文を・・・
n = int(input())
li = list(map(int,input().split()))
copied = li.copy()
copied.sort()

ans1 = copied[-1]

ans2 = copied[0]

for i in range(1, n):
    if abs(copied[i] - (ans1 / 2)) < abs(ans2 - (ans1 / 2)):
        ans2 = copied[i]

print("%s %s" %(ans1, ans2))

Measured memory_bytes: 14060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
const ll INF=1e18;
const ll MOD=998244353;
const double pi=3.1415926;
ll m,k;
void solve()
{
    if(m==1)
    {
        if(k==0)
        {
            printf("0 0 1 1\n");
            return;
        }
        else
        {
            printf("-1\n");
            return;
        }
    }
    ll lim=1;
    for(ll i=1;i<=m;i++)
    {
        lim*=2;
    }
    lim-=1;
    if(k>lim)
    {
        printf("-1\n");
    }
    else
    {
        for(ll i=0;i<=lim;i++)
        {
            if(i!=k)
            {
                printf("%lld ",i);
            }
        }

        printf("%lld ",k);
        for(ll i=lim;i>=0;i--)
        {
            if(i!=k)
            {
                printf("%lld ",i);
            }
        }
        printf("%lld ",k);

    }
}
int main()
{
//    freopen("c://duipai//data.txt","r",stdin);
//    freopen("c://duipai//wa.txt","w",stdout);
 //   printf("%d",1^2^3^4^5^6^7^8^9^10^11^12^13^14^15);
    while(~scanf("%lld %lld",&m,&k))
    {
        solve();
    }
}
/*
100
3
1 1
1
4
1 1 1
1 1
1
*/


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

int main(){
    int h,w;
    cin >> h >> w;
    while(h!=0 && w!=0){
        for(int i=0;i<w;i++){
            cout << "#";
        }cout << endl;
            for(int j=1;j<h-1;j++){
                cout << "#";
                for(int k=1;k<w-1;k++){
                    cout << ".";
                }cout << "#" << endl;
            }
        for(int i=0;i<w;i++){
            cout << "#" ;
        }cout << endl << endl; 
    cin >> h >> w;
    }
}


Measured memory_bytes: 2984
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] hs = br.readLine().split(" ");
		int[] he = new int[n];			
		for (int i = 0; i < n; i++) {
			he[i] = Integer.parseInt(hs[i]);
		}
		int max = he[0];
		boolean stop = false;
		for (int i = 0; i < n-1 && !stop; i++) {
			if(max < he[i]) {
				max=he[i];
			}
			if(he[i] <= he[i+1]) {
				if(max == he[i]) {
					max--;
				}
				he[i]--;
			} else {
				if(he[i] - 1 > he[i+1] || he[i] < max) {
					stop = true;
					System.out.println("No");
				} else {
					he[i]--;
					if(max == he[i]) {
						max--;
					}
				}
			}
			//System.out.println(Arrays.toString(he));
			//System.out.println(max);
		}
		if(!stop) System.out.println("Yes");
		//System.out.println(Arrays.toString(he));
		br.close();
	}

}


Measured memory_bytes: 42256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
vector<pair<int,pair<int,int> > > v;
int  main(){
int d,g;
cin>>d>>g;
for(int i=0;i<d;i++)
{
    int a,b;
    cin>>a>>b;int o=(i+1)*100;
    v.push_back(make_pair(o ,make_pair(a,b)));
}int o=1e8;
do{
   int p=g,k=0;
   for(int i=0;i<d;i++)
   {if(p<=0)
   break;
       if(v[i].ff*v[i].ss.ff+v[i].ss.ss<=p)
       {
           p-=v[i].ff*v[i].ss.ff+v[i].ss.ss;
           k+=v[i].ss.ff;
       }
           else if(v[i].ff*v[i].ss.ff+v[i].ss.ss>=p&&v[i].ff*v[i].ss.ff<p)
       {
           p-=v[i].ff*v[i].ss.ff+v[i].ss.ss;
           k+=v[i].ss.ff;
       }
       else {
        k+=p/v[i].ff;
        if(p%v[i].ff!=0)
            k++;
        p=0;
       }
   }
   o=min(o,k);
}
while(std::next_permutation(v.begin(), v.end()));
cout<<o;
}



Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._

  val Array(n, k) = readLine.trim.split(' ').map(_.toInt)
  val numbers = 0L +: readLine.trim.split(' ').map(_.toLong)
  for (i ← numbers.indices.tail){
    numbers(i) += numbers(i - 1)
  }
  var result = 0L
  var rest = numbers.indices.dropRight(1).flatMap(left ⇒ (left + 1 to n).map(right ⇒ numbers(right) - numbers(left)))
  for (digit ← (0 until 63).reverse){
    val filtered = rest.filter(l ⇒ (l & (1L << digit)) != 0)
    if (filtered.length >= k){
      result |= 1L << digit
      rest = filtered
    }
  }
  println(result)
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 51084
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 1 << 12;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)


int main() {
    string s;
    cin >> s;
    if(s[0]==s[2])cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#if loc||local
#define _GLIBCXX_DEBUG
#endif

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<ll(n);++i)
#define repr(i,n) for(ll i=ll(n);i-->0;)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n,m;
  cin>>n>>m;
  vector<vector<int>> adj(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    adj[a].emplace_back(b);
    adj[b].emplace_back(a);
  }
  vector<int> seen(n);
  auto dfs = [&](auto&&dfs,int cur,int prv)->int{
    if(seen[cur])return 0;
    seen[cur] = 1;
    int res = 0;
    for(auto to:adj[cur])if(to!=prv)res+=dfs(dfs,to,cur);
    return res+1;
  };
  int ans = 0;
  rep(i,n)chmax(ans,dfs(dfs,i,-1));
  cout<<(ans)<<endl;

}

Measured memory_bytes: 30640
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define P pair<int,int>
//P pa(114,514);   ,vector<P>vec(N,0);
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
//cout << setprecision(123);
int main(){
  int N,K;
  cin>>N>>K;
  cout<<N-K+1<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a[] = new int[5];
        int ans = 0;
        int max = 0;
        for(int i = 0;i<5;i++){
            a[i] = sc.nextInt();
            sc.nextLine();
            
            ans += a[i] + 10 - a[i] % 10;
            if(a[i] % 10 != 0){
                max = Math.max(max,10 - a[i] % 10);
            }else{
                ans -=10;
            }
        }
        System.out.println(ans - max);
    }
}

Measured memory_bytes: 23764
n = int(input())
A = list(map(int,input().split()))

dp = [[0]*2 for i in range(n)]

dp[0][0] = A[0]
dp[0][1] = -A[0]

for i in range(1,n):
    dp[i][0] = max(dp[i-1][0]+A[i],dp[i-1][1]-A[i])
    dp[i][1] = max(dp[i-1][0]-A[i],dp[i-1][1]+A[i])

print(dp[n-1][0])

Measured memory_bytes: 99296
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        //Compute c1 = new Compute();//calc
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //StringBuilder answer=new StringBuilder();
        //input
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        double k=0;
        k=n-(n/2);
        //System.out.println(k);
        double ans = k/n;
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
 
 
int main(){
    int n;
    cin >> n;
    vector<int> s(n);
    rep(i, n) cin >> s[i];
 
    int ans = 0;
    rep(i, n) ans += s[i];
    sort(s.begin(), s.end());
    if (ans%10==0) {
        rep(i, n) {
            int now = ans - s[i];
            if (now%10!=0) {
                cout << now << endl;
                return 0;
            }
        }
    }
    else {
        cout << ans << endl;
        return 0;
    }
    
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

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

using namespace std;

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

    ll H, W, N;
    cin >> H >> W >> N;
    set<pair<ll, ll>> black;
    Rep (i, N) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        black.insert(make_pair(a, b));
    }

    vector<ll> ans(10, 0);
    ans[0] = (H-2)*(W-2);
    set<pair<ll, ll>> visited;
    for (auto e : black) {
        ll ny = e.first, nx = e.second;
        for (ll i = -1; i <= 1; i++) {
            for (ll j = -1; j <= 1; j++) {
                ll cy = ny + i, cx = nx + j;
                if (cy <= 0 || H-1 <= cy || cx <= 0 || W-1 <= cx) continue;
                if (visited.find(make_pair(cy, cx)) != visited.end()) continue;
                ll cnt = 0;
                for (ll k = -1; k <= 1; k++) {
                    for (ll l = -1; l <= 1; l++) {
                        ll y = cy + k, x = cx + l;
                        if (black.find(make_pair(y, x)) != black.end()) cnt++;
                    }
                }
                ans[0]--;
                ans[cnt]++;
                visited.insert(make_pair(cy, cx));
            }
        }
    }

    for (ll e : ans) {
        cout << e << "\n";
    }

}

Measured memory_bytes: 62848
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    
    int n;
    cin>>n;
    
    int a[100];
    
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    int max=0;
    int s=0;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            s=abs(a[i]-a[j]);
            if(s>=max){
                max=s;
            }
            
        }
    }
    
    cout<<max<<endl;
    
    return 0;
}








Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
    // 入力を解釈
	input = input.split("\n");
	tmp0 = input[0];
	tmp1Array = input[1].split(" ");
	tmp2Array = input[2].split(" ");
	
	var length = tmp1Array.length;
	var totalValue = 0;
	for(var i = 0 ; i <= length ; i++){
	    var temp = tmp1Array[i] -  tmp2Array[i];
	    
	    if(temp > 0){
	        totalValue += temp;
	    }
	}

    
	
	// 文字を10進数に変換
	// var a = parseInt(input[0], 10);


	//出力
	console.log(totalValue);
}

// var counter = function(str,seq){
//     return str.split(seq).length - 1;
// }

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


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

int sign(long long int num) {
  if (num<0) {
    return -1;
  }
  else if(num > 0) {
    return 1;
  }
  else {
    return 0;
  }
}

int main() {
  long long int n;
  cin >> n;
  vector<long long int> list(n);
  for (long long int i=0;i<n;i++) {
    cin >> list.at(i);
  }
  long long int count=1;
  long long int len=0;
  long long int judge=0;
  for (long long int i=0;i<n-1;i++) {
    len++;
    //cout << len << endl;
    if (len == 1) {
      judge = 0;
    }
    else {
      //cout << i << endl;
      if(judge==0) {
        judge = sign(list.at(i)-list.at(i-1));
      }
      if ( judge * sign(list.at(i+1)-list.at(i)) < 0 ) {
        count++;
        len=0;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 1024
N, M = map(int,input().split())
light = []
for _ in range(M):
    light.append(list(map(int,input().split())))
p = list(map(int,input().split()))
ans = 2 ** N
for i in range(2 ** N):
    tmp = [0] * N
    for k in range(N):
        if 1 & i>>k:
            tmp[k] = 1
    for k in range(M):
        count = 0
        for l in range(1,light[k][0]+1):
            if tmp[light[k][l]-1] == 1:
                count += 1
        if count % 2 != p[k]:
            ans -= 1
            break
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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



int main() {
    int n, a[100000], mx = 0, mn = 1e9;
    cin >> n;
    REP(i, n){
        cin >> a[i];
        mx = max(mx, a[i]);
        mn = min(mn, a[i]);
    }
    if(mx - mn > 1){
        cout << "No" << endl;
    }
    else if(mx - mn == 1){
        int x = 0, y = 0;
        REP(i, n){
            if(a[i] == mx)y++;
            else x++;
        }
        
        if(x < mx && 2 * (mx - x) <= y){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    else{
        if(mx == n - 1 && mn == n - 1){
            cout << "Yes" << endl;
            return 0;
        }
        
        REP(i, n){
            if(2 * a[i] > n){
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 640
sx,sy,tx,ty = map(int,input().split())
right = abs(tx - sx)
up = abs(ty - sy)
root = 'U'*up + 'R'*right
root_back = 'D'*up + 'L'*right
root2 = 'L' + 'U'*(up+1) + 'R'*(right+1) + 'D'
root_back2 = 'R' + 'D'*(up+1) + 'L'*(right+1) + 'U'
print(root+root_back+root2+root_back2)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
    int n,a[200000],i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    int max=a[1]-a[0];
    int min=a[0];
    for(i=1;i<n;i++){
        if(max<a[i]-min){
            max=a[i]-min;
        }
        if(min>a[i]){
            min=a[i];
        }
    }
    printf("%d\n",max);
    return 0;
}



Measured memory_bytes: 2508
/**
*	created: 22.08.2020 21:00:20
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using ll = long long;
using P = pair<int,int>;
// #define endl '\n'
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1ll << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n, x, t; cin >> n >> x >> t;
    if (n % x == 0) cout << t*(n/x) << endl;
    else cout << t*(n/x+1) << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;
using ll = long long int; 


ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}


int main(void){

   int n, m;
   cin>>n>>m;

   vector<vector<int>> x(n);
   int input[m][2];

   for(int i=0;i<m;i++){
     int p, y;
     cin>>p>>y;
     input[i][0] = p;
     input[i][1] = y;

     x[p-1].push_back(y);
   }

   for(int i=0;i<n;i++){
     vector<int> v;
     v = x[i];
     sort(v.begin(), v.end());
     x[i] = v;
   }

   for(int i=0;i<m;i++){

     //県番号
     //cout<<string(6-keta(input[i][0]), '0')<<input[i][0];
     cout<<setfill('0')<<right<<setw(6)<<input[i][0];

    //  vector<int> v;
    //  v = x[input[i][0]-1];

     //input[i][1]のイテレータを探す（2分探索）
     auto position = lower_bound(x[input[i][0]-1].begin(), x[input[i][0]-1].end(), input[i][1]);

     int index = distance(x[input[i][0]-1].begin(), position)+1;

     //年数順番号
     //cout<<string(6-keta(index), '0')<<index<<endl;
     cout<<setfill('0')<<right<<setw(6)<<index<<endl;

   }


    return 0;
}

Measured memory_bytes: 7680
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = (sc.nextLong() + 11) % 13;
		long b = (sc.nextLong() + 11) % 13;
		System.out.println(a > b ? "Alice" : a < b ? "Bob" : "Draw");
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }

  int ans = 0;
  vector<bool> visited(n, false);
  int now = 0;
  while (now != 1) {
    if (visited[now]) {
      cout << -1 << endl;
      return 0;
    }
    visited[now] = true;
    now = a[now];
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
def WarshallFloyd(M):
    N = len(M)
    for k in range(N):
        for j in range(N):
            for i in range(N):
                M[i][j] = min(M[i][j], M[i][k] + M[k][j])
    return M

H, W = [int(i) for i in input().split()]
C = [[int(i) for i in input().split()] for _ in range(10)]
A = [[int(i) for i in input().split()] for _ in range(H)]

M = WarshallFloyd(C)

ans = 0
for r in A:
    for a in r:
        if a >= 0:
            ans += M[a][1]
print(ans)

Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    n, m = [int(x) for x in input().split()]
    ans = [0] * m
    a = defaultdict(list)
    for i in range(m):
        p, y = [int(x) for x in input().split()]
        a[p].append((y, i))

    for p in a:
        r = a[p]
        r.sort()
        for x, (y, i) in enumerate(r):
            ans[i] = f'{p:06}{x+1:06}'
    for r in ans:
        print(r)

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""
a b a
d c d
a b a
"""


Measured memory_bytes: 47208
n = gets.chomp.to_i
d = gets.chomp.split.map(&:to_i)

f = d.shift
if f != 0
  p 0
  exit
end

d.sort!

if d[0] == 0
  p 0
  exit
end

ans = 1
last_node = 1
1.upto(n) do |i|
  num = 0
  d.size.times do |u|
    p = d[0]
    if p == i
      num += 1
      d.shift
    else
      break
    end
  end
  if num == 0
    if d.empty?
      break
    else
      p 0
      exit
    end
  end
  t = (last_node ** num) % 998244353
  ans *= t
  ans %= 998244353
  last_node = num
end
p ans


Measured memory_bytes: 11256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pcont(x) for(auto i: x){cout << i << " ";} cout << "\n";

int main(){
    IOS;
    string n;
    cin >> n;
    int sum = 0;
    for(int i = 0; i<(int)n.size(); i++){
        int d = n[i] - '0';
        sum += d;
    }
    cout << ((sum%9==0)?"Yes\n":"No\n");
    return 0;
}

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

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define RepG(i,u) for(int i=head[u];~i;i=e[i].next)

typedef long long ll;

const int N=1e5+5;

template<typename T> void read(T &x){
   x=0;int f=1;
   char c=getchar();
   for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
   for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
    x*=f;
}

int a,b,c,k;

int main()
{
    read(a),read(b),read(c),read(k);
    int t=0;
    while(b<=a)b*=2,t++;
    while(c<=b)c*=2,t++;
    if(t<=k)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <sstream>
#include <fstream>
#include <float.h>
#include <cmath>
#include <cstring>

using namespace std;
#define int long long
const int mod = 1000000007;
int dp[501][501][50] = {};

signed main(){
	int N, Ma, Mb;
	int a[100] = {}, b[100] = {}, c[100] = {};
	cin >> N >> Ma >> Mb;
	for (int i = 0; i < N; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		for (int i = 450; i >= 0; i--) {
			for (int j = 450; j >= 0; j--) {
				for (int k = N; k >= 0; k--) {
					if (dp[i][j][k] != 0) {
						if (dp[i + a][j + b][k + 1] != 0) {
							dp[i + a][j + b][k + 1] = min(dp[i + a][j + b][k + 1], dp[i][j][k] + c);
						}
						else dp[i + a][j + b][k + 1] = dp[i][j][k]+ c;
					}
				}
			}
		}
		if(dp[a][b][1]!=0)dp[a][b][1] = min(dp[a][b][1],c);
		else dp[a][b][1] = c;
	}
	int m = 999999999999;
	for (int i = 0; i <=450; i++) {
		for (int j = 0;j<=450; j++) {
			for (int k = 0; k <= N;k++) {
				if (dp[i][j][k] != 0) {
					//cout << (double)i / j <<" "<< (double)Ma / Mb << endl;
					if((Ma*j)==(Mb*i)){
						m = min(m, dp[i][j][k]);
					}
				}
			}
		}
	}
	if (m == 999999999999) {
		cout << "-1" << endl;
		return 0;
	}
	cout <<m << endl;
	

	
	return 0;
}


Measured memory_bytes: 9472
#include <stdio.h>
#include <vector>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
using vi = vector<int>;

string str;
string stra;
int id = 0;

void pt(vector<int> v){
  for(int r=0;r<v.size();r++){
    cout << v[r];
  }
  cout << endl;
}

vi number(){
  vi res;
  for (;'0'<=stra[id]&&stra[id]<='9'; id++) {
    res.push_back(stra[id] - '0');
  }
  reverse(res.begin(),res.end());
  return res;
}
int solve(){
  stra = str;
  for (int i = 9; i >= 0; i--) {
    id = 0;
    for (int j = 0; j <(int)str.size(); j++) {
      if (str[j] == 'X') {
        stra[j] = i + '0';
      }
    }
    vi a = number();
    if (stra[id] == '+' ) {
      id++;
    }
    vi b = number();

    a.resize(max(b.size() + 1,a.size()+1),0);

    for (int j = 0; j < (int)b.size(); j++) {
      a[j] += b[j];
      if (a[j]>=10) {
        a[j] -= 10;
        a[j+1]++;
      }
    }
    for (int j = b.size(); j < (int)(a.size()-1); j++) {
      if (a[j] >= 10) {
        a[j] -= 10;
        a[j+1]++;
      }
    }


    if(a[a.size()-1]==0){
      a.pop_back();
    }


    if (stra[id] == '=') {
      id++;
    }

    vi c = number();
    while(a.size()<c.size()){
      a.push_back(-1);
    }
    // while(a.size()>c.size()){
    //   c.push_back(0);
    // }
    
    if (a.size() != c.size()) {
      continue;
    }
    int flag = 0;
    for (int j = 0; j < (int)a.size(); j++) {
      if (a[j] == c[j]) {
        flag++;
      }
    }
    if (flag ==(int)a.size()) {
      return i;
    }

  }
  return -1;
}
int main(){
  cin >> str;
  while(str.size()){
  int ans = solve();
  if (ans >= 0) {
    cout << ans << endl;
  } else {
    cout << "NA" << endl;
  }
  str="";
  cin >> str;
}
  return 0;
}



Measured memory_bytes: 3204
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

bool arr[101];

int main(void){
	uint32_t n, k;
	scanf("%"SCNu32"%"SCNu32, &n, &k);
	for(uint32_t i=k; i>0; i--){
		uint32_t d;
		scanf("%"SCNu32, &d);
		for(uint32_t j=d; j>0; j--){
			uint32_t a;
			scanf("%"SCNu32, &a);
			arr[a]=true;
		}
	}
	uint32_t ans=0;
	for(uint32_t i=n; i>0; i--){
		if(!arr[i]) ans++;
	}
	printf("%"PRIu32"\n", ans);
}


Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
int main(){
    long k;
    cin>>k;
    vector<int>P;
  for(int i=0;i<k;i++){
     int x;
     cin>>x;
     P.push_back(x);
  }
  int cnt=0;
  for(int i=1;i<k-1;i++){
    if(((P[i-1]<P[i]) && (P[i]<P[i+1])) || ((P[i-1]>P[i]) && (P[i]>P[i+1])) ){
        cnt++;
    }
  }

cout<<cnt;
    
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map{it.toInt()}
    val x = Array(M) {0}
    val y = Array(M) {0}

    for (i in x.indices) {
        val (X, Y) = readLine()!!.split(" ").map{it.toInt() - 1}

        x[i] = X
        y[i] = Y
    }

    val f = Array(N) { false }
    val cnt = Array(N) { 1 }
    f[0] = true

    for (i in x.indices) {
        cnt[x[i]]--
        cnt[y[i]]++
        f[y[i]] = f[y[i]] || f[x[i]]

        if (cnt[x[i]] == 0) {
            f[x[i]] = false
        }
    }

    println(f.count {it})
}


Measured memory_bytes: 60792
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
  long long int n, s;
  scanf("%lld %lld", &n, &s);
  if(s > n){
    printf("%d\n",-1);
    return 0;
  }else if(s == n){
    printf("%lld\n",n+1);
    return 0;
  }
  long long int d = n - s, ans = -1, m = sqrt(d);
  for(long long int i = 1; i <= m; ++i){
    if(d != d/i*i) continue;
    long long int b = i + 1, n_ = n, t = n;
    while(n_ > 0){
      n_ /= b;
      t -= n_*(b-1);
      if(t < s) break;
    }
    if(t == s){
      printf("%lld\n",b);
      return 0;
    }
    b = d/i + 1;
    n_ = n;
    t = n;
    while(n_ > 0){
      n_ /= b;
      t -= n_*(b-1);
      if(t < s) break;
    }
    if(t == s){
      ans = b;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
n=int(input())
a=list(map(int,input().split()))
col=[0]*8
ans=0
for i in a:
    for j in range(8):
        if j*400<=i<(j+1)*400:
            col[j]=1
    if i>=3200:
        ans+=1
ans1=sum(col)
print(max(ans1,1),ans1+ans)

Measured memory_bytes: 3064
{-
This answer was written after referring to the editorial.
-}

import qualified Data.ByteString.Lazy.Char8 as B
import Data.List
import Data.Maybe

bsReadInts = map (fst . fromJust . B.readInt) . B.words

solve :: Int -> [Int] -> String
solve n as = if solve2 (zip [1..] as) then "Yes" else "No"

solve2 nas = all isGood $ unfoldr getPart nas

getPart :: [(Int,Int)] -> Maybe (([(Int,Int)], Int), [(Int,Int)])
getPart = f . dropWhile (uncurry (==))
  where
    f [] = Nothing
    f (na:nas) = Just ((na : nas1, len), nas2)
      where
        (nas1, nas2) = splitAt (2*len) nas
        len = length $ takeWhile prop $ binzip nas

prop ((n0,a0), (n1,a1)) = n0 == a0 && n1 /= a1

binzip = unfoldr f
  where f (x:y:p) = Just ((x,y), p)
        f _       = Nothing

isGood ([_], _) = False
isGood (nas, len) = ordpres left && ordpres right && all rangeOK nas
  where
    left =  [a | (n,a) <- nas, n < a]
    right = [a | (n,a) <- nas, n > a]
    rangeOK (_,a) = xmin <= a && a <= xmax
    xmin = snd (nas !! 1) - 1
    xmax = xmin + 2 * len

ordpres x = all (uncurry (<)) $ zip x (tail x)

main = do
  cont <- B.getContents
  let n : as = bsReadInts cont
  putStrLn $ solve n as


Measured memory_bytes: 56572
/*
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 |                                                                 |
 |   author : thanos1399     Language : C ++                         | 
 |   college : MSIT                                                | 
 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |  
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
using namespace std ;
#define TEST            int t ; cin>>t; while(t--)
#define line            cout<<endl;
#define loop(i,a,b)     for(long long int i=a;i<b;i++)
#define loopIn(i,a,b)   for(long long int i=a;i<=b;i++)
#define MAX_SIZE        1000000
#define ff              first
#define ss              second
#define pb              push_back
#define ll              long long int  
#define mp              make_pair
#define vt              vector<tup>
#define vtt             vector<vt >
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
void Sieve( int *prime , int n){for(int i=0;i<n;i++){prime[i] = 0;}for(int i=2;i<n;i++){prime[i] = 1 ;}for(int i=4;i<n;i+=2){prime[i] = 0;}for(int i=3;i<n;i++){if(prime[i]==1){for(int j=i*i;j<n;j+=i){prime[j] = 0;}}}return ;}
void input(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("/home/yash/Desktop/CPP/input.txt","r",stdin);
    freopen("/home/yash/Desktop/CPP/output.txt","w",stdout);
    #endif
}
ll inp;
int parent[101];
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) {return (a.second < b.second); } 
/*int find(int a)
{
    while(parent[a] > 0)
        a = parent[a];
 
    return a;
} */
 
void Union(int a , int b)
{
    parent[a] += parent[b];     //adding size of set b to set a
    parent[b] = a;              //making a , parent of new set
}
int find ( int node )
{
    if ( parent[node] < 0 )
        return node ;
 
    parent[node] = find( parent[node] ) ;
    return parent[node] ;
}
 
int main() {
    //input();
    int n;
    cin>>n;
    vi V;
    loop(i,0,n){
        cin>>inp;
        V.pb(inp);
    }
    int dp[n];
    dp[0] = 0 ;
    dp[1] = abs(V[0] - V[1]);
    loop(i,2,n){
        int ans1 = dp[i-1] + abs(V[i] - V[i-1]);
        int ans2 = dp[i-2] + abs(V[i] - V[i-2]);
        dp[i] = min (ans1 , ans2); 
    }
    cout<<dp[n-1]<<endl;


    return 0;
}

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

towns = [0] * N

town = 1
i = 0
while True:
    if towns[town-1] < 2:
        
        if towns[town-1] == 0:
            i += 1
            
        towns[town-1] += 1
        town = A[town-1]
    else:
        s = town
        break
    
loop = towns.count(2)
i = i - loop
k = (K - i) % loop

if K < i:
    town = 1
    for _ in range(K):
        town = A[town-1]
    print(town)
    exit()

if k == 0:
    print(s)
    exit()

for _ in range(k):
    town = A[town-1]
print(town)

Measured memory_bytes: 92436
package main

import (
        "fmt"
)

func solution(n, m int, lr [][]int) int {
        l, r := -1<<31, 1<<31
        for i := 0; i < m; i++ {
                l = max(l, lr[i][0])
                r = min(r, lr[i][1])
        }
        if l <= r {
                return r - l + 1
        }
        return 0
}

func min(x, y int) int {
        if x < y {
                return x
        }
        return y
}

func max(x, y int) int {
        if x > y {
                return x
        }
        return y
}

func main() {
        var n, m int
        fmt.Scan(&n, &m)
        lr := make([][]int, m)
        for i := 0; i < m; i++ {
                l, r := 0, 0
                lr[i] = make([]int, 2)
                fmt.Scan(&l, &r)
                lr[i][0], lr[i][1] = l, r
        }
        fmt.Println(solution(n, m, lr))
}

Measured memory_bytes: 8324
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int D,G;
    cin >> D >> G;
    vector<ll> p(D),c(D);
    ll ans = 1e10;
    rep(i,D){
        cin >> p[i] >> c[i];
    }
    for(int i=0;i< (1<<D);i++){
        ll sum = 0; // 合計得点
        ll num = 0; // 問題を解いた数
        for(int j=0;j<D;j++){
            if( (i>>j) & 1){
                // j番目の問題をコンプリートする
                num += p[j];                
                sum += p[j]*100*(j+1) + c[j];
            }
        }
        if(sum>=G){
            ans = min(ans,num);
            continue;
        }
        // 足りない点数を得点の大きい順に解いていく
        ll need = G - sum ;
        for(int j=D-1;j>=0;j--){
            if( (i>>j) & 1)continue; // 既にコンプリートしていたらその問題は選べない
            int cur = (j+1)*100; // 現在1問解くと得られる得点
            if(cur * p[j] >= need){
                ans = min(ans,num + (need+cur-1)/cur);
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#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, x, t;
  cin >> n >> x >> t;

  // (20 / 12) * 6
  ll cnt = n / x;
  if(n % x != 0) {
    cnt++;
  }
  cout << cnt * t << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;

ll N,M;
vector<ll> v[8];
vector<ll> ans;

int main(){
    ll a,b,c;
    cin >> N >> M;
    for(int i=0;i<N;i++){
        cin >> a >> b >> c;
        for(int j=0;j<8;j++){
            ll aa = a;
            ll bb = b;
            ll cc = c;
            if(j % 2 == 0) aa *= (-1);
            if((j >> 1) % 2 == 0) bb *= (-1);
            if((j >> 2) % 2 == 0) cc *= (-1);
            v[j].push_back(aa+bb+cc);
        }
    }
    for(int i=0;i<8;i++) sort(v[i].begin(),v[i].end(),greater<ll>());
    for(int i=0;i<8;i++){
        ll p = 0;
        for(int j=0;j<M;j++){
            p += v[i][j];
        }
        ans.push_back(p);
    }
    sort(ans.begin(),ans.end(),greater<ll>());
    cout << ans[0] << endl;
    return 0;
}

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

public class Main
{
  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String s;
    String sl[];

    s = r.readLine();
    sl = s.split(" ");
    long a = Long.parseLong(sl[0]);
    long b = Long.parseLong(sl[1]);

    long i;
    for(i = Math.max(a, b); i >= 2; i--)
    {
      if(a / i * i == a && b / i * i == b)break;
    }
    System.out.println(a * b / i);
  }

}

class RemRing
{
  long module;

  public RemRing(long module)
  {
    this.module = module;
  }

  public long sum(long a, long b)
  {
    return (a + b + module) % module;
  }

  public long sub(long a, long b)
  {
    return (a - b + module) % module;
  }

  public long prod(long a, long b)
  {
    return (a * b) % module;
  }

  public long div(long a, long b)
  {
    return (a * inv(b)) % module;
  }

  public long inv(long a)
  {
    long b = this.module;
    long u = 1;
    long v = 0;
    while (b > 0)
    {
      long t = a / b;
      a -= t * b;
      u -= t * v;
      long z = a;
      a = b;
      b = z;
      z = u;
      u = v;
      v = z;
    }
    u %= this.module;
    if (u < 0)
      u += this.module;
    return u;
  }
}

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

#define vi std::vector<int>
#define iter std::vector<int>::iterator
#define pb = push_back



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

	b = b.substr(0, (int)b.length()-1);

	if (a == b)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  if((S.at(0)==S.at(1))&&(S.at(1)==S.at(2))){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}


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

struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}

signed main() 
{
  int w,h,n; cin>>w>>h>>n;
  pii s={0,0},b={w,h};
  rep(i,n)
  {
    int x,y,a; cin>>x>>y>>a;
    if(a==1) s.Fi=max(s.Fi,x);
    else if(a==2) b.Fi=min(b.Fi,x);
    else if(a==3) s.Se=max(s.Se,y);
    else b.Se=min(b.Se,y);
  }
  s.Fi>=b.Fi||s.Se>=b.Se?print(0):print((b.Fi-s.Fi)*(b.Se-s.Se));

  return 0;
}

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

int main() {
    int H, W;

    while (true) {
        cin >> H >> W;
        
        if (H == 0 && W == 0) break;
        
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (i == 0 || (i + 1) == H || j == 0 || (j + 1) == W) {
                    cout << '#';
                }
                else {
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}



Measured memory_bytes: 3056