akhauriyash/Code-Regression huggingface dataset:
type hand = Rock | Paper | Scissors
 
type result = Win | Lose | Draw
 
module HandSet = Set.Make (
                     struct
                       type t = hand
                       let compare (a : hand) b = compare a b
                     end)
 
let hand_of_int = function
  | 1 -> Some Rock
  | 2 -> Some Scissors
  | 3 -> Some Paper
  | _ -> None
 
let int_of_result = function
  | Win -> 1
  | Lose -> 2
  | Draw -> 3
 
exception BreakLoop
 
let read_hands () =
  try
    let hands = Array.init
                  5
                  (fun _ -> match read_int () |> hand_of_int with
                            | None -> raise BreakLoop
                            | Some hand -> hand) in
    Some (Array.to_list hands)
  with BreakLoop -> None
 
let match_ hands =
  let set = HandSet.of_list hands in
  if HandSet.cardinal set <> 2 then Array.make 5 Draw |> Array.to_list
  else
    let defeats a b =
      match a, b with
      | Rock, Paper -> false
      | Rock, Scissors -> true
      | Paper, Rock -> true
      | Paper, Scissors -> false
      | Scissors, Rock -> false
      | Scissors, Paper -> true
      | _ -> invalid_arg "defeats" in
    List.map
      (fun hand ->
       let match_ = HandSet.remove hand set |> HandSet.choose in
       if defeats hand match_ then Win else Lose)
      hands
 
let rec solve () =
  match read_hands () with
  | None -> ()
  | Some hands ->
     let results = match_ hands in
     List.iter
       (fun result ->
        int_of_result result |> print_int;
        print_newline ())
       results;
     solve ()
 
let () = solve ()

Measured memory_bytes: 2272
A = str(input())
n = len(A)
B = str(input())
m = len(B)
#dp[i][j], Aがi文字目、Bがj文字目までにおける最小処理回数
INF = float("inf")
dp = [[INF]*(m+1) for _ in range(n+1)]
#初期化の方法が特殊。片方が0でもう片方がi文字なら最小処理回数はi。
for i in range(n+1):
  dp[i][0] = i
for i in range(m+1):
  dp[0][i] = i

for i in range(n): #i = 0つまり、0文字目なのでdp[1][1]からスタート
  for j in range(m):
    if A[i] == B[j]: #同じ場合そのままか、片方が一つずれているところから追加挿入。
      dp[i+1][j+1] = min(dp[i][j],dp[i][j+1]+1,dp[i+1][j]+1)
    else: #異なる場合i文字目を交換か、片方が一つずれているところから追加挿入。
      dp[i+1][j+1] = min(dp[i][j]+1,dp[i][j+1]+1, dp[i+1][j]+1)
print(dp[n][m])
  


Measured memory_bytes: 41976
#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef dsu uf;
typedef fenwick_tree<ll> fw;

const ll mod=1e9+7;
const ll inf=1e18;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()



void solve(){
 int n,d;
  cin >> n >> d;
 vector<int> x(2*n);
  rep(i,0,2*n) cin >> x[i];
  
  two_sat s(2*n);
  rep(i,0,n){
   s.add_clause(i*2,true,i*2+1,true);
   s.add_clause(i*2,false,i*2+1,false);
  }
  
  rep(i,0,2*n){
   rep(j,i+1,2*n) if(abs(x[i]-x[j])<d) s.add_clause(i,false,j,false); 
  }
  
  if(s.satisfiable()){
   cout << "Yes" << endl; 
    vb ans=s.answer();
    rep(i,0,ans.size()) if(ans[i]) cout << x[i] << endl;
  }else{
  cout << "No" << endl;
    
  }
  
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 3736
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, c; cin >> a >> b >> c;
  if (a == b && b == c) print("Yes");
  else print("No");


  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int h,w,n;
	cin>>h>>w>>n;
	int ma=max(h,w);
	int ans;
	if(n%ma==0) ans=n/ma;
	else ans=n/ma+1;
	cout<<ans<<endl;
}
// 0 0 0
// 0 0 0
// 0 0 0
// 0 0 0
// 0 0 0
// 0 0 0
// 0 0 0


Measured memory_bytes: 256
#include <cstdio>
#include <set>
using namespace std;
#define R for(i=0;i<n;++i)
#define L(l,m,n) l=max(l,min(max(a[i]-e,m),max(f-a[i],n)));
int a[1<<17],b[1<<17],e=1e7,f=-1e7,g=1e7,h=-1e7,n,c,d,j=-1e7,k=-1e7,i;
int main(){
	scanf("%d",&n);
	R{scanf("%d%d",&c,&d);a[i]=c+d;b[i]=c-d;e=min(e,a[i]);f=max(f,a[i]);g=min(g,b[i]);h=max(h,b[i]);}
	R{L(j,b[i]-g,h-b[i])L(k,h-b[i],b[i]-g)}
	printf("%d\n",min(j,k));
}

Measured memory_bytes: 1816
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(int i=0;i<(int)N;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    ll c = x;

    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
        if (p[k] > sqrt(c)) { break; }
    }
    if (a > 1) { return b / a * (a - 1); }
    else { return b; }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    int N; cin >> N;
    vector<ll> A(N), le(N), ri(N), lr(N);
    rep(i, N) cin >> A[i];

    le[0] = A[0];

    for(int i=1; i<N; ++i){
        le[i] = gcd(le[i-1], A[i]);
    }

    ri[N - 1] = A[N - 1];

    for (int i = 1; i < N; ++i) {
        ri[N-i-1] = gcd(ri[N-i], A[N-1-i]);
    }

    lr[0] = ri[1]; lr[N - 1] = le[N - 2];

    for (int i = 1; i < N - 1; ++i) {
        lr[i] = gcd(ri[i+1], le[i-1]);
    }

    sort(lr.begin(), lr.end());

    cout << lr[N - 1] << endl;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/

