akhauriyash/Code-Regression huggingface dataset:
import java.lang.Math;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;
import java.util.stream.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int points[] = new int[N+2];
        points[0] = 0;
        points[N + 1] = 0;  // last
        int costs[] = new int[N+1];

        for (int i = 1; i < N + 1; i++) {
            points[i] = sc.nextInt();
        }

        for (int i = 0; i < costs.length; i++) {
            costs[i] = Math.abs(points[i] - points[i+1]);
        }

        int cost_sum = IntStream.of(costs).sum();
        for (int i = 0; i < N; i++) {
            System.out.println(cost_sum + Math.abs(points[i] - points[i+2]) - costs[i] - costs[i+1]);
        }
    }
}


Measured memory_bytes: 70280
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int x[N], y[N], h[N];
  for(int i=0;i<N;++i) cin>>x[i]>>y[i]>>h[i];
  int index;
  for(int i=0;i<N;++i) {
    if(h[i]>0) {
      index = i;
      break;
    }
  }
  bool ok;
  int height;
  int tmp;
  int Cx, Cy, H;
  for(int i=0;i<=100;++i) {
    for(int j=0;j<=100;++j) {
      height = h[index] + abs(x[index]-i) + abs(y[index]-j);
      ok = true;
      for(int k=0;k<N;++k) {
        tmp = max(0, height-abs(x[k]-i)-abs(y[k]-j));
        if(tmp!=h[k]) ok = false;
      }
      if(ok) {
        Cx = i;
        Cy = j;
        H = height;
      }
    }
  }
  cout<<Cx<<" "<<Cy<<" "<<H<<endl;
}



Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		System.out.println(n-k+1);
		
	}
}


Measured memory_bytes: 21332
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

int X, Y;

ll factorial(ll x)
{
    ll ret = 1;
    FOR (i, 2, x+1) {
        ret = (ret * i) % MOD;
    }
    return ret;
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

void solve()
{
    ll ans = 0;
    if (X > Y) swap(X, Y);
    REP (i, X/2+1) {
        int one = X - 2*i, two = i;
        if (2*one + two != Y) continue;
        ll val = factorial(one+two);
        val *= modinv(factorial(one), MOD);
        val %= MOD;
        val *= modinv(factorial(two), MOD);
        val %= MOD;
        ans += val;
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> X >> Y;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

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

    s[b-1] += 0x20;

    cout << s << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int ndat;
vector<int> dat;

void rmg_init(int n_) {
  ndat = 1;
  while (ndat < n_) ndat *= 2;
  dat.resize(2 * ndat - 1, 0);
}

void update(int k, char nxt) {
  k += ndat - 1;
  int nt = nxt - 'a';
  dat[k] = (1 << nt);
  while (k > 0) {
    k = (k - 1) / 2;
    dat[k] = dat[2 * k + 1] | dat[2 * k + 2];
  }
}

int query(int a, int b, int k, int l, int r) {
  int res = 0;
  if (r <= a || b <= l) return 0;
  if (a <= l && r <= b) {
    return dat[k];
  }
  else {
    int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    res |= vl;
    res |= vr;
    return res;
  }
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;

  rmg_init(n);
  rep(i, n) {
    update(i, s[i]);
  }
  int q;
  cin >> q;
  rep(i, q) {
    int t;
    cin >> t;
    if (t == 1) {
      int iq;
      char cq;
      cin >> iq >> cq;
      update(iq - 1, cq);
    }
    else {
      int lq, rq;
      cin >> lq >> rq;
      int res = query(lq - 1, rq, 0, 0, ndat);
      int cnt = 0;
      while (res > 0) {
        if (res & 1) cnt++;
        res /= 2;
      }
      cout << cnt << endl;
    }
  }


  
  return 0;
}

Measured memory_bytes: 4996
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

while(true){
        int m =sc.nextInt();
        int f =sc.nextInt();
        int r =sc.nextInt();

        if(m==-1&&f==-1&&r==-1){
            break;
        }

        if(m==-1 || f==-1){
            System.out.println("F");
        }else{
            if(80<=m+f){
                System.out.println("A");
            }else{
                if(m+f<80 && 65 <= m+f){
                    System.out.println("B");
                }else{
                    if(m+f<65 && 50<=m+f){
                        System.out.println("C");
                    }else{
                        if(m+f<50 && 30<=m+f){
                            if(50<=r){
                                System.out.println("C");
                            }else{
                                System.out.println("D");
                            }
                        }else{
                            System.out.println("F");
                        }
                    }
                }
            }
        }
    }

    }
}


Measured memory_bytes: 26292
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Regular080
{
    public class ARC080C_4adjacent
    {
        public static void Main(string[] args)
        {
            
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int x4Cnt = 0;
            int x2Cnt = 0;
            int x1Cnt = 0;

            for(int i = 0; i < n; i++)
            {
                if(a[i] % 4 == 0) x4Cnt++;
                else if(a[i] % 2 == 0) x2Cnt++;
                else x1Cnt++;
            }

            if(x1Cnt == 0)
            {
                Console.WriteLine("Yes");
            }
            else if(x4Cnt + 1 >= x1Cnt + ((x2Cnt != 0) ? 1 : 0))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
            
        }
    }
}

Measured memory_bytes: 19680
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Maybe

main :: IO ()
main = do
  [a,b,c] <- readInts
  print . showAnswer $ solve (a,b,c)

type Input  = (Int, Int, Int)
type Output = Int

solve :: Input -> Output
solve (a,b,c) = (a*b) `div` 2

showAnswer :: Output -> Answer
showAnswer = Number

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)    = bool "No" "Yes" b
  show (YESNO b)    = bool "NO" "YES" b
  show (AB b)       = bool "B"  "A" b
  show (Number i)   = show i
  show (String s)   = s
  show (Compare o)  = ordering "<" "=" ">" o
  show (Compare2 o) = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

