akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.end()

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;

void solve();

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

void solve()
{
    int h, a;
    in2(h, a);
    out((h - 1) / a + 1);
}

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

match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
d = dict()
for e in a:
    d[e] = match[e]

dp = [-1] * (n + 1)
dp[0] = 0
for i in range(1, n + 1):
    for k, v in d.items():
        if i - v >= 0 and dp[i-v] != -1:
            dp[i] = max(dp[i], dp[i-v] * 10 + k)

print(dp[n])


Measured memory_bytes: 14516
#include <stdio.h>

#define N 100
#define min(a, b) ( a < b ? a : b )
#define max(a, b) ( a > b ? a : b )
#define INF 999999

int main(void)
{
    int i, j, l, k ,q;
    int n;
    int r, c;
    int p[N+1] = {0};
    int m[(N+1)*(N+1)] = {0};

    scanf( "%d", &n );
    for( i=0; i<n; ++i ) {
        scanf( "%d%d", &r, &c );
        p[i] = r;
    }
    p[n] = c;

    for( i=1; i<=n; ++i )
        m[i*n+i] = 0;

    for( l=2; l<=n; ++l ) {
        for( i=1; i<=n-l+1; ++i ) {
            j = i + l - 1;
            m[i*n+j] = INF;
            for( k=i; k<=j-1; ++k ) {
                q = m[i*n+k] + m[(k+1)*n+j] + p[i-1] * p[k] * p[j];
                m[i*n+j] = min( m[i*n+j], q );
            }
        }
    }

    printf( "%d\n", m[1*n+n] );

    return 0;
}



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

int main() {
  int A, B;
  cin >> A >> B;

  if (A % 2 == 1 && B % 2 == 1) {
    cout << "Odd" << endl;
  }else{
    cout << "Even" << endl;
  }
  
}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

n = int(input())

yaku = make_divisors(n)