int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    int s, w;
    cin >> s >> w;
    if(w>=s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}


Measured memory_bytes: 3608
#include<iostream>
#include<complex>
#include<cmath>

using namespace std;

typedef complex<double> P;

int main(){
  for(int N,M;cin>>N>>M,N;){
    double V[10];
    P p[10];
    for(int i=0;i<N;i++){
      double Dx,Dy;
      cin>>Dx>>Dy>>V[i];
      p[i]=P(Dx,Dy);
    }
    int nf[10]={};
    while(M--){
      double FPx,FPy,FVx,FVy;
      cin>>FPx>>FPy>>FVx>>FVy;
      int dx;
      double m=1e9;
      bool move[10]={};
      P v[10];
      for(int i=0;i<N;i++){
	double x=FPx-p[i].real();
	double y=FPy-p[i].imag();
	double a=FVx*FVx+FVy*FVy-V[i]*V[i];
	double b=x*FVx+y*FVy;
	double c=x*x+y*y;
	double D=b*b-a*c;
	if(D>=0){
	  double t=(-b+sqrt(D))/a;
	  double t2=(-b-sqrt(D))/a;
	  if(t<0||t2>=0&&t2<t){
	    t=t2;
	  }
	  if(t>=0){
	    move[i]=true;
	    v[i]=P(x+FVx*t,y+FVy*t);
	    if(t<m){
	      m=t;
	      dx=i;
	    }
	  }
	}
      }
      nf[dx]++;
      for(int i=0;i<N;i++){
	if(move[i]){
	  p[i]+=v[i]/abs(v[i])*V[i]*m;
	}
      }
    }
    for(int i=0;i<N;i++){
      cout<<nf[i]<<" \n"[i==N-1];
    }
  }
}