Measured memory_bytes: 380
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = 1LL<<55;
const Int mod = (1e9)+7;
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class CumulativeSum{
public:
  vector<Int> sum;
  CumulativeSum(){}
  CumulativeSum(vector<Int> A){
    Int n = A.size();
    sum.resize(n+1,0);
    for(Int i=1;i<=n;i++) sum[i] += sum[i-1] + A[i-1];
  }
  Int get(Int l,Int r){assert(l<=r && l>=0 && r<=(Int)sum.size());return sum[r] - sum[l];} //[l,r)
};


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int n;
  cin>>n;
  string s;
  cin>>s;
  vector<Int> E(n+10),W(n+10);
  for(Int i=0;i<n;i++) E[i] = s[i] == 'E';
  for(Int i=0;i<n;i++) W[i] = s[i] == 'W';

  CumulativeSum A(E), B(W);

  Int ans = INF;
  for(Int i=0;i<n;i++){
    Int a = B.get(0, i);
    Int b = A.get(i+1, n);
    Min(ans, a + b);
  }
  
  cout<<ans<<endl;
  
  
  return 0;
}


Measured memory_bytes: 12268
#include <stdio.h>
void main()
{
int n,i,m;
int a[10000];
int x=0;
scanf("%d",&n);
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%d",&a[i]);
}
  for(i=0;i<m;i++)
    x=x+a[i];
  n=n-x;
 if(n>=0)
  printf("%d",n);
  else
  printf("-1");  
}

Measured memory_bytes: 1760
#include<stdio.h>
#include<string.h>

typedef struct {
  char name[100];
  int t;
}Process;

Process Q[1001];
int n, head = 0, tail = 0;

void enqueue(Process x){

  if(tail == n){
    tail = 1;
  } else {
    tail += 1;
  }

 Q[tail] = x;
}

Process dequeue(){
  if(head == n){
    head = 1;
  } else {
    head++;
  }
  return Q[head];
}

int main(){
  int i, q, count = 0, time = 0;
  Process cell;

  scanf("%d %d", &n, &q);

 for (i = 1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }

  while(count != n){
    cell = dequeue();
    if(cell.t - q <= 0){
      time += cell.t;
      cell.t = 0; 
      count++;
      printf("%s %d\n",cell.name ,time);
    } else if (cell.t > 0){
      time += q;     
      cell.t -= q;
      enqueue(cell);
    }
    
  }
  return 0;
  }

Measured memory_bytes: 0
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {
        s:Chars
    }

    let e = s.iter().find(|&&x| x == 'E');
    let w = s.iter().find(|&&x| x == 'W');
    let n = s.iter().find(|&&x| x == 'N');
    let s = s.iter().find(|&&x| x == 'S');
    let mut ok = true;
    if let Some(e) = e {
        if w == None {
            ok = false;
        }
    }
    if let Some(w) = w {
        if e == None {
            ok = false
        }
    }
    if let Some(n) = n {
        if s == None {
            ok = false;
        }
    }
    if let Some(s) = s {
        if n == None {
            ok = false;
        }
    }
    pub fn yn(ans: bool) {
        if ans {
            println!("Yes");
        } else {
            println!("No");
        }
    }
    yn(ok);
}
const INF: i64 = 1 << 60;


Measured memory_bytes: 2088
#include <stdio.h>
int main(void)
{
    char c1[3]={};
    char c2[3]={};
    scanf("%s",c1);
    scanf("%s",c2);
    int ans=0;
    for(int p=0;p<3;p++)
    {
        if(c1[p]==c2[2-p])
          ans++;
    }
    if(ans==3)
      printf("YES");
    else
      printf("NO");
}


Measured memory_bytes: 128
#coding: utf-8

