akhauriyash/Code-Regression huggingface dataset:
X,Y = map(int,input().split())
mod = 10**9+7
if (2*X-Y) % 3 != 0 or (2*Y-X) % 3 != 0:
    print(0)
    exit(0)
x,y = (2*Y-X)//3,(2*X-Y)//3
if x < 0 or y < 0:
    print(0)
    exit(0)
N = x+y
K = min(x,y)
def pow(x, n, mod):
    ret = 1
    while n>0:
        if (n&1):
            ret = (ret*x) % mod
        x = (x*x) % mod
        n >>= 1
    return ret
fact = [0]*(N+1)
fact[0] = 1
for i in range(1, N+1):
    fact[i] = (fact[i-1]*i) % mod
finv = [0]*(N+1)
finv[N] = pow(fact[N], mod-2, mod)
for i in range(N, 0, -1):
    finv[i-1] = (finv[i]*i) %mod
print((fact[x+y]*finv[x]*finv[y]) % mod)

Measured memory_bytes: 49136
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
	fast;
	ll arr[5],diff[5]{},sum=0,cnt=0;
	for(int i=0;i<5;i++)
		cin>>arr[i],diff[i]=arr[i]%10;
	sort(diff,diff+5);
	for(int i=0;i<5;i++)
		if(arr[i]%10==0)
			cnt++;
	for(int i=0;i<5;i++)
		sum+=arr[i]-arr[i]%10;
	for(int i=4;i>cnt;i--)
		if(diff[i]!=0)
			sum+=10;
	if(cnt!=5)
	cout<<sum+diff[cnt];
	else
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3632
def LI():
    return list(map(int, input().split()))


N, total = LI()
a = LI()
Nlist = [0]*N
a.sort()
ans = 0
if sum(a) == total:
    ans = N
elif sum(a) < total:
    ans = N-1
else:
    for i in range(N):
        if total == a[i]:
            ans += 1
            break
        elif total > a[i]:
            ans += 1
            total -= a[i]
        else:
            break
print(ans)


Measured memory_bytes: 9084
#include <iostream>
#include <algorithm>
#include <string>
#include <bits/stdc++.h>

using namespace std;

int main(){
  int N, cnt=0;
  cin >> N;
  while (N > 0){
    N >>= 1;
    cnt ++;
  }
  cout << pow(2, cnt-1) << endl;
  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> checked(N, -1);
  int result = 0;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    int ind = N - s[i];
    if (checked[ind] != -1) {
      if (checked[ind] != c[i]) {
        result = -1;
        break;
      }
    } else {
      if (N > 1 && s[i] == 1 && c[i] == 0) {
        result = -1;
        break;
      }
      checked[ind] = c[i];
      result += pow(10, ind)*c[i];
    }
  }
  if (N > 1 && result != -1 && checked[N-1] == -1) {
      result += pow(10, N-1);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			long l = cin.Long();
			long r = cin.Long();
			long num = r - l + 1;
			long nn = Math.Min(num, 2019);
			long[] a = new long[nn];
			for (int i = 0; i < nn; i++) {
				a[i] = (l + i) % 2019;
			}

			long ans = 2020;
			for (int i = 0; i < nn; i++) {
				for (int j = i + 1; j < nn; j++) {
					long v = (a[j] * a[i]) % 2019;
					if (v < ans) {
						ans = v;
					}
				}
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}


		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 11220
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		String n = scan.nextLine();
		String[] list = n.split("");
		String answer = "No";
		if(list[0].equals(list[1]) && list[0].equals(list[2])) {
				answer = "Yes";
		}else if(list[1].equals(list[2]) && list[1].equals(list[3])){
				answer = "Yes";
		}

		System.out.println(answer);
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i=0,n,p=0,y=0,w=0,g=0;
  cin>>n;
  
  
  while(i<n){
    string a;
    cin>>a;
    
    if(a=="G"&&g==0){      
        g++;
      }      
     else if(a=="P"&&p==0){      
        p++;
      }       
     else if(a=="W"&&w==0){
        w++;
      }       
     else if(a=="Y"&&y==0){
        y++;
      }
       
      i++;            
     }
              
   if(p+g+y+w==3){
         cout<<"Three"<<endl;
       }
   else if(p+g+y+w==4){
         cout<<"Four"<<endl;
       }           
}

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

typedef long long ll;