Measured memory_bytes: 1256
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
ll gcd(ll a,ll b){
    ll r,tmp;
    if(a<b){tmp=a;a=b;b=tmp;}
    r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int main(){
  int n,x;
  cin>>n>>x;
  vll a(n);
  REP(i,n){
    cin>>a[i];
    a[i]=abs(x-a[i]);
  }
  if(n==1){cout<<a[0]<<endl;}
  else{
    ll r=gcd(a[0],a[1]);
    if(x>2){
      FOR(i,2,n){
        r=gcd(r,a[i]);
      }
    }
    cout<<r<<endl;
  }
  
  
}


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

string s;
string t;

int q;

int memo_s[100010];
int memo_t[100010];

void making(string a,int * memo)
{
	char now = 'A';
	int cou = 0;

	for(int i = 0;i < a.size();i++)
	{
		if(a[i] == now)
		{
			cou++;
		}
		else
		{
			cou = 1;
			now = a[i];
		}

		if(now == 'A')
		{
			memo[i + 1] = memo[i] + 1;
		}
		else
		{
			if(cou % 2 == 1)
			{
				memo[i + 1] = memo[i] + 2;
			}
			else
			{
				memo[i + 1] = memo[i] - 1;
			}
		}
	}
}

bool solve(int a,int b,int c,int d)
{
	int sv = memo_s[b] - memo_s[a - 1];
	int tv = memo_t[d] - memo_t[c - 1];
	int mod = (max(sv,tv) - min(sv,tv));

	mod = mod % 3;

	return mod == 0;
}

int main()
{
	cin >> s >> t >> q;
	
	making(s,memo_s);
	making(t,memo_t);
	for(int i = 0;i < q;i++)
	{
		int a,b,c,d;
		cin >> a >> b >> c >> d;

		if(solve(a,b,c,d))
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	return 0;


}


Measured memory_bytes: 1664
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	stack<int> S;
	for (string s; cin >> s&&s != "$";) {
		int a, b;
		switch (s[0]) {
		case '+':
			b = S.top(); S.pop();
			a = S.top(); S.pop();
			S.push(a + b);
			break;
		case '-':
			b = S.top(); S.pop();
			a = S.top(); S.pop();
			S.push(a - b);
			break;
		case '*':
			b = S.top(); S.pop();
			a = S.top(); S.pop();
			S.push(a * b);
			break;
		default:
			S.push(atoi(s.c_str()));
			break;
		}
	}

	cout << S.top() << endl;

	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int N, M, L, Q;
int d[310][310];
int d2[310][310];

signed main() {
    cin >> N >> M >> L;
    rep(i, N) rep(j, N) d[i][j] = 1000000000000;
    rep(i, N) d[i][i] = 0;
    rep(i, M) {
        int A, B, C; cin >> A >> B >> C;
        d[A-1][B-1] = d[B-1][A-1] = C;
    }
    rep(k, N) rep(i, N) rep(j, N) d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
    
    rep(i, N) rep(j, N) d2[i][j] = 1000000000000;
    rep(i, N) d2[i][i] = 0;
    rep(i, N) rep(j, N) if (d[i][j]<=L) d2[i][j] = 1;
    rep(k, N) rep(i, N) rep(j, N) d2[i][j] = min(d2[i][j], d2[i][k]+d2[k][j]);
    
    cin >> Q;
    while (Q--) {
        int s, t; cin >> s >> t;
        int ans = d2[s-1][t-1];
        if (ans==1000000000000) cout << -1 << endl;
        else cout << ans-1 << endl;
    }
}

Measured memory_bytes: 2048
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
const int mod = 1000000007;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;
using namespace std;
ll gcd(ll a, ll b) {
	if (max(a, b) % min(a, b) == 0)return min(a, b);
	else return gcd(max(a, b)%min(a, b), min(a, b));
}
int main() {
	ll n, v[110],ans=1;
	cin >> n;
	rep(i, n) { cin >> v[i]; ans = ans/gcd(ans, v[i])*v[i]; }
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

 class Main{
    int high,low,sa;
	
    public void solve(){
        Scanner sc = new Scanner(System.in);
    
	     for(int i=0;i<7;i++){
	         high = sc.nextInt();
            	low = sc.nextInt();
	              sa = high-low;
	                 System.out.println(sa);
	     }
    }
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

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

int main(void){
    int n;
    cin >> n;
    int count = 0;
    rep(i,n){
        rep(j,n){
            rep(k,n){
                
                    count++;
                
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  Test
//
//  Created by Nag on 2017/08/18.
//  Copyright ?? 2017??´ Nag. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>

using namespace std;

int main(void) {
    string card1, card2;
    int score1, score2;
    int N;
    int i;
    
    cin >> N;
    
    score1 = score2 = 0;
    for(i=0; i<N; i++) {
        cin >> card1 >> card2;

        if( card1 < card2 ) score2 += 3;
        else if( card1 == card2 ) { score1++; score2++; }
        else if( card1 > card2 ) score1 += 3;
        
//        cout << card1 << " " << card2 << " : " << (card1 < card2) << " / " << score1 << " " << score2 << endl;
    }
    
    cout << score1 << " " << score2 << endl;
    
    return 0;
    
}

Measured memory_bytes: 3120
// Beginner159.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <climits>
#include <vector>

using namespace  std;

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

	int sum = 0;
	sum += n * (n - 1) / 2;
	sum += m * (m - 1) / 2;
	cout << sum;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int A,B;
  cin>>A>>B;
  if(A==B){cout<<"Draw";}
  else if(A==1){cout<<"Alice";}
  else if (B==1){cout<<"Bob";}
  else if (A>B){cout<<"Alice";}
  else cout<<"Bob";
    return 0;
}


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

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s;
	bool isMonthF = false, isMonthS = false;
	cin >> s;
	if ((s[0] == '0' and s[1] > '0') or (s[0] == '1' and s[1] <= '2'))
		isMonthF = true;
	if ((s[2] == '0' and s[3] > '0') or (s[2] == '1' and s[3] <= '2'))
		isMonthS = true;
	if (isMonthF and isMonthS)
		cout << "AMBIGUOUS" << endl;
	else if (isMonthF)
		cout << "MMYY" << endl;
	else if (isMonthS)
		cout << "YYMM" << endl;
	else
		cout << "NA" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define faf ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define ll long long
#define pb push_back
#define mp make_pair
#define For(i,k,n) for(i=k;i<=n;i++)


const  ll modo=1e9+7;



int main()
{
    faf;
    int a,b,c;
    cin>>a>>b>>c;
    int rr=a-b;
    int pp=min(a-b,c);
    int ans=c-pp;
    cout<<ans;




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
using Graph = vector<vector<int>>;
using Graph_Wei = vector<vector<pair<int,int>>>;
using ll = long long;
const long long INF = 1LL<<60; // 仮想的な無限大の値
vector<bool> seen;

Graph G;


int main() {
    // int a;
    // int b;
    // int c;

    // a = 'a';
    // b = 'b';
    // c = 'c';
    // cout << a << endl;
    // cout << b << endl;
    // cout << c << endl;
    //

    string str;
    cin >> str;
    //アルファベット出現回数記録用
    int b[26] = {};//全要素０で初期化
    int a = 'a';
    for(int i =0; i < str.length();i++){
        int t = str[i];
        b[t - a]++;
    }
    int cnt = 0;
    for(int i =0;i < 26;i++){
        cnt += b[i] % 2;
    }

    if(cnt == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }



    return 0;

}

Measured memory_bytes: 256
// ABC168 B Triple Dots
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  // 初期値
  int K, length;
  string S;
  cin >> K >> S;
  length = S.size();
  
  //Main loop
  for (int i = 0; i < length; i++){
    if (i < K){
      cout << S.at(i);
    } else if (i == K){
      cout << "...";
      break;
    }
  }
   
  return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}


// successor graph
const int N=2e5+5;
int succ[61][N];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    LL n,k;
    cin >> n >> k;
    VI a(n+1);
    REP1(i,1,n) {
        cin >> a[i]; 
    }
    REP1(i,1,n) {
        succ[0][i]=a[i];
    }
    REP1(i,1,60) {
        REP1(j,1,n) {
            succ[i][j]=succ[i-1][succ[i-1][j]];
        }
    }
    int v=1;
    for ( int i=60; i>=0; i-- ) {
        if ( k>>i&1 ) {
            v=succ[i][v];
        }
    }
    cout << v << '\n';
    return 0;
}

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

using namespace std;

const int N = (int) 1e4+5;
int h, n, dp[N];
vector<int> a, b;

int dfs(int h)
{
    if (h <= 0) return 0;
    if (dp[h] == 0) {
        int an = 1e9;
        for (int i = 0; i < n; ++i) {
            an = min(an, dfs(h-a[i]) + b[i]);
        }

        dp[h] = an;
    }

    return dp[h];
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> n;
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        a.push_back(x);
        b.push_back(y);
    }

    memset(dp, 0, sizeof(dp));
    cout << dfs(h) << endl;

    return 0;
}


Measured memory_bytes: 768
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
		int H = sc.nextInt();
        int W = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();
		System.out.println((H-h)*(W-w));
  }
}

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

int N,M,X,i,bil,sum,mus;

int main(){
	cin>>N>>M>>X;
	for (i = 1;i <= M;i ++) {
		cin>>bil;
		if (bil < X) {
			sum ++;
		}
		else {
			mus ++;
		}
	}
	if (sum > mus) {
		cout<<mus<<endl;
	}
	else {
		cout<<sum<<endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n;
  cin>>n;
  vector<Int> ds(n);
  for(Int i=0;i<n;i++) cin>>ds[i];

  sort(ds.begin(),ds.end());
  cout<<ds[n/2]-ds[n/2-1]<<endl;
  return 0;
}


Measured memory_bytes: 1024
#import <Foundation/Foundation.h>
#import <stdio.h>

int main(int argc, char **argv) {
	NSInteger M, N;
    scanf("%ld %ld", &M, &N);
    for (NSInteger i = 0; i < N; i++) {
    	NSInteger cost;
        scanf("%ld", &cost);
    	M -= cost;
    }
    printf("%ld", MAX(-1, M));
	return 0;
}

Measured memory_bytes: 12524
require 'prime'
n = gets.chomp.to_i
ans = 0
divisor = []
i = 1
while i * i <= n
    if n % i == 0 then
        divisor << i
        tmp = n / i
        divisor << tmp if tmp != i
    end
    i += 1
end
divisor.sort!

divisor.each do |e|
    break if n < e
    if Prime.prime_division(e).size == 1 then
        next if n % e != 0
        n /= e
        ans += 1
    end
end

puts ans

Measured memory_bytes: 14500
import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._

  val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
  val edges = Array.tabulate(m){_ ⇒
    val Array(a, b) = readLine.trim.split(' ').map(_.toInt - 1)
    (a, b)
  }
  val nodes = Array.tabulate(n){_ ⇒ new UnionFind}
  var current = n.toLong * (n - 1) / 2
  var history = Nil: List[Long]
  for ((a, b) ← edges.reverse){
    history ::= current
    if (!nodes(a).isSameUnion(nodes(b))) {
      current -= nodes(a).size * nodes(b).size
      nodes(a).merge(nodes(b))
    }
  }
  println(
    history.mkString("\n")
  )

  class UnionFind{
    private var mParent: UnionFind = this
    private var mSize: Int = 1
    private def parent: UnionFind = {
      if (mParent != this){
        mParent = mParent.parent
      }
      mParent
    }
    def isSameUnion(that: UnionFind): Boolean = {
      parent == that.parent
    }
    def size: Int = parent.mSize
    def merge(that: UnionFind): Unit = {
      if (!isSameUnion(that)){
        val thisP = parent
        val thatP = that.parent
        if (thisP.mSize < thatP.mSize){
          thisP.mParent = thatP
          thatP.mSize += thisP.mSize
        }else {
          thatP.mParent = thisP
          thisP.mSize += thatP.mSize
        }
      }
    }
  }
}


Measured memory_bytes: 82964
#pragma comment(linker, "/STACK:102400000,102400000")
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#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 <ctime>
#include <cstring>
#define LL long long
using namespace std;
const int M = 1e5 + 5, INF = 0x3f3f3f3f, mod = 1000007;
char s[M];
int main() {
    scanf("%s",s);
    int n=strlen(s);
    int K;
    scanf("%d",&K);
    for(int j=0;j<n;j++){
        int now='z'-s[j]+1;
        if(s[j]!='a'&&K>=now){
            s[j]='a';
            K-=now;
        }
    }
    int t=s[n-1]-'a';
    t=(t+K)%26;
    s[n-1]=t+'a';
    printf("%s\n",s);
    return 0;
}


Measured memory_bytes: 384
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>

#define mp make_pair

using namespace std;

const int Mxn=100005;
const int Mxm=1005;
int sum[Mxm*4][Mxm*4];
struct eeee{
	int x,y;
	char c;
}a[Mxn];
inline int find(int x,int y,int X,int Y){
	return sum[x][y]-sum[x][Y+1]-sum[X+1][y]+sum[X+1][Y+1];
}
int n,m,tm,fm;
int main(){
	cin>>n>>m;
	tm=m*2;
	fm=tm*2;
	int i,j;
	for(i=1;i<=n;i++) cin>>a[i].x>>a[i].y>>a[i].c;
	for(i=1;i<=n;i++){
		if(a[i].c=='B') sum[a[i].x%tm][a[i].y%tm]++;
		else sum[(a[i].x+m)%tm][a[i].y%tm]++;
	}
	for(i=0;i<tm;i++) for(j=0;j<tm;j++){
		sum[i][j+tm]=sum[i][j];
		sum[i+tm][j]=sum[i][j];
		sum[i+tm][j+tm]=sum[i][j];
	}
	for(i=fm-1;i>-1;i--) for(j=fm-1;j>-1;j--) sum[i][j]=sum[i][j]+sum[i+1][j]+sum[i][j+1]-sum[i+1][j+1];
	int ans=0;
	for(i=0;i<tm;i++) for(j=0;j<tm;j++) ans=max(ans,find(i,j,i+m-1,j+m-1)+find(i+m,j+m,i+tm-1,j+tm-1));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 64512
#include<iostream>
#include<vector>
#include<queue>
#include<utility>

using namespace std;

pair<int,int> finish(vector<vector<int>> a,int h,int w){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]==1){return make_pair(i,j);}
    }
  }
  return make_pair(h,w);
}