ans = 0
for y in yaku:
    m = y - 1
    if m and (n//m == n % m):
        ans += m
print(ans)

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n+1), b(n), res(n);
    rep1(i, n+1) cin >> a[i];
    rep1(i, n) cin >> b[i];
    ll ans = 0;
    rep1(i, n){
        ans += min(a[i], b[i]);
        res[i] = b[i]-a[i];
        if (res[i]<0) res[i] = 0;
        ans += min(a[i+1], res[i]);
        a[i+1] -= res[i];
        if (a[i+1]<0) a[i+1] = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5540
#-*-coding:utf-8-*-

def get_input():
    for i in range(int(input())):
        yield "".join(input())

if __name__ == "__main__":
    array = list(get_input())
    
    for i in range(len(array)):        
        a,b,c = array[i].split()
        if int(a)**2 + int(b)**2 == int(c)**2:
            print(u"YES")
        elif int(c)**2 + int(a)**2 == int(b)**2:
            print(u"YES")
        elif int(b)**2 + int(c)**2 == int(a)**2:
            print(u"YES")
        else:
            print(u"NO")

Measured memory_bytes: 7792
#include <stdio.h>

int main()

{

    int n ;

    scanf("%d",&n) ;

    if( n % 2 == 0 )  {

        printf("%d\n",(n/2)*(n/2)) ;

    }

    else  {

        printf("%d\n",(n/2)*((n/2)+1)) ;

    }

    return 0 ;

}


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

const int N = 1e5+2;
bool check(int z)
{ int i;
   for(i=2;i*i<=z;i++)
    { if(z%i==0)
       return false;
    }
    return true;
}
int main()
{
 int x;
    cin>>x;
    while(!check(x))x++;
    cout<<x;
 }      

Measured memory_bytes: 3164
N = int(input())
ans_lis = [[0] * 9 for i in range(9)]
for i in range(1,N+1):
  t = str(i)
  mae = int(t[0])
  ushiro = int(t[-1])
  if ushiro == 0:
    continue
  ans_lis[mae-1][ushiro-1] += 1
ans = 0
for i in range(9):
  for j in range(9):
    ans += ans_lis[i][j] * ans_lis[j][i]
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
using ll = long long;
int main() {
	int N, K; cin >> N >> K;
	ll dp[1000];
	dp[0] = 1;
	for (int i = 1; i < N; i++)
		dp[i] = dp[i - 1] * (K - 1);
	ll res = K * dp[N - 1];
	cout << res << endl;
	//system("pause");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<ii,int> ti;
typedef vector<ii> vii;
typedef vector<vi> vvi;
int v[200200];
int sp[2][200200][18];
int lp[200200];
int n;
int lg(int n) {
	if(n <= 1) return 0;
	if(lp[n] != -1) return lp[n];
	return lp[n] = 1+lg(n/2);
}
int qu(int l, int r) {
	int id = l%2;
	//printf("query %d %d\n",l,r);
	l = (l-id)/2;r = (r-id)/2;
	int k = lg(r-l+1);
	if(v[sp[id][l][k]] <= v[sp[id][r-(1<<k)+1][k]]) return sp[id][l][k];
	return sp[id][r-(1<<k)+1][k];
}
void pre() {
	for(int id = 0;id<2;id++) {
		for(int i=0;i<(n+1-id)/2;i++) {
			sp[id][i][0] = i*2+id;
		}
		for(int j=1;(1<<j) <= n;j++) {
			for(int i=0;i+(1<<j)-1<n;i++) {
				if(v[sp[id][i][j-1]] < v[sp[id][i+(1<<(j-1))][j-1]]) {
					sp[id][i][j] = sp[id][i][j-1];
				} else {
					sp[id][i][j] = sp[id][i+(1<<(j-1))][j-1];
				}
			}
		}
	}
}
vi g[200100];
ii bs[200100];
int ctr = 0;
void pr(int l, int r,int u) {
	//printf("find %d %d, v %d\n",l,r,u);
	int ml = qu(l,r);
	int mr = qu(ml+1,r);
	bs[u] = {v[ml],v[mr]};
	if(ml-1 >= l) {
		ctr++;
		int k = ctr;
		pr(l,ml-1,k);
		g[u].push_back(k);
	}
	if(mr-1 >= ml+1) {
		ctr++;
		int k = ctr;
		pr(ml+1,mr-1,k);
		g[u].push_back(k);
	}
	if(mr+1 <= r) {
		ctr++;
		int k = ctr;
		pr(mr+1,r,k);
		g[u].push_back(k);
	}
}
int main() {
	memset(lp,-1,sizeof(lp));
	scanf("%d ",&n);
	for(int i=0;i<n;i++) {
		scanf("%d ",&v[i]);
	}
	pre();
	pr(0,n-1,ctr);
	priority_queue<ti,vector<ti>,greater<ti>> pq;
	pq.push(make_pair(bs[0],0));
	vi res;
	while(!pq.empty()) {
		ii va = pq.top().first;
		int id = pq.top().second;pq.pop();
		res.push_back(va.first);
		res.push_back(va.second);
		for(int i=0;i<g[id].size();i++) {
			int u = g[id][i];
			//printf("%d -> %d\n",id,u);
			pq.push(make_pair(bs[u],u));
		}
	}
	for(int i=0;i<res.size();i++) {
		if(i > 0) printf(" ");
		printf("%d",res[i]);
	}
	printf("\n");

}


Measured memory_bytes: 46964
#include<iostream>
#include<cstring>
using namespace std;
int main(){
  int n;
  cin>>n;
  int out=0;
  int score;
  string a;
  bool rui[3]={0};
  for(int i=0;i<n;i++){
    out=0; score=0;
    for(int j=0;j<3;j++){
      rui[j]=false;
    }
    while(out<3){
      cin>>a;
      if(a=="OUT")out++;
      if(a=="HIT"){
	if(rui[2]){rui[2]=false;score++;}
	if(rui[1]){rui[1]=false;rui[2]=true;}
	if(rui[0]){rui[0]=false;rui[1]=true;}
	rui[0]=true;
      }
      if(a=="HOMERUN"){
	score++;
	for(int j=0;j<3;j++){
	  if(rui[j]){rui[j]=false;score++;}
	}
      }
    }
    cout<<score<<endl;
  }
}

Measured memory_bytes: 1208
#include<iostream>
#include<vector>
#include<list>
#include<algorithm> // sort,reverse,min,lower_bound
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

template<typename T>
void print_item(T x) {cout << x+1;}
// vector 型
template<typename T>
void print(list<T>& vec,string str=""){
  if(str!="") cout << str << ":";
  for(T x: vec) {print_item(x); cout << " ";}
  cout << endl;
}
// vector 型
template<typename T>
void print(vector<T>& vec,string str=""){
  if(str!="") cout << str << ":";
  for(T x: vec) {print_item(x); cout << " ";}
  cout << endl;
}
// 二重vector 型
template<typename T>
void print(vector<vector<T>>& vec,string str=""){
  if(str!="") cout << str << ":\n";
  int n=vec.size();
  rep(i,n){
    print(vec.at(i),(string){(char)(i%10+'0')});
  }
}

void dfs(int c,list<int>& path,const vector<vector<int>>& adj,int a=0){
  const static int n=adj.size();
  static vector<int> seen(n,0);
  seen.at(a)=1;
  if(c==0) path.push_front(a);
  for(int v:adj.at(a)){
    if(seen.at(v))continue;
    if(c==1) path.push_back(v);
    dfs(c,path,adj,v);
    break;
  }
}


int main(){
  if(df) printf("*debug mode*\n");
  int n,m; cin >>n >>m;
  vector<vector<int>> adj(n);
  rep(i,m){
    int a,b; cin >>a >>b; a--; b--;
    adj.at(a).push_back(b);
    adj.at(b).push_back(a);
  }
  if(df){
    for(auto& x:adj) sort(x.begin(),x.end());
    print(adj,"graph");
  }
  list<int> path;
  dfs(0,path,adj);
  dfs(1,path,adj);
  printf("%d\n",path.size());
  print(path);
}

/// confirm df==0 ///


Measured memory_bytes: 9856
a, b, x = map(int, input().split())

# 0以上b以下で、xで割り切れる数の個数
temp1 = b // x + 1

# 0以上a-1以下で、xで割り切れる数の個数
# a==0の時だけ例外処理
if a == 0:
    temp2 = 0
else:
    temp2 = (a - 1) // x + 1

print(temp1 - temp2)


Measured memory_bytes: 9088
program main
    implicit none
    integer(4):: a,b,c
    integer(4):: x,y
    
    read*, a,b,c,x,y

    print*, min(x,y) * min(a+b, 2*c) + min(max((x-y)*a,(y-x)*b), abs(x-y)*2*c)

end program main

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define PI 3.14159265
using namespace std;
void solve(){
	int n;
	cin>>n;
	int a[n][3];
	for(int i=0; i<n; ++i){
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	int dp[n][3] = {0};
	dp[0][0] = a[0][0], dp[0][1] = a[0][1], dp[0][2] = a[0][2];
	for(int i=1; i<n; ++i){
		for(int j=0; j<3; ++j){
			
			if(j==0){
				dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i][0];
			}else if(j==1){
				dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + a[i][1];
			}else{
				dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + a[i][2];
			}
			
		}
	}
	int ans = max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
	cout<<ans<<"\n";
	
	
}
int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 2560
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int n,i;cin>>n;
	vector<llint>a(n);
	vector<llint>b(n);
	for(i=0;i<n;i++){cin>>a[i]>>b[i];}
	SO(a);SO(b);
	if(n%2==0){cout<<b[n/2-1]+b[n/2]-a[n/2-1]-a[n/2]+1<<endl;}
	else{cout<<b[n/2]-a[n/2]+1<<endl;}
	return 0;
}


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

int main()
{
    int n,k;
    int a[n];
    scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
    int p[k+1];
    for(int i=0;i<k+1;i++)p[i]=-1;
    int t=0;
    for(int i=0;i<k+1&&t<1;i++){
        for(int j=0;j<n&&t<1;j++){
            if(i+a[j]<=k)if(p[i+a[j]]!=1)p[i+a[j]]=-1*p[i];
            if(p[k]==1)t++;
        }
    }
    if(p[k]==1)cout<<"First"<<endl;
    else cout<<"Second"<<endl;
	return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;

class DP {
    static void Main(string[] args) {
        var st = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = st[0];
        int W = st[1];
        var w = new int[N];
        var v = new int[N];
        for (int i = 0; i < N; i++) {
            var x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            w[i] = x[0];
            v[i] = x[1];
        }

        //少し大きめに配列を確保
        var dp = new long[N + 2, W + 2];

        for (int i = 0; i < N; i++) {
            dp[i, 0] = 0;
        }

        for (int j = 0; j <= W; j++) {
            if (j >= w[0]) {
                dp[0, j] = v[0];
            } else {
                dp[0, j] = 0;
            }
        }

        for (int i = 0; i < N - 1; i++) {
            for (int j = 0; j <= W; j++) {
                long kari = dp[i, j];
                if (j - w[i + 1] >= 0) {
                    kari = Math.Max(kari, dp[i, j - w[i + 1]] + v[i + 1]);
                }
                dp[i + 1, j] = kari;
            }
        }

        Console.WriteLine(dp[N - 1, W]);
    }
}

Measured memory_bytes: 90592
#include <stdio.h>

int main(){
  int H,W;
  scanf("%d%d",&H,&W);
  int a[H+1][W+1];
  int i,j;
  for(i=1;i<=H;i++){
    for(j=1;j<=W;j++){
      scanf("%d", &a[i][j]);
      a[i][j]=a[i][j]%2;
    }
  }
  int ans[H*W][4];
  int k=0;
 
  for(i=1;i<=H;i++){
    if(i%2==1){
      for(j=1;j<=W;j++){
	if(a[i][j]==1){
	  if(j==W && i!=H){
	    a[i+1][W]=(a[i+1][W]+1)%2;
	    ans[k][0]=i;ans[k][1]=W;ans[k][2]=i+1;ans[k][3]=W;
	    k=k+1;
	  }
	  if(j!=W){
	    a[i][j+1]=(a[i][j+1]+1)%2;
	    ans[k][0]=i;ans[k][1]=j;ans[k][2]=i;ans[k][3]=j+1;
	    k=k+1;
	  }
	}
      }
    }
    if(i%2==0){
      for(j=W;1<=j;j--){
        if(a[i][j]==1){
          if(j==1 && i!=H){
            a[i+1][1]=(a[i+1][1]+1)%2;
            ans[k][0]=i;ans[k][1]=1;ans[k][2]=i+1;ans[k][3]=1;
            k=k+1;
          }
	  if(j!=1){
	    a[i][j-1]=(a[i][j-1]+1)%2;
	    ans[k][0]=i;ans[k][1]=j;ans[k][2]=i;ans[k][3]=j-1;
            k=k+1;
          }
        }
      }
    }
  }

  printf("%d\n",k);
  for(i=0;i<k;i++){
    printf("%d %d %d %d\n",ans[i][0], ans[i][1],ans[i][2],ans[i][3]);
  }
  return 0;
}

      
  
  

  


Measured memory_bytes: 6656
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();
    String blank = sc.nextLine();
    char[][] array = new char[h][w];
    Set<Integer> h_black_idx = new TreeSet<>();
    Set<Integer> w_black_idx = new TreeSet<>();

    for(int i = 0; i < h; i++){
      String s = sc.nextLine();
      array[i] = s.toCharArray();
    }

    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
        if(array[i][j] == '#'){
          h_black_idx.add(i);
          w_black_idx.add(j);
        }
      }
    }

    for(Integer i : h_black_idx){
      for(Integer j : w_black_idx){
        System.out.print(array[i][j]);
      }
      System.out.println("");
    }

  }
}