n, m = map(int, input().split())
a = list()
b = list()
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(m):
    b.append(int(input()))
for i in range(n):
    S = 0
    for j in range(m):
        S += a[i][j] * b[j]
    print(S)


Measured memory_bytes: 6012
#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>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int n;
vector<int> to[200005];

mint ans;
int dfs(int v, int p=-1) {
  int res = 1;
  vector<int> ts;
  for (int u : to[v]) {
    if (u == p) continue;
    int t = dfs(u,v);
    res += t;
    ts.push_back(t);
  }
  if (p != -1) {
    ts.push_back(n-res);
  }
  mint now = mint(2).pow(n-1)-1;
  for (int t : ts) {
    now -= mint(2).pow(t)-1;
  }
  ans += now;
  return res;
}

int main() {
  cin >> n;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  ans /= mint(2).pow(n);
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 29184
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)



int main() {
	int n,i = 0,j=0;
	long long int ans=0;
	cin >> n;
	vector<long long>a(n);
	rep(i, n) {
		cin >> a.at(i);
		
		if (a.at(i) == 0) {
			cout << 0<< endl;
			return 0;
		}
		
		
	}
	rep(i,n){
		if (a.at(i) > 1000000000) {
			ans++;
		}
	}
	if (ans == 2) {
		cout << -1 << endl;
		return 0;
	}
	ans = 1;
	rep(i, n) {
		ans *= a.at(i);
		if (ans > 1000000000000000000||ans==0) {
			cout << -1 << endl;
			return 0;
		}
	
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3976
n, m = map(int, input().split())
ac = [False] * n
wa = [0] * n

for _ in range(m):
  p, s = input().split()
  p = int(p) - 1
  if s == 'AC':
      ac[p] = True
  else:
      if not ac[p]:
          wa[p] += 1

a = 0
b = 0

for i in range(n):
    if ac[i]:
        a += 1
        b += wa[i]

print(*[a, b])

Measured memory_bytes: 4724
N,M=map(int,input().split())
abs_NM=abs(N-M)
if abs_NM>1:
    print(0)
    exit()

p=10**9+7
ans=1
for i in range(1,N+1):
    ans=(ans*i)%p
for i in range(1,M+1):
    ans=(ans*i)%p
if abs_NM==0:
    ans=(ans*2)%p

print(ans)

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long ans = 4;
		for(int i = 0; i < 4; i++)
			A = Math.min(A, sc.nextLong());
		ans += N / A;
		if(N % A != 0)
			ans += 1;
		System.out.println(ans);

	}

}

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

int main() {
	int n, k;
	char s[100001];
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	
	int c[100001];
	int p = 0;
	int q = 1;
	for (int i = 1; i < n; i++) {
		if (s[i] != s[i - 1]) {
			c[p] = q;
			q = 1;
			p++;
		}
		if (s[i] == s[i - 1]) {
			q++;
		}
	}

	c[p] = q;
	
	if (s[0] == '0') {
		int ans = 0;
		if (s[n - 1] == '0'&& k >= p / 2 + 1) {
			for (int i = 0; i <= p; i++) {
				ans += c[i];
			}
		}
		else if (s[n - 1] == '1'&&k >= (p + 1) / 2) {
			for (int i = 0; i <= p; i++) {
				ans += c[i];
			}
		}
		else {

			int l = 1;
			int r = 2 * k + 1;
			while (r <= p) {
				int pre = 0;
				for (int i = l; i <= r; i++) {

					pre += c[i];
					if (pre > ans)ans = pre;
				}
				l = l + 2;
				r = r + 2;
			}
			int pre = 0;
			for (int i = 0; i <= 2 * k - 1; i++) {

				pre += c[i];
				if (pre > ans)ans = pre;
			}
			if (s[n - 1] == '0') {
				int pre = 0;
				for (int i = p - 2 * k + 1; i <= p; i++) {

					pre += c[i];
					if (pre > ans)ans = pre;
				}
			}

			else {
				int pre = 0;
				for (int i = p - 2 * k; i <= p; i++) {

					pre += c[i];
					if (pre > ans)ans = pre;
				}
			}
		}
		cout << ans << endl;
	}

	else {
		int ans = 0;
		if (s[n - 1] == '1'&&k >= p / 2) {
			for (int i = 0; i <= p; i++) {
				ans += c[i];
			}
		}
		else if (s[n - 1] == '0'&&k >= (p + 1) / 2) {
			for (int i = 0; i <= p; i++) {
				ans += c[i];
			}
		}
		else {


			int l = 0;
			int r = 2 * k;
			while (r <= p) {
				int pre = 0;
				for (int i = l; i <= r; i++) {

					pre += c[i];
					if (pre > ans)ans = pre;
				}
				l = l + 2;
				r = r + 2;
			}



			if (s[n - 1] == '0') {
				int pre = 0;
				for (int i = p - 2 * k + 1; i <= p; i++) {

					pre += c[i];
					if (pre > ans)ans = pre;
				}
			}

			else {
				int pre = 0;
				for (int i = p - 2 * k; i <= p; i++) {

					pre += c[i];
					if (pre > ans)ans = pre;
				}
			}
		}
		cout << ans << endl;


	}


	return 0;
}