//沈めてく
void idlands(int H,int W){
  vector<vector<int>> d(H,vector<int>(W,0));
  queue< pair<int,int> > x;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> d[i][j];
    }
  }
  int l=1;
  int c=0;
  while(finish(d,H,W)!=make_pair(H,W)){
    x.push(finish(d,H,W));
    c+=1;l=x.size();d[x.front().first][x.front().second]=0;
    while(l!=0){
      for(int i=0;i<l;i++){
        int h,w;h=x.front().first;w=x.front().second;
        if(0<h and d[h-1][w]==1){
          x.push(make_pair(h-1,w));d[h-1][w]=0;}
        if(h<H-1 and d[h+1][w]==1){
          x.push(make_pair(h+1,w));d[h+1][w]=0;}
        if(0<w and d[h][w-1]==1){
          x.push(make_pair(h,w-1));d[h][w-1]=0;}
        if(w<W-1 and d[h][w+1]==1){
          x.push(make_pair(h,w+1));d[h][w+1]=0;}
        if(0<h and w<W-1 and d[h-1][w+1]==1){
          x.push(make_pair(h-1,w+1));d[h-1][w+1]=0;}
        if(h<H-1 and 0<w and d[h+1][w-1]==1){
          x.push(make_pair(h+1,w-1));d[h+1][w-1]=0;}
        if(0<h and 0<w and d[h-1][w-1]==1){
          x.push(make_pair(h-1,w-1));d[h-1][w-1]=0;}
        if(h<H-1 and w<W-1 and d[h+1][w+1]==1){
          x.push(make_pair(h+1,w+1));d[h+1][w+1]=0;}
        x.pop();
      }
      l=x.size();
    }
  }
  cout << c << endl;
}