Measured memory_bytes: 25040
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}

//int ()



int main()
{
  int a ,b, c, d, e, X, Y;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
  int  A[200003]={};
//  long long  A[100003]={};
//  long long  B[100003]={};
  int  C[100003][11]={};

  int  flg=0;

//  long long  a, b, c, d, X, Y;
  char s[101][101]={};
  char t[101]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  long long ans=1;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
  scanf("%d%d", &a, &b);
  num=a;
  while(num>0){
    num=num-(b*2+1);
    cnt++;
//    printf("%d\n", num);
  }
  printf("%d\n", cnt);
  
  

  

    
//    printf("%s %d %d\n", s[i],C[i][0],C[i][1]);
   // printf("%d\n", C[i][1]);
/*  for(i=0;i<addr;i++){
//  scanf("%lld%lld", &B[0][i],&B[1][i]);
//    ans=ans+A[i];
    printf("%lld ", A[i]);
  }
*/
//    printf("%d ", cnt);
   

return 0;
}


Measured memory_bytes: 128
program test;
{$mode objfpc}{$H+}{$R+}{$S+}
Uses sysutils,math;
var
	a,b,c,d		:int64;
    ans         :int64;
begin
    readln(a,b,c,d);
    ans:=max(max(a*c,a*d),max(b*c,b*d));
    writeln(stdout,ans);
