akhauriyash/Code-Regression huggingface dataset:
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>n;
    for(i=1;i<=9;i++)
    {
      if(n%i==0 && n/i<=9)
      {
        cout<<"Yes";
        return 0;
      }
    }
    cout<<"No";
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

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

#define xx first
#define yy second



void solve() {
    int a; cin >> a;
    cout << (a * (1 + a + a * a)) << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan =new Scanner(System.in);
		int X=scan.nextInt();
		int Y=scan.nextInt();
	
		int turu=0;
		int kame=0;
		for(int i=0;i<=Y/2;i++) {
			int a=0;
			a=Y-(i*2);
			if(a%4==0&&(i+a/4)==X) {
		      turu=i;  kame=a/4;
		      break;
		      
			}
		}
		if(turu==0&&kame==0) {
			System.out.println("No");
		}
		else {
			System.out.println("Yes");
		}
		
	}
}


Measured memory_bytes: 35708
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=998244353;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

ll pow_mod(ll n,ll p,ll m){
    ll res = 1;
    while(p>0){
        if(p%2==1) res = (res * n) % m;
        n = (n * n) % m;
        p /= 2;
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    map<int,int> m;
    ll ans = 1;
    rep(i,n){
        int a;
        cin >> a;
        m[a]++;
        if(i==0 && a!=0) ans = 0;
        if(i!=0 && a==0) ans = 0;
    }
    
    for(int i=0;i<m.size()-1;i++){
        ll t = pow_mod(m[i],m[i+1],MOD);
        ans = (ans * t) % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cmath>
#define ll long long 
#define For(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int a[100002];
main(){
	int n;
	cin >>n;
	For(i,1,n){
		scanf("%d",a+i);
	}
	ll sum = 0;
	ll ans = 0;
	ll ans1 = 0;
	ll ans2 = 0;
	if(a[1]==0){
		a[1] = 1;
		ans1 = 1;	
		sum = a[1];
		int dau = (a[1]>0)?1:-1;
		For(i,2,n){
			sum += a[i];
			dau = -dau;
			if(dau == 1){
				if(sum <=0){
					ans1 += 1-sum;
					sum = 1;
				}	
			}	else	{
				if(sum >=0){
					ans1 += sum+1;
					sum = -1;
				}
			}
		}
			a[1] = -1;
			ans2 = 1;	
		sum = a[1];
		dau = (a[1]>0)?1:-1;
		For(i,2,n){
			sum += a[i];
			dau = -dau;
			if(dau == 1){
				if(sum <=0){
					ans2 += 1-sum;
					sum = 1;
				}	
			}	else	{
				if(sum >=0){
					ans2 += sum+1;
					sum = -1;
				}
			}
		}
		ans = min(ans1,ans2);
	}	else	{
		ans = 0;		
		sum = a[1];
		int dau = (a[1]>0)?1:-1;
		For(i,2,n){
			sum += a[i];
			dau = -dau;
			if(dau == 1){
				if(sum <=0){
					ans += 1-sum;
					sum = 1;
				}	
			}	else	{
				if(sum >=0){
					ans += sum+1;
					sum = -1;
				}
			}
		}
		if(a[1]>0){
			ans2 = a[1]+1;	
			a[1] = -1;			
			sum = a[1];
			dau = (a[1]>0)?1:-1;
			For(i,2,n){
				sum += a[i];
				dau = -dau;
				if(dau == 1){
					if(sum <=0){
						ans2 += 1-sum;
						sum = 1;
					}	
				}	else	{
					if(sum >=0){
						ans2 += sum+1;
						sum = -1;
					}
				}
			}
			ans = min(ans,ans2);
		}	else	{
			ans1 = 1-a[1];
			a[1] = 1;			
			sum = a[1];
			int dau = (a[1]>0)?1:-1;
			For(i,2,n){
				sum += a[i];
				dau = -dau;
				if(dau == 1){
					if(sum <=0){
						ans1 += 1-sum;
						sum = 1;
					}	
				}	else	{
					if(sum >=0){
						ans1 += sum+1;
						sum = -1;
					}
				}
			}
			ans = min(ans,ans1);
		}
	}
	cout << ans;
}

Measured memory_bytes: 640
import scala.io.StdIn.readLine

object Main {
  def main(args: Array[String]) {
    val input = readLine().split(" ").map(_.toInt)
    val (a: Int, b: Int, c: Int) = (input(0), input(1), input(2))
    val result = if(a < b && b < c) "Yes" else "No"

    println(result)
  }
}

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

int main() {
  int N;
  long long total = 0;
  cin >> N;
  vector<long long>A(N);
  vector<long long>B(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    B.at(A.at(i)-1) += 1;
  }
  for (int i = 0; i < N; i++) {
    if (B.at(i) > 1) {
      total += B.at(i) * (B.at(i) - 1) / 2;
    }
  }
  for (int i = 0; i < N; i++) {
    if (B.at(A.at(i)-1) > 1) {
      cout << total - B.at(A.at(i)-1) + 1 << endl;
    }
    else {
      cout << total << endl;
    }
  }
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
 
int main(){
  string s; cin >> s;
  if(s[2] == s[3] and s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 888
use proconio::*;
use std::cmp::*;

fn main() {
    input! {
    a:isize,
    b:isize,
    c:isize,
    x:isize,
    y:isize,
    }
    let n=min(x,y);
    let z=max(x,y);
    println!("{}",min(c*z*2,min(a*x+b*y,if x>y{c*2*n+a*(z-n)}else{c*2*n+b*(z-n)})));
}

Measured memory_bytes: 2140
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pii;
#define usize(x) (int)(x.size())

#define foreach(x) for (auto item : x)
#define fill(s, x)              \
    for (int i = 0; i < x; i++) \
        cin >> s[i];
#define in(veriler, a) (veriler.find(a) != veriler.end())
#define btw(x, y, z) x >= y&& x <= z;
std::ostream& operator<<(std::ostream& os, pair<int,int> p) {
    os << p.first << ", " << p.second;
    return os;
}
#ifdef ONLINE_JUDGE
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define dbg(x) //a
#define plist(x) //a

#else
#define fio //a
#define dbg(x) cout << #x << " has a value of: " << x << "\n";
#define plist(x)                       \
    for (int i = 0; i < usize(x); i++) \
        cout << "eleman " << i << " = " << x[i] << "\n";
#endif
int main(){
	string s;
	cin>>s;
	vector<pii> prs;
	char c=s[0];
	int ln=1;
	for (int i = 1; i < (int)s.size(); i++)
	{
		if(s[i]==c){
			ln++;
		}
		else{
			prs.push_back(pii(c=='<'?1:0,ln));
			c=s[i];
			ln=1;
		}
	}
	prs.push_back(pii(c=='<'?1:0,ln));
	lli cvb=0;
	for (int i = 0; i < (int)prs.size(); i++)
	{
		cvb+=(prs[i].second*(prs[i].second+1))/2;
		
	}
	//plist(prs);
	for (int i = 0; i < (int)prs.size()-1; i++)
	{
		if(prs[i].first==1){
			cvb-=prs[i].second;
			cvb-=prs[i+1].second;
			cvb+=max(prs[i+1].second,prs[i].second);
		}
	}
	cout<<cvb<<"\n";
	return 0;
}


Measured memory_bytes: 6264
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
template <typename X>
struct DST
{
  int n;
  vector<X> dat,delay;
  X init;

  DST(int _n,X _init)
  {
    n = 1;
    init = _init;
    while(n < _n) n *= 2;
    dat.assign(2*n-1,init);
    delay.assign(2*n-1,init);
  }

  void eval(int k,int l,int r)
  {
    if(delay[k] != init){
      dat[k] = delay[k];
      if(k < n-1){
	delay[2*k+1] = delay[k];
	delay[2*k+2] = delay[k];
      }
      delay[k] = init;
    }
  }
  
  void update(int a,int b,X x,int k,int l,int r)
  {
    eval(k,l,r);
    
    if(r<=a||b<=l) return ;
    
    if(a<=l&&r<=b){
      delay[k] = x;
      eval(k,l,r);
    }
    else{
      update(a,b,x,2*k+1,l,(l+r)/2);
      update(a,b,x,2*k+2,(l+r)/2,r);
      dat[k] = min(dat[2*k+1],dat[2*k+2]);
    }
  }

  X query(int a,int b,int k,int l,int r)
  {
    eval(k,l,r);
    
    if(r<=a||b<=l) return init;

    if(a<=l&&r<=b) return dat[k];    
    else{
      X vl = query(a,b,2*k+1,l,(l+r)/2);
      X vr = query(a,b,2*k+2,(l+r)/2,r);
      return min(vl,vr);
    }
  }
};
int _n,q;
vector<ll> x;
vector<int> com,s,t;
const ll INF = (ll)(1<<30)*2-1;
int main()
{
  cin >> _n >> q;
  x.resize(q);
  com.resize(q);
  s.resize(q);
  t.resize(q);
  rep(i,q){
    cin >> com[i] >> s[i] >> t[i];
    if(com[i] == 0) cin >> x[i];
  }
  
  DST<ll> dst(_n,INF);

  rep(i,q){
    if(com[i] == 0){
      dst.update(s[i],t[i]+1,x[i],0,0,dst.n);
    }
    else{
      cout << dst.query(s[i],t[i]+1,0,0,dst.n) << "\n";
    }    
  }
  return 0;
}



Measured memory_bytes: 8928
n, w = map(int, input().split())
V = [list(map(int, input().split())) for i in range(n)]

w0 = V[0][0]

V_split = [[] for i in range(4)]
for i in range(n):
    V_split[V[i][0] - w0].append(V[i][1])

for i in range(4):
    V_split[i].sort(reverse=True)

# print(V_split)

V_split_S = [[0] for i in range(4)]
for i in range(4):
    for j in range(len(V_split[i])):
        V_split_S[i].append(V_split_S[i][-1] + V_split[i][j])

# print(V_split)
# print(V_split_S)


ans = 0

for i in range(min(len(V_split_S[0]), w//w0 + 1)):
    wi = w - w0 * i
    for j in range(min(len(V_split_S[1]), wi//(w0+1) + 1)):
        wj = wi - (w0+1) * j
        for k in range(min(len(V_split_S[2]), wj//(w0+2) + 1)):
            wk = wj - (w0+2) * k
            l = min(len(V_split_S[3]), wk//(w0+3) + 1) - 1
            
            ans = max(ans, V_split_S[0][i] + V_split_S[1][j] + V_split_S[2][k] + V_split_S[3][l])
            # print(i,j,k,l, ans)
print(ans)


Measured memory_bytes: 40304
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

from fractions import gcd

A, B, C, D = rl()

def f(n, d):
	return n // d

b = f(B, C)+f(B, D)-f(B, C*D//gcd(C,D))
a = f(A-1, C)+f(A-1, D)-f(A-1, C*D//gcd(C,D))

print(B-A+1 - (b-a))



Measured memory_bytes: 77236
#81 C - 一次元リバーシ
S = input()
S = S + '1'# 番兵

# 連続する文字をカウント
cnt = []
conti = 1
for i in range(1,len(S)):
    if S[i-1] == S[i]:
        conti += 1
    else:
        cnt.append(conti)
        conti = 1
print(len(cnt)-1)

Measured memory_bytes: 9640
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
#define int long long
#define rep(i,a,n) for (int (i)=(a);(i)<(n);(i)++)
using namespace std;
#define hash hush
typedef long long ll;
typedef long double ld;
signed  main() {
	string a[100];
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++){
		cin>>a[i];
	}
	for(int i=0;i<w+2;i++)  cout<<'#';
	cout<<endl;
	for(int i=0;i<h;i++){
		cout<<"#"<<a[i]<<"#";
		cout<<endl;
	}
	for(int i=0;i<w+2;i++){
		cout<<"#";
	}
	cout<<endl;
	getchar(); getchar();
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int main(){
    int k, s;
    cin >> k >> s;
    int cnt = 0;
    int mi = min(k, s);
    for(int i=0;i<=mi;i++) {
        int mj = min(k, s-i);
        for(int j=0;j<=mj;j++) {
            int z = s - i - j;
            if(0 <= z && z <= k) {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };


int main() {
	ll n;
	cin >> n;
	ll z = 1000000000000000;
	rep(i, 0, 5) {
		ll s;
		cin >> s;
		if (z > s)z = s;
	}
	ll ans = ((n+z-1) / z) + 4;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>

int main(void){
   int a,b;
   int k;
   bool j=false;
   
   scanf("%d",&k);
   scanf("%d %d",&a,&b);

   for(int i=a;i<=b;i++){
      if(i%k==0){
         j=true;
      }
   }

   if(j){
      printf("OK");
   }else{
      printf("NG");
   }

   return 0;
}


Measured memory_bytes: 1700
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

b.append(0)

ans = 0

for i in range(n+1):
  if a[i] <= b[i]:
    ans += a[i]
    if i != n:
      if a[i+1] >= b[i]-a[i]:
        ans += b[i]-a[i]
        a[i+1] -= b[i]-a[i]
      else:
        ans += a[i+1]
        a[i+1] = 0
  else:
    ans += b[i]
print(ans)

Measured memory_bytes: 18476
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
long long mod=998244353;
int n;
int a[3000];
int s;
long long dp[3001][3001]={};
int main(){
	cin>>n>>s;
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		cin>>a[i];
		for(int j=s;j>=0;j--){
			(dp[i+1][j]+=dp[i][j])%=mod;
			if(j+a[i]<=s){
				(dp[i+1][j+a[i]]+=dp[i][j])%=mod;
			}
			(dp[i+1][j]*=2)%=mod;
		}
	}
	cout<<dp[n][s]<<endl;
	return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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


#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/

// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
	os << "(" << pair_var.first << ", " << pair_var.second << ")";
	return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	os << "{";
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
	}
	os << "}";
	return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
	os << "{";
	repi(itr, map_var) {
		os << *itr;
		itr++;
		if (itr != map_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
	os << "{";
	repi(itr, set_var) {
		os << *itr;
		itr++;
		if (itr != set_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}

#define DUMPOUT cerr

void dump_func() {
	DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
	DUMPOUT << head;
	if (sizeof...(Tail) > 0) {
		DUMPOUT << ", ";
	}
	dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {

	int N;
	cin >> N;
	for(int a=1; a<=9; a++) for(int b=1; b<=9; b++)
		if (N == a * b) { Yes; return 0; }

	No;

	return 0;
}


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

#define       pb                 push_back
#define       mx                 200005
#define       MOD                1000000007
#define 	  optimize           ios::sync_with_stdio(0);cin.tie(0);
#define 	  inf                0x3f3f3f3f
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);

using namespace std;

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

int main()
{
    int n, ans=0, a, cn = 0, b;

    cin >> n >> a;

    for(int i = 1; i < n; i++)
    {
        cin >> b;

        if(b<=a) cn++;
        else cn = 0;

        a = b;
        ans = max(ans, cn);
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    int n;
    int m;
    int res;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        res += (n * (n - 1)) / 2;
        res += (m * (m - 1)) / 2;
        System.out.println(res);
    }
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> x;
    rep(i, M){
        int t;
        cin >> t;
        x.push_back(t);
    }
    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }
    sort(x.begin(), x.end());
    vector<int> kyori;
    rep(i, M-1){
        kyori.push_back(-x[i+1]+x[i]);
    }
    int ans = x[M-1] - x[0];
    
    sort(kyori.begin(), kyori.end());
    rep(i, N-1){
        ans += kyori[i];
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
	int a, b, c, nokori, nokori_3bai;
	while(true){
		cin>>a>>b>>c;
		if(a==-1 && b==-1 && c==-1)break;
		nokori = 120*60;
		nokori = nokori - (3600*a + 60*b + c);
		nokori_3bai = nokori*3;
		printf("%02d:%02d:%02d\n", nokori/3600, (nokori/60)%60, (nokori)%60);
		printf("%02d:%02d:%02d\n", nokori_3bai/3600, (nokori_3bai/60)%60, (nokori_3bai)%60);
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

int n, m;
vector < int > g[101010];
int q;
int v[101010], d[101010];
int c[101010], ans[101010];
bool was[101010][21];

void dfs (int v, int dist, int color, int par = 0) {
	if (!ans[v]) ans[v] = color;
	was[v][dist] = 1;
	if (!dist) return ;
	for (int to : g[v]) {
		if(to == par || was[to][dist - 1]) continue;
		was[to][dist - 1] = 1;
		dfs(to, dist - 1, color, v);
	}
}

void perform (int x) {
	dfs(v[x], d[x], c[x]);
}

int main () {
	cin >> n >> m;

	for (int i = 1; i <= m; i ++) {
		int l, r;
		cin >> l >> r;
		g[l].pb(r);
		g[r].pb(l);
	}


	cin >> q;
	for (int i = 1; i <= q; i ++) {
		cin >> v[i] >> d[i] >> c[i];
	}

	for (int i = q; i; i --) {
		perform(i);
	}

	for (int i = 1; i <= n; i ++)
		cout << ans[i] << '\n';
}

Measured memory_bytes: 10104
n, m = map(int, input().split())
positions = sorted([int(i) for i in input().split()])

ans = positions[-1] - positions[0]
distances = [abs(positions[i] - positions[i-1]) for i in range(1, m)]
distances = sorted(distances)[::-1]

print(ans - sum(distances[:n-1]))


Measured memory_bytes: 13832
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
int K;
int H[300];
long long dp[300][300];
long long nx[300][300];
int main(){
  int m;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(H[Lj4PdHRW]);
    }
  }
  if(N==K){
    wt_L(0);
    wt_L('\n');
    return 0;
  }
  for(m=(0);m<(N);m++){
    int i;
    for(i=(0);i<(K+1);i++){
      int j;
      for(j=(0);j<(m+1);j++){
        nx[i][j] = 4611686016279904256LL;
      }
    }
    if(m<=K){
      nx[m][m] = H[m];
    }
    for(i=(0);i<(K+1);i++){
      int j;
      for(j=(0);j<(m);j++){
        chmin(nx[i][m], dp[i][j] +max_L(H[m] - H[j], 0));
      }
    }
    for(i=(0);i<(K);i++){
      int j;
      for(j=(0);j<(m);j++){
        chmin(nx[i+1][j], dp[i][j]);
      }
    }
    for(i=(0);i<(K+1);i++){
      int j;
      for(j=(0);j<(m+1);j++){
        dp[i][j] = nx[i][j];
      }
    }
  }
  {
    int AlM5nNnR;
    long long XJIcIBrW;
    if(N==0){
      XJIcIBrW = 0;
    }
    else{
      XJIcIBrW = dp[K][0];
      for(AlM5nNnR=(1);AlM5nNnR<(N);AlM5nNnR++){
        XJIcIBrW = min_L(XJIcIBrW, dp[K][AlM5nNnR]);
      }
    }
    wt_L(XJIcIBrW);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191111-2

// --- original code ---
// int N, K, H[300];
// ll dp[300][300], nx[300][300];
// 
// {
//   rd(N,K,H(N));
//   if(N==K) wt(0), return 0;
//   rep(m,N){
//     rep(i,K+1) rep(j,m+1) nx[i][j] = ll_inf;
//     if(m<=K) nx[m][m] = H[m];
//     rep(i,K+1) rep(j,m) nx[i][m] <?= dp[i][j] + max(H[m] - H[j], 0);
//     rep(i,K) rep(j,m) nx[i+1][j] <?= dp[i][j];
//     rep(i,K+1) rep(j,m+1) dp[i][j] = nx[i][j];
//   }
//   wt(min(dp[K](N)));
// }


Measured memory_bytes: 1408
#include <cmath>
#include <iostream>
#include <vector>
#include <tuple>

int main(){
  int H,W,D;
  std::cin >> H >> W >> D;

  std::vector<std::tuple<int, int>> A_map(H*W+1);
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      int tmp;
      std::cin >> tmp;
      A_map[tmp] = std::make_tuple(i, j);
    }
  }

  std::vector<long long> cost_map(H*W+1);
  for(int dm = 1; dm <= D; dm++){
    int cost = 0;
    int xp,yp;
    std::tie(xp,yp) = A_map[dm];
    for(int r = dm; r <= H*W; r+=D){
      int x,y;
      std::tie(x,y) = A_map[r];
      cost += std::abs(x-xp)+std::abs(y-yp);
      xp = x;
      yp = y;
      cost_map[r] = cost;
    }
  }

  int Q;
  std::cin >> Q;
  for(int q = 0; q < Q; q++){
    int L,R;
    std::cin >> L >> R;
    std::cout << cost_map[R]-cost_map[L] << "\n";
  }

  return 0;
}



Measured memory_bytes: 2560
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,k = LI()
    if k == 0:
        return n*n
    r = 0
    for b in range(k+1,n+1):
        t = b - k
        u = n // b
        a = t * u
        a += max(0, n - (u * b + k - 1))
        r += a

    return r


print(main())




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

int main(){
    int N;
    int alice=0,bob=0;
    cin >> N;
    vector<int> a(N);
    for(int i=0;i<N;i++ ){
        cin >> a[i];
    }
sort(a.begin(),a.end(),greater<int>());
for (int i=0;i<N;i++){
    if (i%2==0){
        alice+=a[i];
    }else{
        bob+=a[i];
    }
}
cout << alice-bob << endl;
}


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

string S, T;
int main(){
    int c=0;
    cin >> S >> T;
    bool flag = false;
    for(int i = S.length()-1; i >= 0; i--){
        for(int j = 0; j <T.length(); j++){
            if(i-j >= 0){
                if(S[i-j] == T[T.length()-1-j] || S[i-j] == '?') {
                    flag = true;
                }
                else{
                    flag = false;
                    break;
                }
            }else{
                flag = false;
                break;
            }
        }
        if(flag){
            for(int k = 0; k < T.length(); k++){
                S[i-k] = T[T.length()-1-k];
            }
            for(int k = 0; k < S.length(); k++){
                if(S[k] == '?') S[k] = 'a';
            }
            cout << S << '\n';
            return 0;
        }
    }
    cout << "UNRESTORABLE\n";
}

Measured memory_bytes: 256
from collections import Counter
from itertools import product

n = int(input())
V = list(map(int, input().split()))
odd = Counter(V[1::2]).most_common()[:2]
even = Counter(V[::2]).most_common()[:2]

if len(odd) == 1:
    odd.append((0, 0))
if len(even) == 1:
    even.append((0, 0))
INF = 10**18
total = -INF
for p in product((1, 0), repeat=2):
    if odd[p[0]][0] == even[p[1]][0]:
        continue
    total = max(total, odd[p[0]][1]+even[p[1]][1])
ans = n - total
print(ans)


Measured memory_bytes: 17116
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ull unsigned long long 
int main()
{
  ll n;
  cin>>n;
  ll arr[n+1],sum[n+1];
  sum[0]=0;
  for(int i=1;i<=n;++i)
  {
    cin>>arr[i];
    sum[i] = sum[i-1]+arr[i];
  }
  
  ll dp[n+1][n+1];
  for(int i=0;i<=n;++i)
  for(int j=0;j<=n;++j)
  dp[i][j] = 1e17;
 // memset(dp,0,sizeof(dp));
  for(int i=1;i<=n;++i)
  dp[i][i]=0;
  for(int l=2;l<=n;++l)
  {
    for(int i=1;i<=n-l+1;++i)
    {
      for(int j=i+1;j<=i+l-1;++j)
      dp[i][i+l-1] = min(dp[i][i+l-1],sum[i+l-1]-sum[i-1] +dp[i][j-1]+dp[j][i+l-1]);
    }
  }
  
  cout<<dp[1][n];
}

Measured memory_bytes: 1536
package main

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


func main() {
	scanner := bufio.NewScanner(os.Stdin)

	inputs := strToInts(scanLine(scanner))
	a, b := inputs[0], inputs[1]

	if a <= 8 && b <= 8 {
		fmt.Print("Yay!")
	} else {
		fmt.Print(":(")
	}
}

func scanLine(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func strToInts(line string) []int {
	strSlice := strings.Split(line, " ")

	var intSlice []int
	for _, str := range strSlice {
		intValue, _ := strconv.Atoi(str)
		intSlice = append(intSlice, intValue)
	}

	return intSlice
}

Measured memory_bytes: 640
n,p,i,a[51];
main(){
	for(;~scanf("%d",&n),n;) {
		for(a[n]=p=i=0;i<n;i++)scanf("%d",a+i);
		for(i=1;i<=n;i++){
			if(a[i-1]-a[i]+1) {
				i-p-1?printf(n-i?"%d-%d ":"%d-%d\n",a[p],a[i-1]):printf(n-i?"%d ":"%d\n",a[p]);p=i;
			}
		}
	}
	exit(0);
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }



string s;
void solve(){
	cin >> s;
	int n = s.size();
	int ans = (n-1)*9;
	bool ok = 0;
	for(int i = 1; i < n; i++){
		if(s[i] != '9'){
			ok = 1;
		}
	}
	if(ok) ans += s[0]-'1';
	else ans += s[0]-'0';
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 256
<?php
list($n) = ints();
$a = ints();
$b = ints();
for ($i = 0; $i < $n; ++$i) {
    if ($a[$i] > $b[$i]) $c1 += $a[$i] - $b[$i];
    elseif ($a[$i] < $b[$i]) $c2 += intdiv($b[$i] - $a[$i], 2);
}
echo $c2 >= $c1 ? 'Yes' : 'No';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

const int N=11;
int n,ans=1,dec=1,num,a[N];

int main()
{
	scanf("%d",&n); for (int i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (int i=1; i<=n; ++i) {if (!(a[i]%2)) num++;ans*=3;}
	for (int i=1; i<=num; ++i) dec*=2; ans-=dec;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<iostream>
#include<set>
#include<map>
using namespace std;
#define mp make_pair
#define ll long long
#define re register
typedef pair<int,int> pii;
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9'&&ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=200010;
int n,a[N],b[N],p[N];
int main()
{
	n=gi();
	for(int i=1;i<=n;i++)a[i]=gi(),b[i]=gi();
	ll lm=0,rm=0;
	for(int i=1;i<=n;i++)p[i]=a[i];
	sort(p+1,p+n+1);
	if(n&1)lm=p[(n+1)/2]*2ll;else lm=p[n/2]+p[n/2+1];
	for(int i=1;i<=n;i++)p[i]=b[i];
	sort(p+1,p+n+1);
	if(n&1)rm=p[(n+1)/2]*2ll;else rm=p[n/2]+p[n/2+1];
	printf("%lld\n",(rm-lm+1)/((n&1)?2:1)+(n&1)*(rm-lm+1&1));
	return 0;
}


Measured memory_bytes: 6040
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);
int main(){
  ll n;
  cin >> n;
  vector<ll>vec(n);
  vector<ll>sum(n+1);
  sum[0]=0;
  rep(i,n){
    cin>>vec[i];
    sum[i+1]=sum[i]+vec[i];
  }
  ll ans=INF;
  rep(i,n){
    if(i==n-1)continue;
    ll x=sum[i+1]-sum[0];
    ll y=sum[n]-x; 
    ll num=abs(x-y);
    if(num<ans)ans=num;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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

struct MyStruct {
	int a, b;
};

bool comp(const MyStruct& s, const MyStruct& t) {
	if (s.b != t.b)
		return s.b < t.b; //syoujunn
	return s.a > t.a;
}


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

	VI v(n);
	REP(i, n) {
		cin >> v[i];
	}
	VI sorted(v);
	SORT(sorted);

	if (v == sorted) {
		ANS("YES");
		return 0;
	}
	int tmp;
	REP(i, n-1) {
		FOR(j, i + 1, n - 1) {
			tmp = v[i];
			v[i] = v[j];
			v[j] = tmp;

			if (v == sorted) {
				ANS("YES");
				return 0;
			}
			else {
				tmp = v[i];
				v[i] = v[j];
				v[j] = tmp;
			}
		}
	}


	ANS("NO");


	return 0;
}


Measured memory_bytes: 256
n, k, c = map(int, input().split())
s = input()
left_dp = []
right_dp = []

i = 0
while len(left_dp)<k:
    if s[i] == "o":
        left_dp.append(i+1)
        i += c+1
    else: i += 1
        
i = n-1
while len(right_dp)<k:
    if s[i] == "o":
        right_dp.append(i+1)
        i -= c+1
    else: i -= 1

for i in range(k):
    if left_dp[i] == right_dp[k-i-1]:
        print(left_dp[i])

Measured memory_bytes: 20644
N,x = map(int,input().split())
A = list(map(int,input().split()))
A0 = A.copy()

for i in range(N):
  if(i == 0):
    if(A[i] > x): A[i] = x
  else:
    if((A[i-1]+A[i]) > x): A[i] -= (A[i-1]+A[i])-x

count = 0
for i in range(N):
  count += A0[i]-A[i]
print(count)

Measured memory_bytes: 14540
N, M = map(int, input().split())
light = []
for i in range(M):
    light.append(list(map(int, input().split())))
p = list(map(int, input().split()))
ans = 0
for i in range(2**N):
    switch = "{:010b}".format(i)
    switch = switch[(10-N):]
    flag = 1
    for j in range(M):
        count = 0
        for k in range(light[j][0]):
            if switch[light[j][k+1]-1] == "1":
                count += 1
        if count % 2 == p[j]:
            continue
        else:
            flag = 0
            break
    if flag == 1:
        ans += 1

print(ans)


Measured memory_bytes: 3064
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

w,h,x,y = I()
s = w*h/2
if w % 2 != 0 or h % 2 != 0:
    cnt = 0
else:
    if x == w//2 and y == h // 2:
        cnt =1
    else:
        cnt = 0

print("{} {}".format(s,cnt))


Measured memory_bytes: 10456
h,w,k=map(int,input().split())
c=[input() for l in range(h)]
gyou=[0]*h
s=0
ans=0
for i in range(h):
    for j in range(w):
        if c[i][j]=="#":
            gyou[i]+=1
            s+=1 
retu=[0]*w
for i in range(w):
    for j in range(h):
        if c[j][i]=="#":
            retu[i]+=1
for i in range(2**(h+w)):
    S=s
    a=[0]*(h+w)
    for j in range(h+w):
        if i>=2**(h+w-j-1):
            i-=2**(h+w-j-1)
            a[j]=1
    for i in range(h):
        if a[i]==1:
            S-=gyou[i]
    for i in range(w):
        if a[h+i]==1:
            S-=retu[i]
    for i in range(h):
        for j in range(w):
            if a[i]==1 and a[h+j]==1 and c[i][j]=="#":
                S+=1
    if S==k:
        ans+=1
print(ans)

Measured memory_bytes: 74292
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;


int main()
{
	string S;
	cin >> S ;
	string ans;

	if(S == "A") ans = "T";
	if(S == "C") ans = "G";
	if(S == "T") ans = "A";
	if(S == "G") ans = "C";
	
	cout << ans;

	return 0;
}



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

int main (){
   int k,h;
   cin >> k >>h;
   int l=k-1;
   int r=h-l;
   int count=1+l*2;
   rep(i,count){
       if(-2000000<=r&&r<=2000000) cout << r <<" ";
       r++;
   }
   return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(int, n);
  Cins(int, n, h);

  rep(i, n - 1) {
    if (h[i] <= h[i + 1] - 1) h[i + 1]--;
  }
  rep(i, n - 1) {
    if (!(h[i] <= h[i + 1])) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
using namespace std;
template<typename V,typename Weight>
class Dijekstra {
private:
	typedef pair<Weight,V> P;
	struct edge {
		Weight dist;V node;V prev;
		bool operator<(edge const& a) const {
			return dist < a.dist;
		}
		bool operator>(edge const& a) const {
			return dist > a.dist;
		}
	};
	//vector<V> trace;
	vector<vector<pair<V,Weight>>> E;
	V const sz;
public:
	Weight const inf = numeric_limits<Weight>::max();
	vector<Weight> D;
	Dijekstra(V v) :
		E(v),sz(v),D(v,inf) {}

	void inline addEdgeDirected(V from,V to,Weight dis){
		E[from].emplace_back(make_pair(to,dis));
	}
	void inline addEdgeUndirected(V from,V to,Weight dis){
		E[from].emplace_back(make_pair(to,dis));
		E[to].emplace_back(make_pair(from,dis));
	}

	V size() {return sz;}
	Weight & operator[] (V n) { if (0 <= n && n < sz) return D[n];} 

	void dijekstra(V start){
		priority_queue<P,vector<P>,greater<P>> que;
		D[start] = 0;
		que.push(make_pair(0,start));
		while(!que.empty()){
			P cur = que.top();que.pop();
			Weight d = cur.first;
			V v = cur.second;
			if (D[v] < d) continue; //既により最適が見つかっている
			for(V i = 0;i < E[v].size();i++){
				V next = E[v][i].first;
				Weight newCost = d + E[v][i].second;
				if (D[next] > newCost) {
					D[next] = newCost;
					que.push(make_pair(newCost,next));
				}
			}
		}
	}
/*
	vector<V> show_trace(V start,V goal){ // startからgoalの最短距離上のノード
		vector<V> ret;
		for (V node = goal;node != start;node = trace[node]) ret.push_back(node);
		ret.push_back(start);
		return ret; // 配列の先頭がgoal,末尾がstart
	}
*/
};

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	long V,E,R;
	long s,t,d;
	cin >> V >> E >> R;
	Dijekstra<long,long> dij(V);

	REP(i,E){
		cin >> s >> t >> d;
		dij.addEdgeDirected(s,t,d);
	}
	dij.dijekstra(R);
	REP(i,V) {
		if (dij[i] == dij.inf) cout << "INF" << endl;
		else cout << dij[i] << endl;
	}

	return 0;
}





Measured memory_bytes: 19472
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define INF (2LL << 58)
using namespace std;

int n, x[111111], y[111111], cx[111111], cy[111111];

long long solve(int midx, int midy){
    
    long long maxdis = 0, sum = 0;
    maxdis = 0, sum = 0;
    for(int i = 0; i < n; i++){
        long long dis = abs(midx - x[i]) + abs(midy - y[i]);
        sum += dis * 2;
        maxdis = max(maxdis, dis);
    }
    return sum - maxdis;
}

int main(){
    
    int W, H;

    cin >> W >> H >> n;
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
        cx[i] = x[i], cy[i] = y[i];
    }
    sort(cx, cx + n);
    sort(cy, cy + n);
    
    vector <pair<int, int> > pt;
    if(n % 2) pt.push_back(make_pair(cx[n / 2], cy[n / 2]));
    else {
        for(int i = 0; i < 2; i++){
            for(int j = 0 ; j < 2; j++){
                pt.push_back(make_pair(cx[n / 2 - 1 + i], cy[n / 2 - 1 + j]));
            }
        }
    }
    
    int ax, ay;
    long long ret, res = INF;
    for(int i = 0; i < pt.size(); i++){
        ret = solve(pt[i].first, pt[i].second);
        if(res > ret){
            ax = pt[i].first, ay = pt[i].second;
            res = ret;
        }
    }
    cout << res << endl;
    cout << ax << " " << ay << endl;
}

Measured memory_bytes: 2792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,K;
int a[105];
bool dp[100100];
int main(){
	cin >> N >> K;
	for(int i=0;i<N;i++){
		cin >> a[i];
	}
	sort(a,a+N);
	for(int i=0;i<a[0];i++)dp[i]=false;
	for(int i=a[0];i<=K;i++){
		bool flag = false;
		for(int j=0;j<N;j++){
			if(i>=a[j]&&!dp[i-a[j]]){
				flag = true;
				break;
			}
		}
		dp[i]=flag;
	}
	if(dp[K])cout << "First" << endl;
	else cout << "Second" << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int gcd(int x,int y){
	int z = y % x;
	if(x % z == 0){
		return z;
	}else{
		gcd( z, x);
	}
}

int main(void){
	int a,b;

	scanf("%d %d", &a, &b);

	if(a == 1 || b == 1){
		printf("1\n");
	}
	else if(a == b){
		printf("%d\n", a);
	}
	else if(1 < a && a < b){
		printf("%d\n", gcd( a, b));
	}
	else if(1 < b && b < a){
		printf("%d\n", gcd( b, a));
	}

	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
string Yes[2] = {"Yes", "No"};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};

using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;

/*------------------------------------------------------------------*/

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

    ll d, t, s; cin >> d >> t >> s;
    if(s * t >= d) cout << Yes[0] << endl;
    else cout << Yes[1] << endl;
}

Measured memory_bytes: 3624
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

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

bool PRIME[10004];
void eratosthenes()
{
    fill(begin(PRIME), end(PRIME), true);

    PRIME[0] = PRIME[1] = false;

    int n = NELEMS(PRIME) - 1;
    int isqrt = static_cast<int>(sqrt(n));
    FOR(i, 2, isqrt+1) {
        if(PRIME[i]) {
            for(int j = 2*i; j <= n; j += i) {
                PRIME[j] = false;
            }
        }
    }
}

int main()
{
    eratosthenes();

    int N;
    while(cin >> N) {
        int cnt = 0;
        REP(i, N) {
            if(PRIME[i+1] && PRIME[N-i])
                ++cnt;
        }
        cout << cnt << "\n";
    }

    return 0;
}

Measured memory_bytes: 3012
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using vi = vector<int>;

const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, -1, 0, 1};

int main() {
    int w, h;
    while (cin >> w >> h, w) {
        int H = 2 * h - 1, W = 2 * w - 1;
        vector<vi> table(H, vi(W, -1));
        for (int i = 0; i < H; i++) {
            for (int j = (i % 2 == 0); j < W; j += 2) cin >> table[i][j];
        }
        queue<pair<int, int>> que; que.emplace(0, 0); table[0][0] = 1;
        while (!que.empty()) {
            auto p = que.front(); que.pop();
            int i = p.first, j = p.second;
            if (i == H - 1 && j == W - 1) break;
            for (int k = 0; k < 4; k++) {
                int ni = i + di[k] * 2, nj = j + dj[k] * 2;
                if (ni < 0 || H <= ni || nj < 0 || W <= nj) continue;
                if (table[(i + ni) / 2][(j + nj) / 2]) continue;
                if (table[ni][nj] > 0) continue;
                table[ni][nj] = table[i][j] + 1;
                que.emplace(ni, nj);
            }
        }
        cout << max(0, table[H - 1][W - 1]) << endl;
    }
    return 0;
}


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

int main(){
    int m1,d1,m2,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(m1 != m2){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
	int x, y;
	cin >> x >> y;
	if (y % 2)
	{
		cout << "No" << endl;
		return 0;
	}
	else
	{
		if (2 * x <= y && y <= 4 * x)
		{
			cout << "Yes" << endl;
		}
		else
		{
			cout << "No" << endl;
		}
		return 0;
	}
}

Measured memory_bytes: 3616