int main(){
  int W,H;
  while(cin >> W >> H and W!=0){
    idlands(H,W);
  }
}



Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int k;cin>>k;
    string s;cin>>s;
    if(s.length()<=k)cout<<s;
    else cout<<s.substr(0,k)<<"...";
}


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
using namespace std;
class taxi {
public:
	int money, can, point;
	taxi(int a, int b, int c) :money(a), can(b), point(c) {

	}
};
class city {
public:
	int much,can;
	vector<int> road;
	bool use;
};
bool operator < (const taxi &a, const taxi &b) {
	return a.money < b.money;
}
bool operator >(const taxi &a, const taxi &b) {
	return a.money > b.money;
}
int main() {
	int N, K;
	cin >> N >> K;
	int a, b;
	city *map;
	++N;
	map = new city[N];
	for (int i = 1; i < N; ++i) {
		cin >> map[i].much >> map[i].can;
		map[i].use = true;
	}
	--N;
	for (int i = 0; i < K; ++i) {
		cin >> a >> b;
		map[a].road.push_back(b);
		map[b].road.push_back(a);
	}
	vector<int>::iterator go, to;
	priority_queue < taxi, vector<taxi>, greater<taxi> > que;
	que.push(taxi(0, 0, 1));
	while (true) {
		taxi dummy = que.top(); que.pop();
		if (dummy.point == N) {
			cout << dummy.money << endl;
			break;
		}
		if (dummy.can > 0) {
			for (go = map[dummy.point].road.begin(), to = map[dummy.point].road.end(); go != to; ++go) {
				que.push(taxi(dummy.money, dummy.can - 1, *go));
			}
		}
		if (map[dummy.point].use) {
			map[dummy.point].use = false;
			dummy.money += map[dummy.point].much;
			dummy.can = map[dummy.point].can;
			for (go = map[dummy.point].road.begin(), to = map[dummy.point].road.end(); go != to; ++go) {
				que.push(taxi(dummy.money, dummy.can - 1, *go));
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3796
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
const ll MOD = 1e9+7;
long long modpow(long long a, long long n) {
      long long res = 1;
      while (n > 0) {
          if (n & 1) res = res * a % MOD;
          a = a * a % MOD;
          n >>= 1;
      }
      return res;
  }
 ll inv_mul(ll x, ll y){
     return (x % MOD* modpow(y,MOD-2))%MOD;
 }
int main() {
    ll n;
    std::cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        sum += a[i];
        sum %= MOD;
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += sum*a[i]%MOD;
        ans = ans - a[i]*a[i]%MOD + MOD;
        ans %= MOD;
    }
    std::cout << inv_mul(ans,2) << std::endl;
}


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

int main() {

    int n;

    cin >> n;

    vector<int> v(n);

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

    set<int> canSum;

    int maxBit = 1 << n;
    for(int i = 1; i < maxBit; ++i) {

        int bit = 1;
        int index = 0;
        int sum = 0;
        while(bit < maxBit) {
            
            if(i&bit)
                sum += v[index];
            index++;
            bit = bit << 1;
        }
        
        canSum.insert(sum);
    }


    int q;
    cin >> q;

    int maxN = 1 << n;
    for(int i = 0; i < q; ++i) {

        int num;
        cin >> num;

        if(canSum.find(num) != canSum.end())
            cout << "yes";
        else
            cout << "no";
        cout << endl;

    }

    return 0;

}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

signed main(){
   IOS;
   vector<int> v(5);
   for(int i = 0; i < 5; i++) {
      cin >> v[i];
      if(v[i] == 0) {
         cout << i+1 << "\n";
         return 0;
      }
   }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
 
int main(){
  int n, m; cin >> n >> m;
  map<int, int> mp[n+1];
  int p[m+1], y[m+1];
 
  REP(i, m){
    cin >> p[i] >> y[i];
    mp[p[i]][y[i]]++;
  }
 
  FOR(i, 1, n+1){
    int cnt = 1;
    for(auto& x: mp[i]){
      x.second = cnt++;
    }
  }
 
  REP(i, m){
    printf("%06d%06d\n", p[i], mp[p[i]][y[i]]);
  }
 
  return 0;
}

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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

constexpr int MAXS = 100000;

char S[MAXS + 2];

int main() {
	cin >> S;
	int ls = strlen(S);
	int a = 0, b = 0, c = 0, d = 0;
	for(int i = 0; i < ls; i++)
		if(i & 1)
			if(S[i] == '0')
				a++;
			else
				b++;
		else
			if(S[i] == '0')
				c++;
			else
				d++;
	cout << min(b + c, a + d) << endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
  int d; cin >> d;
  if(d == 25)
    cout << "Christmas" << endl;
  else if(d == 24)
    cout << "Christmas Eve" << endl;
  else if(d == 23)
    cout << "Christmas Eve Eve" << endl;
  else if(d == 22)
    cout << "Christmas Eve Eve Eve" << endl;  
}


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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		int n = sc1.nextInt();
		int m = sc1.nextInt();
		Long[] list1 = new Long[n];
		Long[] list2 = new Long[n];
		Long[] list3 = new Long[n];
		Long[] list4 = new Long[n];
		Long[] list5 = new Long[n];
		Long[] list6 = new Long[n];
		Long[] list7 = new Long[n];
		Long[] list8 = new Long[n];

		for (int i = 0 ; i < n ; i++ ) {
			Long x = sc1.nextLong();
			Long y = sc1.nextLong();
			Long z = sc1.nextLong();

			list1[i] =  x + y + z;
			list2[i] = -x + y + z;
			list3[i] =  x - y + z;
			list4[i] =  x + y - z;
			list5[i] = -x + y - z;
			list6[i] = -x - y + z;
			list7[i] =  x - y - z;
			list8[i] = -x - y - z;
		}

		Arrays.sort(list1, Comparator.reverseOrder());
		Arrays.sort(list2, Comparator.reverseOrder());
		Arrays.sort(list3, Comparator.reverseOrder());
		Arrays.sort(list4, Comparator.reverseOrder());
		Arrays.sort(list5, Comparator.reverseOrder());
		Arrays.sort(list6, Comparator.reverseOrder());
		Arrays.sort(list7, Comparator.reverseOrder());
		Arrays.sort(list8, Comparator.reverseOrder());

		Long[] anslist = new Long[8];
		anslist[0] = 0L;
		anslist[1] = 0L;
		anslist[2] = 0L;
		anslist[3] = 0L;
		anslist[4] = 0L;
		anslist[5] = 0L;
		anslist[6] = 0L;
		anslist[7] = 0L;

		for (int j = 0 ; j < m ; j++) {
			anslist[0] += list1[j];
			anslist[1] += list2[j];
			anslist[2] += list3[j];
			anslist[3] += list4[j];
			anslist[4] += list5[j];
			anslist[5] += list6[j];
			anslist[6] += list7[j];
			anslist[7] += list8[j];
		}

		Arrays.sort(anslist, Comparator.reverseOrder());

		System.out.println(anslist[0]);

		sc1.close();

	}

}

Measured memory_bytes: 26220
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  vll abc(3); REP(i, 3) cin >> abc[i];
  sort(abc.begin(), abc.end());
  if (abc[0]+abc[1] == abc[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
char N_[9],W_[20];
main()
{
	read(0,N_,9);
	int N=0;
	for(int i=0;N_[i]>='0';i++)N=N*10+N_[i]-'0';
	long ans=0;
	int i=1;
	while(i<=N)
	{
		long j=N/(N/i)+1;
		ans+=(j-i)*(i+j-1)*(N/i)*(N/i+1)/4;
		i=j;
	}
	i=20;
	do{W_[--i]=ans%10+'0';}while(ans/=10);
	write(1,W_+i,20-i);
}

Measured memory_bytes: 1384
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char a[10000000];
int main()
{
	scanf("%s",&a);
	for(int i=0;i<=strlen(a)-1;i++)
	if(a[i]=='9')
	{
	printf("Yes");
	return 0;}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		scanner.useDelimiter("[\\n,]");
		int l_num = scanner.nextInt();
		int w_num = scanner.nextInt();
		int[] ans = new int[l_num];
		int tmp;
		for(int i=0; i<l_num; i++){
			ans[i] = i+1;
		}
		int[] change = new int[2*w_num];
		for(int i=0; i <w_num ; i++){
			change[i*2] = scanner.nextInt();
			change[(i*2)+1] = scanner.nextInt();
		}
		for(int i=0; i<w_num ; i++){
			tmp = ans[change[i*2]-1];
			ans[change[i*2]-1] = ans[change[i*2+1]-1];
			ans[change[i*2+1]-1] = tmp;		
		}
		for(int i=0; i<l_num; i++){
			System.out.println(ans[i]);
		}
	}
}

Measured memory_bytes: 17212
#include<bits/stdc++.h>
using namespace std;
int N,M;
int G[100][100];
int a[1000],b[1000],c[1000];

int main(){
  fill(G[0],G[100],1e9);
  for(int i=0;i<100;i++)G[i][i]=0;
  cin>>N>>M;
  for(int i=0;i<M;i++){
    cin>>a[i]>>b[i]>>c[i];
    a[i]--;b[i]--;
    G[ a[i] ][ b[i] ]=min( G[ a[i] ][ b[i] ] , c[i] );
    G[ b[i] ][ a[i] ]=min( G[ b[i] ][ a[i] ] , c[i] );
  }
  
  for(int k=0;k<N;k++)
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
        G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
  
  int ans=0;
  for(int i=0;i<M;i++){
    bool flg=true;
    for(int si=0;si<N;si++){
      for(int ti=0;ti<N;ti++){
        if( G[si][ a[i] ] + G[ b[i] ][ti] +c[i]== G[si][ti] )flg=false;
        if( G[si][ b[i] ] + G[ a[i] ][ti] +c[i]== G[si][ti] )flg=false;
      }
    }
    if(flg){    
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FASTIO
#define endl "\n"  // Since endl forces a buffer flush which slows down large I/O operations.
#define ff first
#define ss second
#define pb push_back
#define input(c, n) for (int i = 0; i < n; i++) cin >> c[i];
#define exit_message(s) return 0*printf(s)
#define show(c) for (auto i: c) cout << i << " "; cout << "\n";
#define display(c, n) for (int i = 0; i < n; i++) cout << c[i] << " "; cout << "\n";
#define forl(i, a, n) for (int i = a; i < n; i++)
#define dugbe(k) cout << "-\t> " << #k << " = " << k << "\n";

/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/

using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
typedef pair<ll, ll> prll;
typedef vector<int> vi;
typedef vector<ll> vill;
typedef vector<pr> vpr;
ifstream in("input.txt");
const ll mod = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long true_rand(long long n)
{
	// Returns a random number between 0 and n - 1 inclusive using mt19937.
    uniform_int_distribution<long long> uid(0, n - 1);
    return uid(rng);
}

ll mod_pow(ll a, ll b)
{
	if (b == 0)
		return 1LL;

	ll res = mod_pow(a, b>>1);
	res = (res*res)%mod;
	if (b&1LL)
		res = (res*a)%mod;
	
	return res;
}

const int N = 1e5 + 5;

int32_t main()
{
	#ifdef FASTIO
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int h, w, n;
	cin >> h >> w >> n;
	int sr, sc;
	cin >> sr >> sc;
	string s, t;
	cin >> s >> t;

	char moves[] = {'R', 'L', 'U', 'D'};

	map<char, pr> mp;
	mp['R'] = {1, 0};
	mp['L'] = {-1, 0};
	mp['U'] = {0, -1};
	mp['D'] = {0, 1};

	int fail = 0;
	int f[2][140] = {};
	forl(i, 0, n)
	{
		f[0][s[i]]++;
		
		// Right.
		if (sc + f[0]['R'] - f[1]['L'] > w)
			fail = 1;
		// Left.
		if (sc - f[0]['L'] + f[1]['R'] < 1)
			fail = 1;
		// Up.
		if (sr - f[0]['U'] + f[1]['D'] < 1)
			fail = 1;
		// Down.
		if (sr + f[0]['D'] - f[1]['U'] > h)
			fail = 1;

		if (t[i] == 'L' && sc + f[0]['R'] - f[1]['L'] > 1)
			f[1][t[i]]++;
		if (t[i] == 'R' && sc - f[0]['L'] + f[1]['R'] < w)
			f[1][t[i]]++;
		if (t[i] == 'U' && sr + f[0]['D'] - f[1]['U'] > 1)
			f[1][t[i]]++;
		if (t[i] == 'D' && sr - f[0]['U'] + f[1]['D'] < h)
			f[1][t[i]]++;
	}
	if (fail)
		cout << "NO\n";
	else
		cout << "YES\n";

	return 0;
}

Measured memory_bytes: 920
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n+2];
  for(int i=1;i<n+1;i++) cin >> a[i];
  a[0]=0,a[n+1]=0;
  int t=0;
  for(int i=0;i<n+1;i++){
    t+=abs(a[i+1]-a[i]);
  }
  for(int i=0;i<n;i++){
    if(abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2])==abs(a[i]-a[i+2])){
      cout << t << endl;
    }
    else{
      cout << t-2*min(abs(a[i]-a[i+1]),abs(a[i+1]-a[i+2])) << endl;
    }
  }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

int dpx[8]={1,1,1,-1,-1,-1,0,0};
int dpy[8]={-1,1,0,1,-1,0,-1,1};

int32_t main()
{
	fastIO
	inp_out();
	int n, ans = 0; 
	cin >> n; 
	vi a(n); 
	for(int i = 0; i < n;  ++ i)
	{
		int x; 
		cin >> x; 
		if(i % 2 == 0 && (x & 1))
			 ++ ans; 
	}
	cout << ans; 
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;

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

  int n, k;
  cin >> n >> k;
  
  int cnt = 0;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    if (a[i] > 0) ++cnt;
  }

  sort(a.begin(), a.end(), [&](int l, int r) {
      return abs(l) > abs(r);
  });
  
  if (k == n || !cnt) {
    long long ans = 1;
    if (k&1) for (int i = n - 1; i >= n - k; --i) ans = ans * a[i] % M;
    else for (int i = 0; i < k; ++i) ans = ans * a[i] % M;
    if (ans < 0) ans += M;
    cout << ans << '\n';
    return 0;
  }
  
  int sign = 1;
  for (int i = 0; i < k; ++i) {
    if (a[i] < 0) sign *= -1;
  }
  
  if (sign == -1) {
    int neg = -1, pos = -1, lneg = -1, lpos = -1;
    for (int i = k; i < n; ++i) {
      if (neg == -1 && a[i] < 0) neg = i;
      if (pos == -1 && a[i] >= 0) pos = i;
    }
    for (int i = k - 1; i >= 0; --i) {
      if (lneg == -1 && a[i] < 0) lneg = i;
      if (lpos == -1 && a[i] >= 0) lpos = i;
    }
    if (lneg == -1 || pos == -1) swap(a[lpos], a[neg]);
    else if (lpos == -1 || neg == -1) swap(a[lneg], a[pos]);
    else {
      if (1ll * a[lpos] * a[pos] >= 1ll * a[lneg] * a[neg]) swap(a[lneg], a[pos]);
      else swap(a[lpos], a[neg]);
    }
  }

  long long ans = 1;
  for (int i = 0; i < k; ++i) ans = ans * a[i] % M;
  if (ans < 0) ans += M;
  cout << ans << '\n';
}


Measured memory_bytes: 3992
#include <stdio.h>
int main(){
	int	h, w, n, a, idx=0;
	int	x[10201]={0}, col[101][101]={0};
	scanf("%d %d %d", &h, &w, &n);

	for(int i=1; i<=n; i++){
		scanf("%d", &a);
		for(int j=0; j<a; j++){ x[idx+j]=i; }
		idx += a;
	}

	idx = 0;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			col[i][j] = x[idx];
			idx++;
		}
	}
	
	for(int i=0; i<h; i++){
		if(i%2){
			for(int j=w-1; j>=0; j--){ printf("%d ", col[i][j]); }
          	printf("\n");
		}else{
			for(int j=  0; j< w; j++){ printf("%d ", col[i][j]); }
          	printf("\n");
		}
	}
	return 0;
}

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