int main()
{
    ll n;
    cin >> n;
    ll x;
    set<ll> s;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        s.insert(x);
    }
    int ans = s.size();
    if (ans % 2 == 0)
    {
        ans -= 1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <iostream>

int main() {
    int top;
    int bottom;
    int hieght;

    std::cin >> top >> bottom >> hieght;
    if(hieght%2 != 0){
        return 0;
    }
    std::cout << (top + bottom) * hieght / 2  << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >>d;
    REP(i,100){
        c-=b;
        if(c<=0){
            cout << "Yes" << endl;
            return 0;
        }
        a-=d;
        if(a<=0){
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}

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


int main(){
  int N , K ; cin >> N >> K ; 
  vector<long long> h(N) ; 
  for(int i = 0 ; i < N ; i++) cin >> h.at(i) ; 
  
  sort(h.begin(),h.end()) ; 
  
  long long ans = 10e9 ;
  for(int i = 0 ; i <= N-K ; i++){
    ans = min(ans , abs(h.at(i)-h.at(i+K-1))) ; 
  }
  
  cout << ans << endl; 
}

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

int main() {
	int Arrey[3];
	int CountIt5 = 0;
	int CountIt7 = 0;
	cin >> Arrey[0] >> Arrey[1] >> Arrey[2];
	for (int i = 0;i < 3;i++) {
		if (Arrey[i] == 5) {
			CountIt5++;
		}if (Arrey[i] == 7) {
			CountIt7++;
		}
	}
	if (CountIt5 == 2 && CountIt7 == 1) {
		cout << "YES" << endl;
		return 0;
	}
	else
	{
		cout << "NO" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String orig = sc.nextLine();
		sc.close();
		String[] arr = orig.split(" ", 2);
		int[] nums = new int[2];
		for (int i = 0; i < arr.length; i++)
			nums[i] = Integer.parseInt(arr[i]);
		if (nums[0] == nums[1]) {
			System.out.println(nums[0]);
		}
		else if (nums[0] > nums[1]) {
			System.out.println(gcd(nums[1], nums[0] % nums[1]));
		}
		else {
			System.out.println(gcd(nums[0], nums[1] % nums[0]));
		}
	}
	
	public static int gcd(int x, int y) {
		int n = 1;
		for(int i = 1; i <= x && i <= y; i++) {
			if(x % i == 0 && y % i == 0) n = i;
		}
		return n;
	}
}


Measured memory_bytes: 26164
X, Y, A, B, C = map(int, input().split())
A =  list(map(int, input().split()))
B =  list(map(int, input().split()))
C =  list(map(int, input().split()))

total = C
A.sort()
A.reverse()
B.sort()
B.reverse()

for i in range(X) :
  total.append(A[i])
  
for j in range(Y) :
  total.append(B[j])

total.sort()
total.reverse()
ans = sum(total[0 : X + Y])
print(ans)

Measured memory_bytes: 23328
#include "bits/stdc++.h"
using namespace std;

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

#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())

#define ll long long
#define ALL(a)  (a).begin(),(a).end()

#define pb(a) push_back(a)
#define MOD 1000000007

int now,n,k;


int main(){
  int ans=0;
  cin >> n ;
  vector<int> w(n);
  vector<int> ar(n);
  
  REP(i,n)cin>>w[i];
  REP(i,n){
    int sum1 = accumulate(w.begin(),w.begin() + i,0);
    int sum2 = accumulate(w.begin()+i,w.begin() + n,0);
    ar[i]=abs(sum1-sum2);
  }
  sort(ar.begin(), ar.end());



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

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] array = new int[n];
    int sum = 0;

    for(int i=0; i<n; i++){
      array[i] = sc.nextInt();
      sum += array[i];
    }

    int p=0;
    p = sum/n;
    if((double)sum/n-sum/n!=0){
      if(sum/n+1-(double)sum/n > (double)sum/n-sum/n){
        p = sum/n;
        if(p==0){p=1;}
      }else{
        p = sum/n + 1;
        if(p==101){p -= 1;}
      }
    }
    //System.out.println((double)sum/n);

    long ans = 0;

    for(int a: array){
      ans += (a-p) * (a-p);
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 22996
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		int[] X = new int[N];
		for(int i = 0; i < K; i++) {
			int M = sc.nextInt();
			for(int j = 0; j < M; j++) {
				X[sc.nextInt() - 1]++;
			}
		}
		
		int count = 0;
		for(int i = 0; i < N; i++) {
			if(X[i] == 0)count++;
		}
		System.out.println(count);
		sc.close();
	}
}

Measured memory_bytes: 46492
from bisect import bisect_right
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    x = int(readline())

    A = [i**5 for i in range(10**6)]
    for b in A:
        a = x + b
        idx = bisect_right(A, a) - 1
        if A[idx] == a:
            print(int(pow(a, 0.2)), int(pow(b, 0.2)))
            break
        
        a = x - b
        idx = bisect_right(A, a) - 1
        if A[idx] == a:
            print(int(pow(a, 0.2)), -int(pow(b, 0.2)))
            break


if __name__ == "__main__":
    main()


Measured memory_bytes: 64788
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#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 inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl

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

int s, a, ans;
int i = 0;
vector<int> v;
bool flag = false;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    while(1){
        if(i == 0) {
            a = s;
            v.push_back(a);
            i++;
        }
        else{
            if(a%2 == 0) a = a/2;
            else a = 3*a + 1;
            v.push_back(a);
            for(int j = i-1; j>=0; j--){
                if(v[j] == v[i]){
                    ans = i + 1;
                    flag = true;
                }
                else continue;
            }
            i++;
        }
        if(flag == true) break;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
using namespace std;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,n,0)

typedef long long ll;
typedef vector<int> VI;

const int _N = 1e5;

struct edge{
  int to, cost;  
};

int n, q, k;
vector<edge> edges[_N];
ll dist[_N];
bool did[_N];
void dfs(int x, ll d){
    if(did[x])return;
    did[x] = true;
    dist[x] = d;
    REP(i, edges[x].size()){
        dfs(edges[x][i].to, d + edges[x][i].cost);
    }
}
int main(){
    cin >> n;
    REP(i, n - 1){
        int a,b,c;
        cin >> a >> b >> c;
        a--;b--;
        edges[a].push_back((edge){b, c});
        edges[b].push_back((edge){a, c});
    }
    cin >> q >> k;
    k--;
    dfs(k, 0);
    REP(i, q){
        int x,y;
        cin >> x >> y;
        x--;y--;
        cout << dist[x] + dist[y] << endl;
    }
}


Measured memory_bytes: 12800
#include <iostream>
#include <cstdint>

using namespace std;

u_int64_t twos(u_int64_t n);

int main()
{
    int N;
    u_int64_t a[10'000];

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

    u_int64_t sum = 0;
    for (int i = 0; i < N; i++)
    {
        sum += twos(a[i]);
    }

    cout << sum << endl;
    return 0;
}

u_int64_t twos(u_int64_t n)
{
    int acc = 0;

    while (n % 2 == 0)
    {
        acc++;
        n /= 2;
    }

    return acc;
}

Measured memory_bytes: 384
def main():
    n = int(input())
    ab = [None for _ in range(n)]
    for i in range(n):
        ab[i] = list(map(int, input().split()))

    ab.sort(key=lambda x: x[0])
    if n % 2 == 0:
        median_min1 = ab[n//2-1][0]
        median_min2 = ab[n//2][0]
    else:
        median_min1 = ab[n//2][0]
        median_min2 = ab[n//2][0]

    ab.sort(key=lambda x: x[1])
    if n % 2 == 0:
        median_max1 = ab[n//2-1][1]
        median_max2 = ab[n//2][1]
    else:
        median_max1 = ab[n//2][1]
        median_max2 = ab[n//2][1]

    if n % 2 == 0:
        ans = (median_max1 + median_max2) - (median_min1 + median_min2) + 1
    else:
        ans = median_max1 - median_min1 + 1

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 48640
conv = {
  '11' => 'a', '12' => 'b', '13' => 'c', '14' => 'd', '15' => 'e',
  '21' => 'f', '22' => 'g', '23' => 'h', '24' => 'i', '25' => 'j',
  '31' => 'k', '32' => 'l', '33' => 'm', '34' => 'n', '35' => 'o',
  '41' => 'p', '42' => 'q', '43' => 'r', '44' => 's', '45' => 't',
  '51' => 'u', '52' => 'v', '53' => 'w', '54' => 'x', '55' => 'y',
  '61' => 'z', '62' => '.', '63' => '?', '64' => '!', '65' => ' '
}

while line = gets
  encode = line.chomp

  decode = ''
  if encode.length % 2 == 0
    encode.each_char.each_slice(2).map(&:join).each do |str|
      if conv[str].nil?
        decode = :NA
        break
      end
      decode += conv[str]
    end
  else
    decode = :NA
  end

  puts decode
end

Measured memory_bytes: 8808
// 失敗するからこそ そこから立ち向かって行く強さがあって そんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/pavan/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int main(){
	FIO
	
	string s;cin >> s;
	string t(s.size(),'x');
	cout << t;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < n ; i++){
            a[i] = sc.nextInt();
        }

        for(int i = 0; i < n ; i++){
            System.out.print(a[n - i - 1]);
            if(i != n - 1)System.out.print(' ');
        }
        System.out.println();
        sc.close();
    }
}



Measured memory_bytes: 26284
#include "bits/stdc++.h"
using    namespace std;
typedef  long double ld;
#define  int long long
typedef  pair<int,int> pii;
#define  RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  rep(i,n) for(i=0; i <n; i++)
#define  repv(i,k,n) for(int i=k; i<=n; i++)
#define  pb push_back
#define  mp make_pair
#define  F  first
#define  S  second
#define  sz(x)  (int)x.size()
#define  all(v) v.begin(),v.end()
#define  endl '\n'
#define  deb(x) c out<<#x<<" = "<<x<<endl
#define  gcd   __gcd
#define  inf   LLONG_MAX
#define  minf  LLONG_MIN 
#define  sp(n) fixed<<setprecision(n)
const int mod = (int)(1e9+7);
int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
int pct(int x)
{   return __builtin_popcountll(x);}
int  lcm(int a,int b){return a*b/gcd(a,b);}
bool is_power_2(int n){ return log2(n)==floor(log2(n));}
bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}
void db()
{   
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
void timeit()
{  
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " <<sp(5)<< 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}
int     dx []    =  {-1 , 0 , 1 , 0 ,-1,-1, 1,  1};
int     dy []    =  { 0 , 1 , 0 ,-1 ,-1, 1, 1, -1};
char    dir[]    =  {'U','R','D','L'};
/* ---------------------- ar.cpp --------------------------------- */
const int maxn = 1e6+5;
void solve(int tc)
{
    //  cout<<"Case #"<<tc<<":\n";
    int n,i,j,k,m,q,l,r;
    cin>>n>>k;
    int ar[n+1];
    repv(i,1,n)
        cin>>ar[i];
    repv(i,k+1,n)
        (ar[i] > ar[i-k])?cout<<"Yes\n":cout<<"No\n";
}  
signed main()
{
    // ar.cpp 
    RAGE;
  //  db();    
    int t=1;
    //cin>>t;
    for(int i=1; i<=t; i++)
    {
        solve(i);
    }
 //   timeit();
    return 0;
}

Measured memory_bytes: 5248
package main

import (
	"fmt"
	"math"
)

func isInt(x float64) bool {
	return float64(int(x)) == x
}

func digits(x int) int {
	switch {
	case x < 10:
		return 1
	case x < 100:
		return 2
	case x < 1000:
		return 3
	case x < 10000:
		return 4
	case x < 100000:
		return 5
	case x < 1000000:
		return 6
	case x < 10000000:
		return 7
	case x < 100000000:
		return 8
	case x < 1000000000:
		return 9
	case x < 10000000000:
		return 10
	default:
		return 999
	}
}

func max(a, b float64) float64 {
	if a > b {
		return a
	}
	return b
}

func main() {
	var n float64
	fmt.Scan(&n)

	var b float64
	ans := 9999
	for a := 1.0; a <= math.Sqrt(n); a++ {
		b = n / a
		if !(isInt(b)) {
			continue
		}
		if x := digits(int(max(a, b))); x < ans {
			ans = x
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

class Main{

	static char[][] map;
	static int H;
	static int W;
	static	int D ;
	static	int G ;
	static	int[] p;
	static	int[] c;
	static int ans = 100000000;

	public static void main(String[] args) {



		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int[] x = new int[N];
		int[] y = new int[M];

		for(int i = 0;i < N;i++){
			x[i] = sc.nextInt();
		}
		for(int i = 0;i < M;i++){
			y[i] = sc.nextInt();
		}

		Arrays.sort(x);
		Arrays.sort(y);
		for(int i = X+1;i <= Y;i++){
			if(x[N-1] < i && y[0] >= i){
				System.out.println("No War");
				return;
			}

		}
		System.out.println("War");



	}



}





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

int main(){
  int N, A;
  cin >> N >> A;
  
  if(N % 500 == 0){
    cout << "Yes" << endl;
  }else{
    int rest = N % 500;
    if(rest <= A){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
n, m = input().split()
n = int(n)
m = int(m)
h = list(map(int, input().split()))

t = [n + 1]*n
for i in range(m):
	a, b = input().split()
	a = int(a) -1
	b = int(b) -1
	if h[a] >= h[b]:
		t[b] = b
	if h[b] >= h[a]:
		t[a] = a

print(t.count(n+1))
		
	
	

Measured memory_bytes: 19996
# Solution reference: https://betrue12.hateblo.jp/entry/2019/07/05/012450
# Dinic reference: https://atcoder.jp/contests/abc091/submissions/5569121
class Dinic
  attr_accessor :g
  def initialize(v, inf = 2 ** 30)
    @V = v
    @inf = inf
    @g = Array.new(v) { [] }
    @level = Array.new(v, 0)
    @iter = Array.new(v, 0)
  end

  def add_edge(from, to, cap)
    @g[from] << {"to" => to, "cap" => cap, "rev" => @g[to].size}
    @g[to] << {"to" => from, "cap" => 0, "rev" => @g[from].size - 1}
  end

  def max_flow(s, t)
    flow = 0
    loop do
      bfs(s)
      return flow if @level[t] < 0
      @iter = Array.new(@V, 0)
      f = dfs(s, t, @inf)
      while f > 0
        flow += f
        f = dfs(s, t, @inf)
      end
    end
  end

  private
    def bfs(s)
      @level = Array.new(@V, -1)
      @level[s] = 0
      q = [s]
      until q.empty?
        v = q.shift
        @g[v].size.times do |i|
          e = @g[v][i]
          if e["cap"] > 0 && @level[e["to"]] < 0
            @level[e["to"]] = @level[v] + 1
            q << e["to"]
          end
        end
      end
    end

    def dfs(v, t, f)
      return f if v == t
      (@iter[v]...@g[v].size).each do |i|
        @iter[v] = i
        e = @g[v][i]
        if e["cap"] > 0 && @level[v] < @level[e["to"]]
          d = dfs(e["to"], t, [f, e["cap"]].min)
          if d > 0
            e["cap"] -= d
            @g[e["to"]][e["rev"]]["cap"] += d
            return d
          end
        end
      end
      0
    end
end

INF = 10 ** 100
n = gets.to_i
dinic = Dinic.new(n + 2)
s = n
t = s + 1
jewels = gets.split.map(&:to_i)
reward = 0
# 罰金化して最小カット問題に帰着
jewels.each_with_index do |jewel, index|
  if jewel > 0
    reward += jewel
    # 残したら罰金 0
    dinic.add_edge(s, index, 0)
    dinic.add_edge(index, t, jewel)
  else
    dinic.add_edge(s, index, -jewel)
    # 割ったら罰金 0
    dinic.add_edge(index, t, 0)
  end
end

# 制約違反の時に、グラフがカットされないように INF の罰金を張る
1.upto(n) do |index|
  ngs = (index * 2).step(n, index).to_a
  ngs.each do |ng|
    dinic.add_edge(index - 1, ng - 1, INF)
  end
end

puts reward - dinic.max_flow(s, t)


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


void solve(int N, int M, vi& u, vi& v, vvi& nxt) {
    assert(N >= 2);

    deque<int> path;
    vector<bool> visited(N, false);

    // int s = 0, g = 1;
    path.push_front(0);
    visited[0] = true;

    path.push_back(nxt[0][0]);
    visited[nxt[0][0]] = true;

    while (true){
        int new_s = -1;
        for (int v: nxt[path.front()]) {
            if (visited[v]) continue;
            else { new_s = v; break; }
        }
        if (new_s == -1) break;

        path.push_front(new_s);
        visited[new_s] = true;
    }
    while (true){
        int new_g = -1;
        for (int v: nxt[path.back()]) {
            if (visited[v]) continue;
            else { new_g = v; break; }
        }
        if (new_g == -1) break;

        path.push_back(new_g);
        visited[new_g] = true;
    }

    cout << path.size() << endl;
    while (!path.empty()) {
        cout << 1+path.front();
        path.pop_front();
        if (!path.empty()) cout << " ";
    }
    cout << endl;
    return;
}

int main() {
    int N, M; cin >> N >> M;
    vi u(M), v(M);
    vvi nxt(N);
    rep(i,M) {
        int ui, vi; cin >> ui >> vi;
        --ui; --vi;
        nxt[ui].push_back(vi);
        nxt[vi].push_back(ui);
        u[i] = ui; v[i] = vi;
    }
    solve(N,M,u,v,nxt);
    return 0;
}


Measured memory_bytes: 7552
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private void doIt() {
		Scanner sc = new Scanner(System.in);
		boolean [] data = new boolean[1000001];
		while(true){
			int n = sc.nextInt();
			int a = sc.nextInt();
			int b = sc.nextInt();
			Arrays.fill(data, false);
			if(n==0 && a == 0 && b == 0){
				break;
			}
			data[0] = true;
			int count = 0;

			for(int i=0; i <= n; i++){
				if(data[i]){
					if(i + a <= n) data[i+a] = true;
					if(i + b <= n) data[i+b] = true;
				}
				else{
					count++;
				}
			}
			System.out.println(count);
		}

	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();

	}

}

Measured memory_bytes: 13000
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#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 X, t;
    cin >> X >> t;

    if (X - t <= 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << X - t << endl;
    }
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), q = scanner.nextInt();
			int[] bottom = new int[n], right = new int[n];
			Arrays.fill(bottom, n);
			Arrays.fill(right, n);
			long result = (n - 2) * (long) (n - 2);
			int h = n, w = n;
			for (int i = 0; i < q; i++) {
				int command = scanner.nextInt(), x = scanner.nextInt();
				if (1 == command) {
					if (x < w) {
						Arrays.fill(bottom, x, w, h);
						w = x;
					}
					result -= bottom[x] - 2;
				} else {
					if (x < h) {
						Arrays.fill(right, x, h, w);
						h = x;
					}
					result -= right[x] - 2;
				}
			}
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 61232
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B;
	cin >> A >> B;
	int ans = 0;
	for(int i = A; i <= B; i++) {
		string tmp = ts(i);
		if(tmp[0] == tmp[4] && tmp[1] == tmp[3]) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int Count(int* n){
  int i,count=0;
	for(i=0;i<3;i++){
		if (n[i] == 1){
  			count++;
		}
    }
  return count;
}

int main() {
  int num,a,b,c,ans=9;
  cin >> num;
  a=num/100;
  if (num == 000 || num == 001 || num == 101 || num == 100) {
    b=0;
  }else {
  	b=1;
  }
  c=num%10;   
  int n[3]={a,b,c};
  ans = Count(n);
  cout << ans << endl;
}

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

int main () {
  
  vector<string> line(3) ;
  
  for ( int i = 0 ; i < 3 ; i++ ) {
    cin >> line.at(i) ;
  }
  
  char dif = 'A' - 'a' ;
  
  char a = line.at(0).at(0) + dif ;
  char b = line.at(1).at(0) + dif ;
  char c = line.at(2).at(0) + dif ;
  
  cout << a << b << c << endl ;
}

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
N,P = map(int,input().split())
ans = 1
for i in factorization(P):
  if i[1] >= N:
    ans *= i[0]**(i[1]//N)
print(ans)
  

Measured memory_bytes: 9468
#include<bits/stdc++.h>
#define FILEIN freopen("input.txt", "r", stdin)
using namespace std;

#define ll long long
#define endl "\n"

const ll INF = 1e9;

int main(){
    // FILEIN;
    vector<int> q;
    int a = 0, ans = INF, n;
    cin>>n;
    q.resize(n);
    for(auto &i : q){
        cin>>i;
        a += i;
    }
    a = ceil(a/n);
    for(int j = -100; j <= 100; j++){
        int ans1 = 0;
        for(auto i : q){
            ans1 += (i - j)*(i - j);
        }
        ans = min(ans, ans1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())

reds =[list(map(int,input().split())) for i in range(n)]
blues = [list(map(int,input().split())) for i in range(n)]
reds.sort(key=lambda x: x[1],reverse=True)
blues = sorted(blues)
count = 0

# print(reds)
# print(blues)

for i in reds:
  for j in blues:
    if i[0] < j[0] and i[1] < j[1]:
      count += 1
      blues.remove(j)
      break
print(count)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
using namespace std;

typedef long long ll;

ll mod_pow(__int128_t x,__int128_t n,__int128_t mod){
  __int128_t res=1;
  while(n){
    if(n%2) res=res*x%mod;
    x=x*x%mod;
    n/=2;
  }
  return res;
}

bool miller_rabin(int n){
  
  if( n == 2 ) return true;
  
  if( n == 1 || n % 2 == 0 ) return false;
  
  int s = 0, d = n - 1;
  
  random_device rd;
  
  while( d % 2 == 0 ) s++, d /= 2;
  
  int cnt = 20;
  
  while(cnt--){
    
    int a = rd() % ( n - 1 ) + 1;
    
    int t = d;
    
    __int128_t y = mod_pow( a, t, n );
    
    while( t != n - 1 && y != 1 && y != n - 1 ){
      y = ( y * y ) % n;
      t *= 2;
    }
    
    if( y != n - 1 && t % 2 == 0 ) return false;
    
  }
  
  return true;
}

int f(__int128_t x, int n){
  int c = 5;
  return ( x * x + c ) % n;
}

__int128_t Abs(__int128_t x){
  if( x < 0 ) x *= -1;
  return x;
}

int pollards_rho(int n){
  
  __int128_t y = rand() % ( n + 1 );
  int r = 1, q = 1, m = rand() + 1;
  
  __int128_t g, ys, x;
  
  do{
    
    x = y;
    
    for(int i=1;i<=r;i++) y = f( y, n );
    
    int k = 0;
    
    do{
      
      ys = y;
      
      for(int i=1;i<=min( m, r - k );i++){
	y = f( y, n );
	q = ( q * Abs( x - y ) ) % n;
      }
      
      g = __gcd( q, n );
      k = k + m;
      
    }
    while( k < r && g <= 1 );
    
    r = 2 * r;
    
  }
  while( g <= 1 );
  
  if( g == n ){
    
    do{
      ys = f( ys, n );
      g = __gcd( (int)Abs( x - ys ), n );
    }
    while( g <= 1 );
    
  }
    
  return g;
}

vector<int> factorial(int n){
  
  assert( 1 < n );
  
  vector<int> res;
  
  while( miller_rabin(n) == false ){
    
    int r = pollards_rho(n);
    
    if( 1 < r && r < n && miller_rabin(r) == true ){
      res.push_back( r );
      n /= r;
    }
    
  }
  
  if( n != 1 ) res.push_back( n );
  
  sort( res.begin(), res.end() );
  
  return res;
}

signed main(){
  
  int n;
  cin>>n;
    
  vector<int> ans = factorial(n);

  cout<<n<<": ";
    
  for(int i=0;i<(int)ans.size();i++){
    if(i) cout<<' ';
    cout<<ans[i];
  }
    
  cout<<endl;
  
  return 0;
}



Measured memory_bytes: 3204
H,W = gets.split.map(&:to_i)
SY,SX = gets.split.map { _1.to_i - 1 }
GY,GX = gets.split.map { _1.to_i - 1 }
S = readlines.map { _1.chomp.chars }

MV = [[1,0],[-1,0],[0,1],[0,-1]]
WP = [*-2..2].product([*-2..2]) - [*MV, [0,0]]

dist = Array.new(H) { [-1]*W }
que = [[SY,SX]]
dist[SY][SX] = 0
mem = Array.new(H) { []*W }
until que.empty?
  break if dist[GY][GX] != -1

  que2 = []
  until que.empty?
    y,x = que.pop
    d = dist[y][x]

    blk = false
    MV.each do |dy,dx|
      yy,xx = y+dy,x+dx
      next if yy < 0 || xx < 0 || H <= yy || W <= xx
      next blk=true if S[yy][xx] == "#"
      next if 0 <= dist[yy][xx] && dist[yy][xx] <= d
      dist[yy][xx] = d
      mem[yy][xx] = true
      que.push([yy,xx])
    end
    que2.push([y,x]) if blk
  end
  
  que2.each do |y,x|
    WP.each do |dy,dx|
      yy,xx = y+dy,x+dx
      next if yy < 0 || xx < 0 || H <= yy || W <= xx
      next if mem[yy][xx]
      next if S[yy][xx] == "#"
      next if 0 <= dist[yy][xx] && dist[yy][xx] <= d + 1
      dist[yy][xx] = d + 1
      que.push([yy,xx])
    end
  end

end

puts dist[GY][GX]


Measured memory_bytes: 110228
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
# define mp make_pair
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  ll l, r; cin >> l >> r;

  if(r - l > 2019) {
    cout << 0 << endl;
    return 0;
  } else {
    ll sa = r - l;
    l %= 2019;
    r = l + sa;
    int ans = 2019;
    for(int i = l; i < r; i++){
      for(int j = i + 1; j <= r; j++){
        ans = min(ans, (i * j)%2019);
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3592
#include <stdio.h>
int main(void){
	int a[10],n,counter=0,check=0;
	while(counter<9){
		scanf("%d",&a[counter]);
		counter++;
	}
	counter=0;
	scanf("%d",&n);
	int b[n+1];
	while(counter<n){
		scanf("%d",&b[counter]);
		counter++;
	}
	counter=0;
	while(counter<9){
		n=0;
		while(n<9){
			if(a[counter]==b[n]){
				a[counter]=-1;
				break;
			}else{
				n++;
			}
		}
		counter++;
	}
	n=0;
	while(n<9){
		if((a[n]==-1)&&(a[n+1]==-1)&&(a[n+2]==-1)){
			check++;
		}
		n+=3;
	}
	n=0;
	while(n<3){
		if((a[n]==-1)&&(a[n+3]==-1)&&(a[n+6]==-1)){
			check++;
		}
		n++;
	}
	n=0;
	if(((a[0]==-1)&&(a[4]==-1)&&(a[8]==-1))||((a[2]==-1)&&(a[4]==-1)&&(a[6]==-1))){
		check++;
	}
	if(check!=0){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>
#include<math.h>
#include<iomanip>


using namespace std;

int main(){
	int a,b,c;
	int n,max=0;
	cin>>n;
	cin>>a>>b;
	if(n==3)cin>>c;
	else c=b;
	max=a;
	if(max>b)max=b;
	if(max>c)max=c;
	bool f=false;
	for(int i=1;i<=max;i++){
		if(a%i==0&&b%i==0&&c%i==0){
			cout<<i<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>




typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

ll lcm(ll a, ll b) {
	ll c;
	c = a * b / gcd(a, b);
	return c;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0):x(x%mod){}
	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);
		res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
};

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	rep(i, 2) {
		if (a > b) {
			ans += a; a--;
		}
		else {
			ans += b; b--;
		}
	}
	cout << ans << endl;
	return 0;
}










Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define li long long int
#define ld long double
#define eb push_back
#define pb pop_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define size(a) a.size()
#define rev(a) reverse(a.begin(),a.end())
#define len(a) a.length()
#define f first
#define s second
#define sort(a) sort(a.begin(),a.end())
#define vli vector<li>
#define vvli vector<vli >
#define pli pair<li,li>199
#define vpli vector<pli>
#define inp(t) li t;cin>>t; while(t--)
using namespace std;
const li mod = 1e9+7;
const long int MAXN = 2e5+100;
#define PI 3.14159265358979323846264338327950

li power(li a, li b) { a%=mod; li ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
li add(li a,li b) { return (((a%mod)+(b%mod))%mod);}
li sub(li a,li b) { return (((a%mod)-(b%mod))%mod);}
li mul(li a,li b) { return (((a%mod)*(b%mod))%mod);}

// vector<li> v[MAXN];
// li ances[MAXN];
// bool visited[MAXN];
// li n,m;

// void bfs(li node)
// { 
//    queue <li> q;
//    q.push(node);

//    visited[node] = true;
//    n-=1;
   
//    while (!q.empty()) 
//    {
//       li u = q.front(); 
//       q.pop();
//       for(li j = 0;j < (li)size(v[u]);j++) 
//       {
//          li nodes = v[u][j];
         
//          if (!visited[nodes]) 
//          {
//             n-=1;
//             ances[nodes] = u;
//             q.push(nodes);
//             visited[nodes] = true;
//          }
//       }
//    }
// }

void solve()
{
   li n;
   cin>>n;
   vli v(n);

   rep(i,0,n)
   cin>>v[i];

   vli dp(n+1,-1);

   dp[0] = 0;
   dp[1] = abs(v[1]-v[0]);

   for(li i=2;i<n;i++)
   {
      dp[i] = min(dp[i-1] + abs(v[i] - v[i-1]), dp[i-2] + abs(v[i] - v[i-2]));
   }

   cout<<dp[n-1]<<'\n';

}
int main()
{
    IOS;

    solve();
    return 0;
}

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

const int MAXN = 3e5 + 10;
const int MAXM = 3e5 + 10;

template <typename value_t>
class fenwick {
   public:
    fenwick(int n) {
        memset(c, 0, sizeof c);
        this->n = n;
    }

    void add(int i, value_t x) {
        while (i <= n) {
            c[i] += x;
            i += Lowbit(i);
        }
    }

    value_t sum(int x) {
        value_t sum = 0;
        while (x > 0) {
            sum += c[x];
            x -= Lowbit(x);
        }
        return sum;
    }

    value_t sum(int x1, int x2) { return sum(x2) - sum(x1 - 1); }

   private:
    value_t c[MAXN];
    int n;

    inline int Lowbit(int x) { return x & (-x); }
};

struct interval {
    int l, r;
} a[MAXM];
struct comp {
    bool operator()(const interval& a, const interval& b) {
        return a.r - a.l < b.r - b.l;
    }
};

#include <cctype>
#include <cstdio>

inline int read() {
    int X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch))
    {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) {
        X = (X << 3) + (X << 1) + (ch ^ 48);
        ch = getchar();
    }
    return w ? -X : X;
}

int main() {
    int n = read();
    int m = read();
    for (int i = 1; i <= n; i++) {
        a[i].l = read();
        a[i].r = read();
    }  
    sort(a + 1, a + n + 1, comp());
    fenwick<int>* tree = new fenwick<int>(m);
    int cur = 1;
    for (int d = 1; d <= m; d++) {
        while (cur <= n && a[cur].r - a[cur].l + 1 < d) {
            tree->add(a[cur].l, 1);
            tree->add(a[cur].r + 1, -1);
            cur++;
        }
        int ans = n - cur + 1;
        for (int i = d; i <= m; i += d) {
            ans += tree->sum(i);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 4480
n, m, x = [int(x) for x in input().split()]
b_list = [[int(x) for x in input().split()] for _ in range(n)]

ans_init = 10 ** 8
ans = ans_init
for i in range(2 ** n):
    temp_list = [0] * (m + 1)
    for j in range(n):
        if (i >> j) & 1:
            temp_list = [t + b for t, b in zip(temp_list, b_list[j])]
    
    if min(temp_list[1:m+1]) >= x and temp_list[0] < ans:
        ans = temp_list[0]
print(ans if ans != ans_init else -1)

Measured memory_bytes: 9156
package main

import "fmt"

func main(){
	var n,a,b,ans int
	fmt.Scan(&n,&a,&b)
	temp := n/(a+b)
	ans = temp*a
	temp = n%(a+b)
	if temp < a {
		ans += temp
	} else {
		ans += a
	}
	fmt.Println(ans)
}


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

int cnt = 0;
int work[500010] = {0};

void mergeSort(int *a, int left, int right){
	if(left >= right) return;
	int mid = (right + left) / 2;
	mergeSort(a, left, mid);
	mergeSort(a, mid + 1, right);
	for(int i = left; i <= mid; i++)
		work[i] = a[i];
	for(int i = mid + 1; i <= right; i++)
		work[i] = a[right-(i-(mid+1))];
	int i = left, j = right;
	for(int k = left; k <= right; k++) {
		if(work[i] < work[j]) a[k] = work[i++];
		else a[k] = work[j--];
		cnt++;
	}
}

int main(){
	int n;
	scanf("%d", &n);
	int a[500010] = {0};
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	mergeSort(a, 0, n-1);
	for(int i = 0; i < n - 1; i++)
		printf("%d ", a[i]);
	printf("%d\n", a[n-1]);
	printf("%d\n", cnt);
}



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

struct SegmentTree {
  struct Node {
    int node, lazy;
    Node() {}
    Node(int node, int lazy) : node(node), lazy(lazy) {}

    Node operator*(const Node &r) const {
      return Node(min(node, r.node), -1);
    }
  };

  Node e = Node(INT_MAX, -1);
  size_t n;
  vector<Node> seg;

  SegmentTree(size_t size) : n(1 << (32 - __builtin_clz(size - 1))), seg(2 * n - 1, e) {}

  void lazy_evaluate(int k) {
    if (seg[k].lazy != -1) {
      seg[k].node = seg[k].lazy;
      if (k < n - 1) {
        seg[2 * k + 1].lazy = seg[k].lazy;
        seg[2 * k + 2].lazy = seg[k].lazy;
      }
      seg[k].lazy = -1;
    }
  }

  void update_node(int k) {
    seg[k] = seg[2 * k + 1] * seg[2 * k + 2];
  }

  void update(int l, int r, int x, int k, int a, int b) {
    lazy_evaluate(k);

    if (r <= a || b <= l) return;
    if (l <= a && b <= r) {
      seg[k].lazy = x;
      lazy_evaluate(k);
      return;
    }

    update(l, r, x, 2 * k + 1, a, (a + b) / 2);
    update(l, r, x, 2 * k + 2, (a + b) / 2, b);
    update_node(k);
  }

  Node query(int l, int r, int k, int a, int b) {
    lazy_evaluate(k);
    if (r <= a || b <= l) return e;
    if (l <= a && b <= r) return seg[k];

    return query(l, r, 2 * k + 1, a, (a + b) / 2) * query(l, r, 2 * k + 2, (a + b) / 2, b);
  }

  void update(int l, int r, int x) {
    update(l, r, x, 0, 0, n);
  }

  int query(int l, int r) {
    return query(l, r, 0, 0, n).node;
  }

  void debug(string s, int l, int r, int k) {
    cerr << s << "[" << l << ", " << r << ") " << k << endl;
  }
};

int main() {
  int n, q;
  cin >> n >> q;

  SegmentTree seg(n);

  while (q--) {
    int c;
    cin >> c;

    if (c) {
      int l, r;
      cin >> l >> r;
      cout << seg.query(l, r + 1) << endl;
    } else {
      int l, r, x;
      cin >> l >> r >> x;
      seg.update(l, r + 1, x);
    }
  }
}

Measured memory_bytes: 4932
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, q;
    cin >> n;
    int arr[10001];
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    cin >> q;
    while (q--) {
        int b, e, t;
        cin >> b >> e >> t;
        for (int j = 0; j < (e - b); j++)
            swap(arr[b + j], arr[t + j]);
    }
    for (int i = 0; i < n; i++) {
        if (i == n - 1)
            cout << arr[i] << endl;
        else cout << arr[i] << " ";
    }
}


Measured memory_bytes: 3092
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
using namespace std;

vector<int> v;
int main(){
  int n;
  cin >> n;
  cout << (n/2)*((n+1)/2) << endl;

}

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

int main() 

{   
	ios::sync_with_stdio(0); cin.tie(0);
	long long int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(a*c,max(b*c,max(a*d,b*d)));
	
} 

Measured memory_bytes: 3648
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm_func(a, b):
    return a / gcd (a, b) * b

N, M = map(int, raw_input().split())
a = map(int, raw_input().split())

lcm = 1
for i in range(N):
    lcm = lcm_func(lcm, a[i])

for i in range(N):
    if lcm/a[i] %2 == 0:
        print 0
        exit()

lcm2 = lcm/2

ans = ((M/lcm2)+1)/2

print ans


Measured memory_bytes: 11316
#include <stdio.h>

int main(){
	int a,b,n,i;
	a=b=n=0;
	for(i=0;i<8;i++){
		scanf("%d",&n);
		if(i<4) a += n;
		else b += n;
	}
	if(a>b) printf("%d\n",a);
	else printf("%d\n",b);
	return 0;
}

Measured memory_bytes: 592