Measured memory_bytes: 768
n,k = map(int,input().split())
mod = 998244353

l,r = [0]*k,[0]*k
for i in range(k):
    ll,rr = map(int,input().split())
    l[i],r[i] = ll,rr

dp = [0]*(n+1)
dpsum = [0]*(n+1)
dp[1], dpsum[1] = 1,1
for i in range(2,n+1):
    for j in range(k):
        li = i - r[j]
        ri = i - l[j]
        if ri < 0:
            continue
        dp[i] += dpsum[ri] - dpsum[li-1]
        dp[i] %= mod
    dpsum[i] = dpsum[i-1] + dp[i]
print(dp[n])

Measured memory_bytes: 76588
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    double n,d,i,j,x,y,m,k,p;
    cin>>n>>d;
    int cunt=0;
    p = d*d;
    for(i=0; i<n; i++)
    {
        cin>>x>>y;
        m = x*x + y*y;

        if ( m <= p )
            cunt++;

    }

    cout<<cunt<<endl;

    return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

template <typename T1, typename T2>
inline bool chmin(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ll dp1[1000100], dp2[1000100];

void solve() {
    ll N, W;
    cin >> N >> W;
    Vl ws(N), vs(N);
    for (ll i = 0; i < N; i++) {
        cin >> ws[i] >> vs[i];
    }

    for (ll i = 0; i < N; i++) {
        swap(dp1, dp2);
        memset(dp2, 0, sizeof(ll) * W);
        for (ll j = 0; j <= W; j++) {
            dp2[j] = dp1[j];
            if (j - ws[i] >= 0)
                chmax(dp2[j], dp1[j - ws[i]] + vs[i]);
        }
    }

    prints()(dp2[W]);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(nullptr), cout.tie(nullptr);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 19284
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long int64;
int64 a,b;
int64 solve()
{
    int64 ret;
    int64 c,d=a*b;
    for(int64 i=sqrt(static_cast<long double>(d-1));i<max({a,b});i++)
    {
        if(d>i*i)c=i;
        else break;
    }
    ret=2*c;
    if(a<=c)ret-=1;
    if(b<=c)ret-=1;
    if(c*(c+1)>=d)ret-=1;
    return ret;
}
main()
{
    int q;
    cin>>q;
    while(q--)
    {
        cin>>a>>b;
        cout<<solve()<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  while(n!=0){
    int s=1,sum=0,e=1,o=0;
    while(e<=n){
      if(sum<n) {
	sum+=e;
	e++;
      }else if(sum==n){
	o++;
	sum+=e;
	e++;
      }else{
	sum-=s;
	s++;
      }
    }
    cout << o << endl;
    cin >> n;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int i;
   
    char s[11];
   
      
    scanf("%s", s);


    if( s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I' ){

        printf("Yes\n");

        return 0;

        }
   

    printf("No\n");


    return 0;
                                                          
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define BUF_SIZE 30

int get_int2(int *a1, uint64_t *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %llu", a1, a2);
#else
#error
#endif
  return 0;
}

#define WEIGHT_MAX 100000
#define NUM_MAX 100

struct product {
    int weight;
    uint64_t value;
};

#define max(a,b) ((a) > (b) ? (a) : (b))

int main(void) {
    int num;
    uint64_t wlimit;
    get_int2(&num, &wlimit);
    static uint64_t dp[NUM_MAX+1][WEIGHT_MAX+1];
    static struct product prods[NUM_MAX+1];

    int i, j;
    for(i = 1; i <= num; i++) {
        get_int2(&prods[i].weight, &prods[i].value);
    }

    for(i = 1; i <= num; i++) {
        int w = prods[i].weight;
        uint64_t v = prods[i].value;
        for(j = 1; j <= wlimit; j++) {
            dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            if(j >= w) {
                dp[i][j] = max(dp[i][j], dp[i-1][j-w]+v);
            }
        }
    }
    printf("%llu\n", dp[num][wlimit]);
    return 0;
}

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

int main()
{
  int N,h,count=0;

  cin >> N;

  int A[N];

  for(int i=1;i<=N;i++)
    {
      cin >> A[i];
    }

  int mini;
  for(int i=1;i<=N;i++)
    {
      mini=i;
      for(int j=i;j<=N;j++)
	{
	  if(A[j]<A[mini])
	    {
	      mini=j;
	    }
	}
      if(A[i] != A[mini])count++;
      h = A[i];
      A[i] = A[mini];
      A[mini] = h;  
    }

  for(int i=1;i<=N;i++)
    {
      cout << A[i];
      if(i != N)cout << " ";
    }
  cout  << endl << count << endl;

  return 0;
}

Measured memory_bytes: 0
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int x, y, s, i, j, max, m, a, b, c, d;

    for(;;){
      x = sc.nextInt(); y = sc.nextInt(); s = sc.nextInt();
      if(x == 0 && y == 0 && s == 0)break;
      max = -1; b = 0; c = 0; d = 0;
      for(i = 1;i < s;i++){
        a = i * (100 + x) / 100;
        for(j = 1;j < s;j++){
          b = j * (100 + x) / 100;
          if(a + b > s && c + d == s){
            j--; b = j * (100 + x) / 100; break;
          }
          c = i * (100 + x) / 100;
          d = j * (100 + x) / 100;
        }
        m = (i * (100 + y) / 100);
        m += (j * (100 + y) / 100);
        if(max < m && j > 0 && j < s)max = m;
      }
      out.println(max);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 20844
from collections import defaultdict
from itertools import combinations

N = int(input())
S = [input() for i in range(N)]

CHARS = "MARCH"

xs = defaultdict(int)

for s in S:
    xs[s[0]] += 1

def calc(xs):
    return sum(xs[a] * xs[b] * xs[c] for a, b, c in combinations(CHARS, 3))

print(calc(xs))


Measured memory_bytes: 10112
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

typedef long long ll;

int main(int argc, char* argv[])
{
  ll n;
  ll sum = 0;
  std::cin >> n;
  std::vector< ll > vs(n, 0);

  for (ll i = 0; i < n; i++) {
    ll tmp;
    std::cin >> tmp;
    vs[i] = tmp;
    sum += tmp;
  }

  std::sort(vs.begin(), vs.end());

  ll ans = sum;
  if (sum % 10 == 0) {
    for (ll i = 0; i < n; i++) {
      if (vs[i] % 10 != 0) {
	ans -= vs[i];
	break;
      }
    }
    if (ans == sum) ans = 0;
  }

  std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;
    ll a[(int)2e5+10];
    map<ll,ll> m;
int main()
{
    /*
	freopen(filename".in","r",stdin);
	freopen(filename".out","w",stdout);
	*/
	/*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    */
    /*
    ios::sync_with_stdio(0);
    */
    int n;
    cin>>n;
    int i;
    fo(i,n)
    {
        cin>>a[i];
        if (i)
        {
            a[i]+=a[i-1];
        }
    }
    ll o=0;
    m[0]++;
    fo(i,n)
    {
        o+=m[a[i]];
        m[a[i]]++;
    }
    cout<<o;
}


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

using namespace std;

const long long N = 1e5 + 5;
const long long INF = 1e18 + 9;

int main(){
    long long n, W; cin >> n >> W;

    vector<long long> w(n + 1), v(n + 1);
    for(long long i = 1; i <= n; i++){
    	cin >> w[i] >> v[i];
    }

	vector<vector<long long>> dp(n + 2, vector<long long>(N + 2, INF));
	dp[1][0] = 0;
	dp[1][v[1]] = w[1];
	for(long long i = 1; i <= n; i++){
		for(long long j = 0; j <= N; j++){
			dp[i][j] = min(dp[i][j], dp[i - 1][j]);
			if(j - v[i] >= 0){
				dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
			}
		}
	}

	for(long long i = N; i >= 0; i--){
		if(dp[n][i] <= W) return cout << i, 0;
    }
    	
    cout << 0;
	return 0;
}

Measured memory_bytes: 81024
//
// Created by yamunaku on 2019/09/21.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    mti ans(h,vi(w,0));
    vi aa(w);
    rep(i,a){
        aa[i]=h-b;
    }
    repl(i,a,w){
        aa[i]=b;
    }
    rep(i,b){
        int k=w-a;
        rep(j,w){
            if(k>0&&aa[j]>0){
                aa[j]--;
                ans[i][j]=1;
                k--;
            }
        }
    }
    repl(i,b,h){
        int k=a;
        rep(j,w){
            if(k>0&&aa[j]>0){
                aa[j]--;
                ans[i][j]=1;
                k--;
            }
        }
    }
    rep(i,h){
        rep(j,w){
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

const ll N=2505;
ll n,m,p,a,b,c;
vector<vi>re(N);
vector<vi>no(N);
vector<tuple<ll,ll,ll>>v;
bool vst[N];
bool r[N];
bool s[N];

void rfs(ll a){
    vst[a]=true;
    r[a]=true;
    for(auto x:re[a]){
        if(!vst[x])rfs(x);
    }
}

void nfs(ll a){
    vst[a]=true;
    s[a]=true;
    for(auto x:no[a]){
        if(!vst[x])nfs(x);
    }
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m>>p;
    while(m--){
        cin>>a>>b>>c;c-=p;c=-c;
        v.pb(mt(a,b,c));
        re[b].pb(a);
        no[a].pb(b);
    }
    rfs(n);mset(vst);nfs(1);
    ll dist[n+1];
    for(int i=1;i<=n;i++)dist[i]=INF;
    dist[1]=0;
    for(int i=1;i<=n;i++){
        for(auto e:v){
            tie(a,b,c)=e;
            if(dist[a]+c<dist[b]){
                dist[b]=dist[a]+c;
                if(s[b]&&r[b]&&i==n){cout<<"-1\n";return 0;}
            }
        }
    }
    cout<<max(0ll,-dist[n])<<"\n";
}


Measured memory_bytes: 768
s=input()
ans=chk=0
ans=[-1]*(len(s)+1)
if s[0]=="<":
    ans[0]=0
if s[-1]==">":
    ans[-1]=0
for i in range(len(s)-1):
    if s[i]==">" and s[i+1]=="<":
        ans[i+1]=0
for i in range(len(s)):
    if s[i]=="<":
        ans[i+1]=ans[i]+1
for i in range(-1,-len(s)-1,-1):
    if s[i]==">":
        ans[i-1]=max(ans[i-1],ans[i]+1)
print(sum(ans))


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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")

typedef long long ll;
typedef unsigned long long ull;
// typedef __int128_t lll;
#define fatnet ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

const ll MOD1 = 1e9 + 7;
const ll MOD2 = 2000003983; // 3571 1e9 + 97
const ll MOD3 = 1e9 + 9;
const ll p1 = 1e6 + 3;
const ll p2 = 2017; // 131 37
const ll p3 = 37;
const ll INF = 5e18;

int main() {
    fatnet;

    ll l, r;
    cin >> l >> r;
    if ((r / 3 - (l - 1) / 3) && (r / 673 - (l - 1) / 673)) {
        cout << 0 << "\n";
        return 0;
    }
    ll ans = 2018;
    for (ll i = l; i < r; ++i)
        for (ll j = l + 1; j <= r; ++j)
            ans = min(ans, (i * j) % 2019);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)

	a := nextInt()
	b := nextInt()
	h := nextInt()

	fmt.Println((a + b) * h / 2)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vii;
typedef vector<ll> vll;

#define X first
#define Y second
#define rep(i,n) for(ll i=0; i<(n); i++)
#define repp(i,ed,b) for(ll i=ed; i<=(b); i++)
#define repp2(i,b,ed) for(ll i=b; i>=(ed); i--)
#define fill(ed,val) memset(ed, (val), sizeof(ed))
#define mp make_pair
#define pb push_back
#define sz(x) (ll)x.size()
#define all(c) (c).begin(), (c).end()
#define uni(c) c.resize(distance(c.begin(), unique(all(c))))
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sc(n) scanf("%lld",&n)

ll mod= 1e9 + 7, mod1=1e9+9;
const ll N=100005,MAX=2e9+5;



int main()
{   
    io;
    
    int n,a,b;
    cin>>n>>a>>b;
    string s;
    cin>>s;
    int tot=0,cn=0;
    for(auto x:s){
        if(x=='a' and tot<a+b){cout<<"Yes\n";tot++;}
        else if(x=='b' and tot<a+b and cn<b){tot++,cn++;cout<<"Yes\n";}
        else cout<<"No\n";
    }
    
    
    return 0;
}

Measured memory_bytes: 848
import java.util.Scanner;

public class Main{
	public static TreeNode[] node = null;
	public static void main(String[] args) {
		int num;
		Scanner sc = new Scanner(System.in);
		num = sc.nextInt();
		node = new TreeNode[num];
		for(int i=0;i<num;i++) {
			node[i] = new TreeNode();
		}
		for(int i=0;i<num;i++) {
			int parent =sc.nextInt();
			int left = sc.nextInt();
			int right = sc.nextInt();
			node[parent].left = left;
			node[parent].right = right;
			if(left!=-1) {
				node[left].parent = parent;
			}
			if(right!=-1) {
				node[right].parent = parent;
			}
			
		}	
		
		for(int i=0;i<num;i++) {
			int parent = node[i].parent;
			if(parent==-1) {
				System.out.println("Preorder");
				PreOrder(i);
				System.out.println();
				System.out.println("Inorder");
				InOrder(i);
				System.out.println();
				System.out.println("Postorder");
				PostOrder(i);
				System.out.println();
				break;
			}
	
		}
	}
	
	public static void PreOrder(int i) {
		if(i==-1) {
			return;
		}
		System.out.print(" "+i);
		PreOrder(node[i].left);
		PreOrder(node[i].right);
		
	}
	
	public static void InOrder(int i) {
		if(i==-1) {
			return;
		}
		InOrder(node[i].left);
		System.out.print(" "+i);
		InOrder(node[i].right);
	}

	public static void PostOrder(int i) {
		if(i==-1) {
			return;
		}
		PostOrder(node[i].left);
		PostOrder(node[i].right);
		System.out.print(" "+i);
}
}

class TreeNode {
	public int parent;
	public int left;
	public int right;

public TreeNode() {
	parent = -1;
}
}




Measured memory_bytes: 26468
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
int n,l,a[205];
int ans,now,tmp,res;
int main()
{
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;++i)
	{
		a[i]=l+i-1;
		ans+=a[i];
	}
	tmp=INF;
	for(int i=1;i<=n;++i)
	{
		now=ans-a[i];
		if(abs(ans-now)<tmp)
		{
			tmp=abs(ans-now);
			res=now;
		}
	}
	printf("%d\n",res);
	return 0;
} 

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

c = {'r': P, 's': R, 'p': S}
ans = 0
for j in range(K):
    for i in range(j, N, K):
        if i == j:
            con = 1
            ans += c[T[i]]
        elif T[i] == T[i - K]:
            con += 1
            if con % 2 == 1:
                ans += c[T[i]]
        else:
            con = 1
            ans += c[T[i]]

print(ans)


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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long unsigned int
#define vi vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define vii vector<pii>
#define pb push_back
#define B begin()
#define E end()
#define sz(A) (ll)(A).size()
#define F first
#define S second
#define loop(z, v) for(auto &z: v)
#define sp << ' ' << 
#define sps << ' '
#define nl "\n"
// #define nl endl
#define fat 1000000007
// #define fat 998244353

int main()
{
    boost;
    ll tt = 1, n, m, i, j, x, y, a ,b , c ,d;
    bool poss = true;

    // cin >> tt;
    for(int _ = 1; _ <= tt; _++){
        // cout << "Case #" << _ << ": ";
        cin >> a >> b >> c >> d;

        int req1 = ceil((1.0*c) / b);
        int req2 = ceil((1.0*a) / d);

        if(req1 <= req2){
            cout << "Yes" << nl;
        }
        else cout << "No" << nl;
    }   
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;
//#define int long long

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

//互除法
ll gcd(ll a, ll b) {
	if (a < b) {
		return gcd(b, a);
	}
	else if (a%b) {
		return gcd(b, a%b);
	}
	else {
		return b;
	}
}

//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b; // Be careful not to overflow

}

//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor(int n) {
	map<int, int> res; // map[i]:=ｎを素因数分解したときiは何乗か。
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n] = 1;
	return res;
}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor_ver2(int n, map<int, int> res) {
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n]++;
	return res;
}


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

	string s;
	int N;
	int x1 = 0, x2 = 0, y1 = 0, y2 = 0;
	bool flgx;
	bool flgy;

	cin >> s;
	N = (int)s.length();

	for (int i = 0; i < N; i++)
	{
		if (s[i] == 'N') {
			x1++;
		}
		if (s[i] == 'S') {
			x2++;
		}
		if (s[i] == 'E') {
			y1++;
		}
		if (s[i] == 'W') {
			y2++;
		}
	}

	if ((x1 > 0 && x2 > 0) || (x1 == 0 && x2 == 0)) {
		flgx = true;
	}
	else {
		flgx = false;
	}
	if ((y1 > 0 && y2 > 0) || (y1 == 0 && y2 == 0)) {
		flgy = true;
	}
	else {
		flgy = false;
	}

	if (flgx&&flgy) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl '\n'
//pair<int, int> *p=new pair<int, int>[n];
//std::vector<pair<int,int>> vp;
//v.push_back(make_pair(x,y))
//pair<int, int> p[1000001];
//string *s=new string [n];
//int freq[e];
//freq[a[i]-'a']++; freq[a[i]]++;
 using namespace std;
ll n,t,m,c1,c2,c,x,y,sum,mn=999999999,avg,pos,dif,j,dis,mx,xi,yi,q;
vector<ll>v;
set<string>s;
map<ll , ll >mp;
bool PE(int x)
{
for (int i=2;i*i<=x;i++)
if (x%i==0)
return false;
return true;
}
bool PR(string s)
{
int n=s.length();
for(int i=0;i<n/2;i++)
if(s[i]!=s[n-i-1])
return false;
return true;
}

int main(void)
{ SpeeD;
ll a,b,c,d;
cin>>a>>b>>c>>d;
while (a>0&&b>0&&c>0&&d>0)
{
   c-=b;
   if (c<=0)break;
   a-=d;
    if (a<=0)break;
   
 
}
if (c<=0)cout<<"Yes";
else cout<<"No";
}


Measured memory_bytes: 3656
import math
import copy
import sys
import bisect
input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    #x,y = map(int,input().split())	x=1,y=2
    #a = input().split()	a=['1','2','3',...,'n']
    #a = list(map(int,input().split()))	a=[1,2,3,4,5,...,n]
    #li = input().split('T')	FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    #複数行の「1 2 3 4」型の入力を一配列に
    #x = sorted([list(map(int, input().split())) for _ in range(n)])
    #ソート x.sort(key=lambda y:y[1])
    # print("Yes")  print("No")  
    n=int(input())
    a = list(map(int,input().split()))
    a.append(0)
    x=[abs(a[0])]
    for i in range(n):
        x.append(abs(a[i]-a[i+1]))
    y=[abs(a[1])]
    for i in range(n-1):
        y.append(abs(a[i]-a[i+2]))
    S=sum(x)
    for i in range(n):
        print(S-x[i]-x[i+1]+y[i])

main()

Measured memory_bytes: 57888
Item = Struct.new(:w, :v)
 
n, w = gets.split.map(&:to_i)
items = n.times.map {Item[*gets.split.map(&:to_i)]}
 
# dp[i][sum_w]
dp = Array.new(w+1, 0)
dp1 = Array.new(w+1, 0)
#dp = (n+1).times.map {Array.new(w+1, 0)}
(1..n).each do |i|
    item = items[i-1]
    (0..w).each do |u|
        dp[u] = [
            u >= item.w ? dp1[u-item.w] + item.v : 0,
            dp1[u]
        ].max
    end
    #dp1に前の重さを記録しておく
    dp, dp1 = dp1,dp
end
 
puts dp1[w]

Measured memory_bytes: 15828
#include <bits/stdc++.h>
#include <set>
#include <queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define reps(i, s, n) for (int i = s; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl
#define readVarll(nam) ll nam; cin >> nam

ll x[20],y[20];
ll n;

double calc1()
{
  int tmp[n];

  rep(i, n)
  {
    tmp[i] = i;
  }

  double sum = 0;
  int cnt = 0;
  do{
    
    reps(i, 1, n)
    {
      sum += sqrt(pow(x[tmp[i]] - x[tmp[i-1]], 2) + pow(y[tmp[i]] - y[tmp[i-1]], 2));
    }
    cnt++;
  }while(next_permutation(tmp, tmp+n));

  return sum / cnt;
}

int main()
{
  cin >> n;
  
  repl(i, n)
  {
    cin >> x[i] >> y[i];
  }
 
  cout << fixed << setprecision(15) << calc1() << endl;
  return 0;
}

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

int main(){
    int R;
    cin>>R;
    if(R<1200){
        cout<<"ABC"<<endl;
    }else if(R<2800){
        cout<<"ARC"<<endl;
    }else{
        cout<<"AGC"<<endl;
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) {
     cin >> a.at(i);
    }
    
    int sum = 0;
    rep(i,n) {
     rep(j,n){
         if(i == j){
         continue;
         }
     sum += a.at(i) * a.at(j);
     }
    }
    
    cout << sum / 2;
    
}

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

int N;
int a[100010];

void solve()
{
	int i;
	sort(a, a+N);
	if(a[N-1] - a[0] > 1){
		printf("No\n");
		return ;
	}
	if(a[N-1] == a[0]){
		if(N/2 >= a[0] || N==a[0]+1)
			printf("Yes\n");
		else
			printf("No\n");
		return ;
	}
	int cnt = 0;
	for(i=0; i<N; i++){
		if(a[i] == a[0])
			cnt ++;
	}
	if(a[N-1] == a[N-2] && cnt == a[0]){
		printf("Yes\n");
		return ;
	}
	if(a[N-1] == a[N-2]){
		int x = a[0]-cnt;
		if(x >= 1){
			if( (N-cnt)/2 > x){
				printf("Yes\n");
				return ;
			}
		}
	}
	printf("No\n");
}

int main()
{
	int i;
	scanf("%d", &N);
	for(i=0; i<N; i++)
		scanf("%d", &a[i]);
	solve();
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> v(N);
  for(int i=0;i<N;i++){
    cin>>v.at(i);
  }
  sort(v.begin(),v.end());
  double x=(v.at(0)+v.at(1))/2.0;
  for(int i=2;i<N;i++){

    x=(x+v.at(i))/2.0;
  }
  cout<<x<<endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int n;
  cin >> n;
  int ans=0;
  REP(i,n){
    int a;
    cin >> a;
    while(a>0){
      if(a%2==0)ans++;
      else break;
      a/=2;
    }
  }
  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(){
    int x,y;
    cin >> x >>y;
    bool can =false;
    for(int i =0; i <=y/2; i++) {
     if (2*i+4*(x-i)==y){
         can = true;
         break;
     }
    }
    
if(can) cout << "Yes" << endl;
else cout << "No" << endl;
}







Measured memory_bytes: 3632