const double EBS=1e-8;

int main(){
	while(1){
		int m, v[400];
		int arg=360;
		double a=0, b=0;
		
		scanf(" %d", &m);
		if(m==0) break;
		for(int i=0; i<m-1; ++i){
			scanf(" %d", &v[i]);
			arg-=v[i];
			a+=sin(v[i]*M_PI/180.0);
		}
		a+=sin(arg*M_PI/180.0);
		
		arg=360;
		scanf(" %d", &m);
		for(int i=0; i<m-1; ++i){
			scanf(" %d", &v[i]);
			arg-=v[i];
			b+=sin(v[i]*M_PI/180.0);
		}
		b+=sin(arg*M_PI/180.0);
		
		//printf(" a=%lf, b=%lf\n", a, b);
			
		if(fabs(a-b) < EBS) printf("0\n");
		else if(a>b) printf("1\n");
		else if(a<b) printf("2\n");
	}
}

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

using namespace std;

#define ll long long
#define N 10000000


int main() {
//#ifndef ONLINE_JUGDE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif

	ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    if(n>=30)
    	cout<<"Yes";
    else
    	cout<<"No";
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	int x=a-b;
	if(c>=x)
	{
		printf("%d\n",c-x);
	}
	else
	{
		printf("0\n");
	}
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
int main(void)
{
	char u[10][100];
	int n, i;
	double x[100], s, s1, s2;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
	    scanf("%lf",&x[i]);
	    scanf("%s",u[i]);
	}
	s1=s2=0;
	for(i=0;i<n;i++){
	    if(strcmp(u[i],"BTC")==0) s1+=x[i];
	    else s2+=x[i];
	}
	s=s1*380000.0+s2;
	printf("%lf\n",s);
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner =new Scanner(System.in);
        int a=scanner.nextInt();
        int b=scanner.nextInt();
        int c=scanner.nextInt();
        if(a<b&&b<c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}



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

int main(){
  int N;

  cin>>N;

  int i,j;
  vector<vector<int>> a(2,vector<int>(N));

  for(i=0;i<2;i++){
    for(j=0;j<N;j++)
    cin>>a.at(i).at(j);
  }

  vector<int> b(N);
  vector<int> c(N);

  b.at(0)=a.at(0).at(0);
  c.at(0)=a.at(0).at(0)+a.at(1).at(0);

  for(i=1;i<N;i++){
    b.at(i)+=(a.at(0).at(i)+b.at(i-1));
    c.at(i)+=(a.at(1).at(i)+max(b.at(i),c.at(i-1)));
  }

  // for(i=0;i<N-1;i++){
  //   cout<<b.at(i)<<" ";
  // }
  // cout<<b.at(N-1)<<endl;
  // for(i=0;i<N-1;i++){
  //   cout<<c.at(i)<<" ";
  // }
  // cout<<c.at(N-1)<<endl;

  cout<<c.at(N-1)<<endl;
}


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

vector<vector<int>> adj = {
    {1, 4},
    {0, 2, 5},
    {1, 3, 6},
    {2, 7},
    {0, 5},
    {1, 4, 6},
    {2, 5, 7},
    {3, 6}
};
map<vector<int>, int> d;

void solve() {
    vector<int> init = {0, 1, 2, 3, 4, 5, 6, 7};
    d[init] = 0;
    queue<vector<int>> q;
    q.push(init);
    while ( ! q.empty()) {
        vector<int> v = q.front();
        q.pop();
        int step = d[v];
        for (int i=0; i<8; ++i) {
            if (v[i] == 0) {
                for (int j=0; j<(int)adj[i].size(); ++j) {
                    swap(v[i], v[adj[i][j]]);
                    if (d.find(v) == d.end()) {
                        q.push(v);
                        d[v] = step + 1;
                    }
                    swap(v[i], v[adj[i][j]]);
                }
            }
        }
    }
}

int main() {
    solve();
    while (1) {
        vector<int> v(8);
        for (int i=0; i<8; ++i) {
            if (cin >> v[i]) { } else { return 0; }
        }
        cout << d[v] << endl;
    }
    return 0;
}

Measured memory_bytes: 3760