end.

Measured memory_bytes: 1392
#include <stdio.h>
const int N = 105;

int main()
{
	int n, a[N] = {0};
	
	scanf("%d", &n);
	
	for(int i=0;i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	
	for(int i = n-1;i >= 0; i--)
	{
		if(i)
		{
			printf("%d ", a[i]);
		}
		else
		{
			printf("%d\n", a[i]);
		}
		
	}
	
	
	
	return 0;
}


Measured memory_bytes: 2672
k, x = map(int, input().split())
mx = 1000000
ans = ''
ma = 0
mi = 0

mi = (-1) * (k - 1)
ma = k
    
for a in range(mi, ma):
  if a == ma:
    ans += str(x + a)
  else:
    ans += str(x + a) + ' '
  
if k == 1:
  ans = str(x)
  
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {

  int a, b, c, x, y, ans = 0;
  cin >> a >> b >> c >> x >> y;
  if(2 * c < a + b){
    ans += (2 * c) * min(x, y);
    if(x > y){
      if(2 * c < a){
        ans += (2 * c) * (x - y);
      }else{
        //cerr << ans << '\n';
        ans += a * (x - y);
      }
      //cerr << "NO";
      cout << ans;
    }else if(y > x){
      if(2 * c < b){
        ans += (2 * c) * (y - x);
      }else{
        ans += b * (y - x);
      }
      //cerr << "No";
      cout << ans;
    }else{
      cout << ans;
    }

  }else{
    cout << x * a + y * b;
  }
  return 0;
}


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

int main() {
    using namespace std;
    unsigned long K;
    cin >> K;
    long X, Y, x{1}, y{1};
    cin >> X >> Y;
    if(~K & (X ^ Y) & 1)return 0 & puts("-1");
    X = X + Y;
    Y = X - 2 * Y;
    if(X < 0)X *= x = -1;
    if(Y < 0)Y *= y = -1;
    vector<pair<long, long>> ans;
    if(X < K && Y < K){
        if(X & 1){
            ans.emplace_back(X - K + 1, K);
            ans.emplace_back(X - K, 0);
        }else ans.emplace_back(X - K, K);
        ans.emplace_back(X, Y);
    }else{
        unsigned long time = (max(X, Y) - 1) / K + 1;
        if(K & (time ^ X) & 1)++time;
        unsigned long remX{time * K - X}, remY{time * K - Y}, a{0}, b{0}, t, k{0};
        for(unsigned long i = 0; i < time; ++i){
            remX -= t = min(remX, 2 * K);
            if(!t)remY -= k = min(remY, 2 * K);
            ans.emplace_back(a += K - t, b += K - k);
        }
    }
    cout << ans.size() << endl;
    for(const auto& i : ans)cout << (x * i.first + y * i.second) / 2 << " " << (x * i.first - y * i.second) / 2 << endl;
    return 0;
}

Measured memory_bytes: 5484
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>

typedef long long ll;
using namespace std;

int main()
{
    string s;
	cin >> s;
	int puni = 0, index = -1, n = s.size();
	for (int i = 2; i <= n - 2; i++)
	{
		if (s[i] == 'C')
		{
			puni++;
			index = i;
		}
	}
	bool f = true;
	for (int i = 1; i < n; i++)
	{
		if (i == index)
		{
			continue;
		}
		if (!('a' <= s[i] && s[i] <= 'z'))
		{
			f = false;
			break;
		}
	}
	cout << ((s[0] == 'A' && puni == 1 && f) ? "AC" : "WA") << endl;
    

    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		for(int i = 0; i < n; i++){
		    h[i] = sc.nextInt();
		}
		
		// 計算
		int result = 0;
		int[] dp = new int[n];
		Arrays.fill(dp, 1000000000);
		dp[0] = 0;
		for(int i = 0; i < n; i++){
		    for(int j = 1; j <= min(k, n-i-1); j++){
		        dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
		    }
		}
		result = dp[n-1];
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 50244
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
    int n,k; cin >> n >> k;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(h[i]>=k)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <deque>
#include <math.h>
#include <set>
#include <iomanip>
#include <time.h>
#include <list>
#include <stdio.h>
#include <queue>
#include <map>
#include <algorithm>
#include <assert.h>
#include <memory.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define sz(s) ( (int)s.size() )
#define all(s) s.begin(), s.end()
#define int long long

using namespace std;

int n, a, ans = 1e18;

inline bool check(int m, int i)
{
    int u = 1;
    for (int j = 1; j <= i; j++)
    {
        u *= m;
        if (u >= n)
            return true;
    }
    return false;
}

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

    ans = n;

    for (int i = 1; i <= 40; i++)
    {
        int l = 0, r = 1e6 + 1;

        while (r - l > 1)
        {
            int md = (l + r) >> 1;
            if ( check(md, i + 1) )
                r = md;
            else
                l = md;
        }
        int cnt = 0;
        int u = 1;

        for (int j = 1; j <= i + 1; j++)
        {
            int pw = 1;

            for (int l = j + 1; l <= i + 1; l++)
                pw *= r;

            if (pw * u * (r - 1) >= n)
                u *= (r - 1),
                cnt += (r - 1);
            else
                u *= r,
                cnt += r;
        }
        ans = min( ans, i * a + cnt );
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
function main()
	n = parseInt(readline())
	t,a = map(parseInt, split(readline()))
	h = map(parseInt, split(readline()))
	min = 1000
	num = 0
	l = Array{Float64}(n)
	for i in 1:n
		l[i] = abs(a-t+0.006*h[i])
		if l[i] <= min
			min = l[i]
			num = i
		end
	end
	print(num)
end
main()

Measured memory_bytes: 110336
//use proconio::input;
use std::cmp::max;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};
    ($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};
    ($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};
    ($iter:expr, usize1) => {read_value!($iter, usize) - 1};
    ($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};
}


fn main() {
    input! {
        n: usize,
        m: usize,
        xy: [(usize, usize); m],
    }

    let mut g = vec![Vec::new(); n];
    for (x, y) in xy {
        g[x - 1].push(y - 1);
    }

    let mut dp = vec![None; n];

    let mut r = 0;
    for x in 0..n {
        r = max(r, rec(&g, &mut dp, x));
    }
    println!("{}", r);
}

fn rec(g: &Vec<Vec<usize>>, dp: &mut Vec<Option<usize>>, x: usize) -> usize {
    if let Some(dpx) = dp[x] { return dpx };

    let mut r = 0;
    for nx in &(*g)[x] {
        r = max(r, rec(g, dp, *nx) + 1);
    }
    (*dp)[x] = Some(r);
    r
}

Measured memory_bytes: 13400
import numpy as np
from collections import deque
H, W = map(int, input().split())
S = [input() for i in range(H)]

L = [[-1] * W for i in range(H)]
L[0][0] = 0
Open = deque([np.array([0,0])])
D = np.array([[0,1], [1,0], [-1,0], [0,-1]])
white = 0
for s in S:
    for s2 in s:
        if s2 == ".":
            white += 1
while True:
    if len(Open) == 0:
        print(-1)
        exit()
    n = Open.popleft()
    for d in D:
        nNew = n+d
        if not(0 <= nNew[0] < H and 0 <= nNew[1] < W):
            continue
        if S[nNew[0]][nNew[1]] == "#":
            continue
        if L[nNew[0]][nNew[1]] == -1:
            L[nNew[0]][nNew[1]] = L[n[0]][n[1]] + 1
            Open.append(nNew)
        if (nNew == np.array([H-1,W-1])).all():
            print(white - L[H-1][W-1] - 1)
            exit()

Measured memory_bytes: 14492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
cout<<fixed<<setprecision(10);
int a,b,c,d,e,k;
  cin >>a>>b>>c>>d>>e>>k;
  if (e-a>k) cout << ":("<<endl;
  else cout << "Yay!" <<endl;

	
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>

using namespace std;

int main()
{
	int a, b;
	scanf("%d %d",&a, &b);
	if(a * b ==1 || a * b == 3 || a * b == 9)
		printf("Yes\n");
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int F[45];

int fib(int n){
  int i;
  if(n == 0 || n == 1) return F[n] = 1;
  if(F[n] != 0) return F[n];
  return F[n] = fib(n-2) + fib(n-1);
}

int main(){
  int n,i,ans;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    F[i] = 0;
  ans = fib(n);

  printf("%d\n",ans);

  return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

int main()
{
  int n,k;
  int i,j;
  char name[20]={};
  int alph[26]={};
  int sum=0;

  cin>>n>>k;
  rep(i,n){
    cin>>name;
    alph[name[0]-'A']++;
  }
  rep(i,n/k+1){
    sort(alph,alph+26);
    int num=0;
    for(j=25;j>=0;j--){
      if(alph[j]){
	alph[j]--;
	num++;
	if(num==k){
	  sum++;
	  break;
	}
      }
    }
    if(num<k)break;
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>

typedef long long ll;

using namespace std;

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

int main() {
  int N, M;
  cin >> N >> M;
  string S, T;
  cin >> S >> T;
  if (S[0] != T[0]) {
    printf("-1\n");
    return 0;
  }
  ll L = (ll)N * (M / gcd(N, M));
  if (N > M) {
    swap(N, M);
    swap(S, T);
  }
  ll n = L / N;
  ll m = L / M;
  ll l = n * m / gcd(n, m);
  for (ll i = l; i < L; i += l) {
    if (S[i / n] != T[i / m]) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld\n", L);
}

Measured memory_bytes: 3308
#include <bits/stdc++.h>
using namespace std;
int main(){
string S;
  cin>>S;
  if(S=="SUN")
     cout<<7<<endl;
    if(S=="MON")
     cout<<6<<endl;
     if(S=="TUE")
     cout<<5<<endl;
     if(S=="WED")
     cout<<4<<endl;
     if(S=="THU")
     cout<<3<<endl;
     if(S=="FRI")
     cout<<2<<endl;
     if(S=="SAT")
     cout<<1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<map>
#include<algorithm>
#include<vector>

#define pb push_back
#define fs first
#define sc second
#define INF 500000000
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P > P2;

int n,m,l;
int num[110][110];

int main(){
  while(scanf("%d %d %d",&n,&m,&l) && (n||m||l)){
    vector<int> to[110],d[110],e[110];

    for(int i=0;i<m;i++){
      int a,b,dis,en;
      scanf("%d %d %d %d",&a,&b,&dis,&en);
      to[a].pb(b);
      d[a].pb(dis);
      e[a].pb(en);
      to[b].pb(a);
      d[b].pb(dis);
      e[b].pb(en);
    }

    for(int i=1;i<=n;i++){
      for(int j=0;j<=l;j++){
	num[i][j] = INF;
      }
    }

    num[1][l] = 0;
    priority_queue<P2 ,vector<P2> ,greater<P2> > q;
    q.push(P2(0,P(1,l)));

    while(q.size()){
      P2 p = q.top();q.pop();
      int en = p.fs, pos = p.sc.fs, mon = p.sc.sc;

      for(int i=0;i<(int)to[pos].size();i++){
	int next = to[pos][i];
	if(d[pos][i] <= mon){
	  int rem = mon - d[pos][i];
	  if(num[next][rem] > en){
	    num[next][rem] = en;
	    q.push(P2(num[next][rem],P(next,rem)));
	  }
	}
	int enemy = en + e[pos][i];
	if(num[next][mon] > enemy){
	  num[next][mon] = enemy;
	  q.push(P2(enemy,P(next,mon)));
	}
      }
    }
  
    int ans = INF;
    for(int i=0;i<=l;i++)ans = min(ans,num[n][i]);
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 1364
from collections import deque

H, W = map(int, input().split())
mp = [list(input()) for _ in range(H)]

ds = [[-1,0],[1,0],[0,-1],[0,1]]
q = deque([])

cnt = 0

for i in range(H):
  for j in range(W):
    if mp[i][j] == '#':
      q.append((i,j,0))
      cnt += 1

if cnt == H*W:
  print(0)
  exit()

while q:
  t = q.popleft()
  for d in ds:
    ny = t[0]+d[0]
    nx = t[1]+d[1]
    if 0 <= ny < H and 0<= nx < W:
      if mp[ny][nx] == '.':
        mp[ny][nx] = '#'
        q.append((ny,nx,t[2]+1))
        cnt += 1
        if cnt == H*W:
          print(t[2]+1)
          exit()


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

int main() {
	int n,sum=0,w=0;
	string x;
	cin>>n;
	vector<pair<string,int>>v(n);
	for(int i=0;i<n;i++){
		cin>>v.at(i).first;
		cin>>v.at(i).second;
	}
	cin>>x;
	for(int i=0;i<n;i++){
		if(v.at(i).first==x) w=i+1;
	}
	for(int i=w;i<n;i++){
		sum+=v.at(i).second;
	}
	cout<<sum<<endl;
	return 0;
}



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

int main(){
  	int a,b;
  	cin>>a>>b;
  	if(a==b){
    	for(int i=0;i<a;i++)
          cout<<b;
    }else if(a<b){
    	for(int i=0;i<b;i++)
          cout<<a;
   	}else{
    	for(int i=0;i<a;i++)
          cout<<b;
   	}
	return 0;
}

Measured memory_bytes: 256
/******************************************************************************

рассвет.

*******************************************************************************/
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define all(a) (a).begin(),(a).end()
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int>
#define tiii tuple <int,int,int>
#define pll pair <lli,lli>
#define vplli vector <pair <lli,lli> >
#define vvi vector <vector <int> >
#define vvlli vector <vector <lli> >
#define vvpii vector <vector <pair <int,int>> >
#define fr(i,n) for (lli i = 0; i < (n); ++i)
#define frbig(i,n) for (lli i = 0; i < (n); ++i)
#define fra(i,a,n) for (lli i = a; i < (n); ++i)
#define run(c,s) for(auto c:s)
#define read(n) int n; cin >> n;
#define readchar(n) char n; cin >> n;
#define readstr(n) string n; cin >> n;
#define readarr(a,n) fr(i,n) cin >> a[i];
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;

const lli MOD=1e9+7;
const lli MAXN=5e5+1;
const ld PI=acos(-1);

int main(){
    rapgame
    //freopen("bridges.in", "r", stdin);
    //freopen("bridges.out", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        read(n);
        lli curmax=0,ans=0;
        fr(i,n){
            readll(x);
            if(x>curmax) curmax=x;
            else ans+=curmax-x;
        }
        cout << ans;
    }
    return 0;
}

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

using namespace std;

int main() {
	int W, a, b;
	cin >> W >> a >> b;
	if (a < b) {
		if (b > a + W) cout << b - a - W << endl;
		else cout << 0 << endl;
	}
	else if (a >= b) {
		if (a > b + W) cout << a - b - W << endl;
		else cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<set>
#include<utility>
#include<vector>
#include<map>
#include<algorithm>
#include<queue>

using namespace std;



//最高のピザ
/*
int n,a,b,c;
int A[110];
int dp[110][110];

int main(){
	cin >> n >> a >> b >> c;

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

	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			dp[i][j] = max(dp[i-1][j], dp[i][j-1] + A[i]);
		}
	}

	int ans = c/a;
	for(int i=0; i<=n; i++){
		ans = max(ans, (dp[n][i]+c)/(a + b*i) );
	}

	cout << ans << endl;
	*/
	/*
	int x = 0;
	dp[0].first = 0;

	for(int j=0; j<n; j++){
		//X.push_back(temp);
		if(dp[j].first < dp[j].first + A[j]){
			dp[j+1].first = dp[j].first + A[j];
			dp[j+1].second = x;
		}
		else{
			dp[j+1] = dp[j];
		}
		//dp.push_back(-1);
	}

	int ans = 0;
	for(int i=0; i<n+1; i++){
		ans = max( (dp[i].first + c)/(dp[i].second * b + a), ans);
	}

	cout << ans << endl;
	*/
	//cout << solve(0) << endl;

//チーズ

int h,w,n;
pair<int,int> factory[10];
int cost[1000][1000];
queue< pair<int,int> > que;
string S[1000];

void Solve(pair<int,int> Now){
	//上
	if(Now.first - 1 >= 0 && S[Now.first - 1][Now.second] != 'X'){
		if(cost[Now.first][Now.second] + 1 < cost[Now.first - 1][Now.second]){
			 cost[Now.first - 1][Now.second] = cost[Now.first][Now.second] + 1;
			 que.push(make_pair(Now.first -1, Now.second));
		}
	}
	//下
	if(Now.first + 1 < h && S[Now.first + 1][Now.second] != 'X'){
		if(cost[Now.first][Now.second] + 1 < cost[Now.first + 1][Now.second]){
			 cost[Now.first + 1][Now.second] = cost[Now.first][Now.second] + 1;
			 que.push(make_pair(Now.first + 1, Now.second));
		}
	}
	//hidari
	if(Now.second - 1 >= 0 && S[Now.first][Now.second - 1] != 'X'){
		if(cost[Now.first][Now.second] + 1 < cost[Now.first][Now.second - 1]){
			 cost[Now.first][Now.second - 1] = cost[Now.first][Now.second] + 1;
			 que.push(make_pair(Now.first, Now.second - 1));
		}
	}
	//r
	if(Now.second +1 < w && S[Now.first][Now.second + 1] != 'X'){
		if(cost[Now.first][Now.second] + 1 < cost[Now.first][Now.second + 1]){
			 cost[Now.first][Now.second + 1] = cost[Now.first][Now.second] + 1;
			 que.push(make_pair(Now.first , Now.second + 1));
		}
	}
}

int main(){
	//チーズ
	
	cin >> h >> w >> n;

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

	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(S[i][j] == 'S'){
				factory[0] = make_pair(i, j);
			}
			else if(S[i][j] != 'X' && S[i][j] != '.'){
				factory[S[i][j]-'0'] = make_pair(i,j);
			}
		}
	}


	int ans = 0;
	for(int i=0; i<n; i++){
		
		for(int j=0; j<h; j++){
			for(int k=0; k<w; k++){
				cost[j][k] = 999999;
			}
		}

		cost[factory[i].first][factory[i].second] = 0;
		que.push(factory[i]);
		while(!que.empty()){
			Solve(que.front());
			que.pop();
		}
		ans += cost[factory[i+1].first][factory[i+1].second];
	}

	cout << ans << endl;


	return 0;	
}


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


int main(){
    int n, m;
    cin >> n >> m;
    int x = 1<<m;
    int ans = x * ((n-m)*100+m*1900);
    
    cout << ans << endl;
    return 0;
}


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

#define int long long

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 1e5 + 5;

vector < pp > V[N];
vector < int > U[N],Y[N];
priority_queue < pair < int , pp > > Q;

int D[N],M[N],MM[N],T[N],t,n,m,i,j,a,b,x,y,z,u,ans,zz;

int f(int x){
    return x*x % mod;
}

signed main(){
    scanf("%lld%lld%lld%lld",&n,&m,&a,&b);
    for(; m-- ;){
        scanf("%lld%lld%lld",&x,&y,&z);
        V[x].pb(mp(y,z));
        V[y].pb(mp(x,z));
    }
    
    Q.push(mp(-1,mp(a,0)));
    for(; Q.size() ;){
        x = Q.top().nd.st;
        y = Q.top().nd.nd;
        u = Q.top().st;
        Q.pop();
        if(D[x] == -u || !D[x]) { U[y].pb(x); Y[x].pb(y); }
        if(D[x]) continue;
        T[++t] = x;
        D[x] = -u;
        for(i=0;i<V[x].size();i++)
            Q.push(mp(u-V[x][i].nd,mp(V[x][i].st,x)));
    }

    for(i=1;i<=n;i++) D[i]--;

    zz = D[b];
    M[b] = 1;
    for(i=t; i ; i--){
        x = T[i];
        for(j=0;j<U[x].size();j++)
            M[x] = (M[x] + M[ U[x][j] ]) % mod;
    }
    
    ans = f(M[a]);
    MM[a] = 1;
    for(i=1;i<=t;i++){
        x = T[i];
        for(j=0;j<Y[x].size();j++)
            MM[x] = (MM[x] + MM[ Y[x][j] ]) % mod;

        if(D[x]*2 == zz) ans = (ans - f(M[x]*MM[x]%mod)) % mod;
        for(j=0;j<U[x].size();j++)
            if(D[x]*2 < zz && D[ U[x][j] ]*2 > zz)
                ans = (ans - f(MM[x]*M[ U[x][j] ]%mod)) % mod;
    }
    
    cout << (ans + mod) % mod;
    return 0;
}

Measured memory_bytes: 29168
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const ll INF = 1e18;


typedef pair<ll, int> P;

const int MAX_V = 100010;

struct edge{int to; ll cost;};

//V := number of nodes
//G := adj
int V;
vector<edge> G[MAX_V];
ll d[MAX_V];
void dijkstra(int s){
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d+V, INF);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top(); que.pop();
		ll v = p.second;
		if (d[v] < p.first) continue;
		rep((int)G[v].size(), i) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}


void solve(void){
	int N;
	cin >> N;
	V = N;
	rep(N-1, i) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		G[a].push_back(edge{b, c});
		G[b].push_back(edge{a, c});
	}
	int Q, K;
	cin >> Q >> K;
	K--;
	dijkstra(K);
	rep(Q, i) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		cout << d[x] + d[y] << endl;
	}
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 11120
#include<bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set<int>        si;
typedef set<ii>         sii;

#define all(x) x.begin(), x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define pb push_back
#define x first
#define y second
#define endl "\n"
#define MOD int(1e9+7)
#define N 200123
int n;
string t;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> t;
    if(t[0]=='7'||t[1]=='7'||t[2]=='7')cout<<"Yes"<<endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3592
N, W = map(int, input().split())
X = [0] + [-1] * W

for i in range(N):
    w, v = map(int, input().split())
    
    for j in range(W - w, -1, -1):
        if X[j] >= 0:
            X[j+w] = max(X[j+w], X[j]+v)

print(max(X))

Measured memory_bytes: 41824
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    if N % sum([int(i) for i in str(N)]) == 0:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9952
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
 
typedef long long ll;
 
using namespace std; 
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 long long INF = 1LL << 60;
 
#define REP(inc, bgn, end) for (int inc = bgn; inc < end; inc++)

int main() {
    int n;
    cin >> n;
    vector<ll> h(n);
    REP(i, 0, n) cin >> h[i];

    vector<ll> dp(n+1);
    REP(i, 0, n+1) dp[i] = INF;

    dp[0] = 0;
    REP(i, 1, n) {
        chmin(dp[i], dp[i-1] + abs(h[i-1] - h[i]));
        if (i > 1) chmin(dp[i], dp[i-2] + abs(h[i-2] - h[i]));
    }
    
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
"use strict"
{
  var input = require("fs").readFileSync("/dev/stdin", "utf8");
   
  var readlines = input.split("\n");
  var n = readlines[0];
  var a = readlines[1].split(" ").map(Number);
  var ans = 0;
  for(let i = 0; i < n; i++){
    if(i % 2 === 0 && a[i] % 2 === 1){
      ans++;
    }
  }
   
  console.log(ans);
}

Measured memory_bytes: 30564
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		while (true) {
			int a0 = nextInt();
			int L = nextInt();
			if (L == 0) {
				break;
			}

			ArrayList<Integer> list = new ArrayList<Integer>();
			list.add(a0);

			loop: while (true) {
				String aString = String.valueOf(a0);
				while (aString.length() < L) {
					aString = "0" + aString;
				}

				int[] nums = new int[L];
				for (int i = 0; i < nums.length; i++) {
					nums[i] = Integer.parseInt(aString.substring(i, i + 1));
				}
				Arrays.sort(nums);
				int big = 0;
				int small = 0;
				for (int i = 0; i < L; i++) {
					big += nums[i] * Math.pow(10, i);
					small += nums[i] * Math.pow(10, L - i - 1);
				}
				int result = big - small;
				for (int i = 0; i < list.size(); i++) {
					if (list.get(i) == result) {
						System.out.println(i + " " + result + " "
								+ (list.size() - i));
						break loop;
					}
				}
				list.add(result);
				a0 = result;
			}
		}

	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

}

Measured memory_bytes: 19236
h,w,x=map(int,input().split())
c=[input() for _ in range(h)]
a=0
for i in range(2**h):
  for j in range(2**w):
    t=0
    for k in range(h):
      for l in range(w):
        if i>>k&1 and j>>l&1 and c[k][l]=='#': t+=1
    if t==x: a+=1
print(a)

Measured memory_bytes: 9100
/***
 ** "Everything before the word 'but' is horseshit."
 **     -- Jon snow
***/

/**
  *  Author: dhruv_gheewala
  *  Problem: __________
  *  Date:   02.08.2020
  *  Time:   18:01:24
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;
    
    #define fundri 108
    #define debug(...) 1729
#endif

#define int int64_t
typedef pair<int, int> pii;
typedef vector<int> vi;

const bool testcases = false;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(), s.end()

// if vector isn't soted then it will remove consecutive same elements
#define make_unique(vec) vec.erase(unique(all(vec)), vec.end())
#define test int TC = 1;if(testcases)cin >> TC;for(int tc = 1 ; tc <= TC ; tc++)solve(), fundri
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

int seed; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = INT_MAX) {return uniform_int_distribution<int>(l, r)(rng);}

inline bool in_range(int a, int l, int r) {return (a >= l && a <= r);}
template<typename H, typename ...T>void inp(H &head) {cin >> head;}
template<typename H, typename ...T>void inp(H &head, T &...tail) {cin >> head;inp(tail...);}
template<typename T>bool isPrime(T n) {for(T i = 2; i * i <= n; i++)if(n % i == 0)return false; return n >= 2;}
template<typename T>inline istream &operator >>(istream &in, vector<T> &a) {for(T &x : a)in >> x; return in;}
template<typename T, typename U>inline istream &operator >>(istream &in, pair<T, U> &a) {in >> a.ff >> a.ss; return in;}

void solve();
void fast_io();

int32_t main(int32_t argc, char **argv)
{
    fast_io();
    test;
    return 0;
}

void solve()
{
    int n;
    cin >> n;
    vector<char> a(n);
    cin >> a;

    int b[2] = {0, 0};
    for(int i = 0 ; i < n ; i++) {
        if(a[i] == 'R')
            b[0]++;
        else
            b[1]++;
    }

    int ans = min(b[0], b[1]);
    int cnt = 0;
    for(int i = 0 ; i < b[0] ; i++)
        cnt += (a[i] == 'W');
    debug(ans);
    ans = min(ans, cnt);
    debug(ans);
    cnt = 0;
    for(int i = b[0] ; i < n ; i++)
        cnt += (a[i] == 'R');
    ans = min(ans, cnt);
    debug(ans);

    cout << ans << endl;
}

void fast_io()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

#ifdef DHRUV_GHEEWALA
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif
}

Measured memory_bytes: 3652