akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << (a - c) * (b - d) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
//int n,m,i,j,k,sum,total,;
//long long int ;
//float ;
//double ;
char s[101];
int i,j;
int main(void){
    scanf("%s",s);
    for (j = 0; j < strlen(s); j++)
    {
        printf("x");
    }
    printf("\n");
    
    return 0;
}

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

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(false);cin.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define error_old(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl
#ifdef DEBUG
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {it++;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); }
#else
#define error(args...)
#endif

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

const int MAXV = 1e5 + 5;

void solve(){
    int n, W;
    cin >> n >> W;

    vi w(n), v(n);
    rep(i, n){
        cin >> w[i] >> v[i];
    }

    vi dp(MAXV, MOD);
    dp[0] = 0;
    rep(i, n){
        vi sdp(MAXV, MOD);     
        rep(val, MAXV){
            if(dp[val] != MOD && dp[val] + w[i] <= W){
                sdp[val + v[i]] = min(dp[val + v[i]], dp[val] + w[i]);
                error(val, dp[val], v[i], w[i]); 
            }
        }
        rep(val, MAXV){
            dp[val] = min(dp[val], sdp[val]);
        }
    }
    int ans = -1;
    rep(i, MAXV){
        if(dp[i] != MOD){
            ans = i;
        }
    }
    cout << ans << endl;

}

signed main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    solve();

    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=2005;
int n,mx,ans=1<<30,i,j,k,head[N],adj[N*2],nxt[N*2],f[N],size[N],sum[N];
char s[N];
void dfs(int x,int dad)
{
	sum[x]=0;
	size[x]=(s[x]=='1');
	int mx=0,w=0;
	for(int y=head[x];y;y=nxt[y])
		if(adj[y]!=dad)
		{
			dfs(adj[y],x);
			size[x]+=size[adj[y]];
			sum[x]+=sum[adj[y]]+size[adj[y]];
			if(f[adj[y]]+size[adj[y]]>mx)
			{
				mx=f[adj[y]]+size[adj[y]];
				w=sum[adj[y]]+size[adj[y]];
			}
		}
	f[x]=max(0,mx-(sum[x]-w));
	//if(i==1)
		//printf("%d %d\n",x,f[x]);
}
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	for(i=1;i<n;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
	}
	for(i=1;i<=n;++i)
	{
		dfs(i,-1);
		if(f[i]==0&&sum[i]%2==0)
			ans=min(ans,sum[i]);
	}
	if(ans<=100000000)
		printf("%d",ans/2);
	else
		printf("-1");
	return 0;
}


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

int main(){
  ll A,B,C,K;
  cin >> A >> B >> C >> K;
  if (K <= A)
    cout  << K;
  else if ( K > A && K <= A+B )
    cout  << A;
  else 
    cout << A*2+B-K;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		sc.close();

		for(int i = 0; i < S.length(); i++) {
			if(S.equals(T)) {
				System.out.println("Yes");
				return;
			}
			String tmp = S.substring(0, S.length() - 1);
			S = S.charAt(S.length() - 1) + tmp;
		}
		System.out.println("No");
	}

}


Measured memory_bytes: 23764
N, W = map(int, input().split())
v = [0]*(N+1)
w = [0]*(N+1)
for i in range(1, N+1):
    v[i], w[i] = map(int, input().split())
dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(1, N+1):
    for j in range(1, W+1):
        if w[i] <= j:
            dp[i][j] = max(dp[i-1][j-w[i]]+v[i], dp[i-1][j])
        else:
            dp[i][j] = dp[i-1][j]
# [print(dp[j]) for j in range(N+1)]
print(dp[N][W])

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

int n;
int s;
int count;

int rec(int state, int num, int sum) {
  int count;
  count = 0;
  if(num > n) {
    if(sum == s) {
      return 1;
    } else {
      return 0;
    }
  }
  for(int i = state; i <= 9; i++) {
    count += rec(i+1, num+1, sum+i);
  }
  return count;
}

int main() {
  while(1) {
    cin >> n >> s;
    if(n == 0 && s == 0) break;
    cout << rec(0, 1, 0) << endl;
  }
}

Measured memory_bytes: 0
/* 
 * File:   main.cpp
 * Author: Sebastian Hall
 * Created on August 20, 2020, 5:06 PM
 * Purpose: https://atcoder.jp/contests/dp/tasks/dp_c
 */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double triple;

int main() {
    ios::sync_with_stdio(false);
    //Declare variables
    int n = 0;
    vector<int> prev(3);
    
    cin>>n;
    
    for(int i = 0; i < n; ++i) {
        vector<int> happy(3), dp(3, 0);
        
        //Three potential activities of today
        cin>>happy[0]>>happy[1]>>happy[2];
        
        //For every combination of current days and previous days
        for(int curDay = 0; curDay < 3; ++curDay) {
            for(int prevDay = 0; prevDay < 3; ++prevDay) {
                if(curDay != prevDay) {//If not two activities same day in a row
                    dp[curDay] = max(dp[curDay], prev[prevDay] + happy[curDay]);
                }
            }
        }
        //Assign total of current days to previous
        prev = dp;
    }

    //Output answer
    cout<<(*max_element(prev.begin(), prev.end()))<<endl;
    
    //A Sebastian Production
    return 0;
}

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

using namespace std;
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x) << ' '; cerr << endl;

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	double p[n+1];
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
	}
	
	vector<vector<double>> dp(n+1, vector<double>(n+1)); // dp[i][j] = probability having j heads from i coins
	
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (j != 0)
				dp[i][j] = dp[i-1][j-1]*p[i];
			dp[i][j] += dp[i-1][j]*(1-p[i]);
		}
	}
	
	double ans = 0;
	for (int i = (n+1)/2; i <= n; i++)
		ans += dp[n][i];
	
	cout << setprecision(10) << ans << endl;
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
int main () {
    int A[3], K;
    cin >> A[0] >> A[1] >> A[2] >> K;
    sort(A, A+3);
    for (int i = 0; i < K; i++) {
        A[2] += A[2];
    }
    cout << A[0]+A[1]+A[2] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,m,i,j,sum=0,ans;
	int t[105],p[105],x[105];
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		{
			scanf("%d",&t[i]);
			sum=sum+t[i];
		}
	scanf("%d",&m);
	for(i=1;i<=m;i++)
		scanf("%d%d",&p[i],&x[i]);
	for(i=1;i<=m;i++)
	{
		ans=sum-t[p[i]]+x[i];
		printf("%d\n",ans);
	}
	//printf("No\n"); 		 
	return 0;
}

Measured memory_bytes: 128
while True:
    n = int(input())
    if n ==0:
        break

    k = list(map(int, input().split()))
    if n == 1:
        print(2)
    elif k.count(0) + k.count(1) == n:
        print("NA")
    else:
        print(n - k.count(0) + 1)



Measured memory_bytes: 7204
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
int N,M,K,A,B,C,D;

class disjointset{

  public:

    vector<int>rank,parent,sz;

    disjointset(int size){
        rank=parent=sz=vector<int>(size+1);
        for(int i=0;i<=size;i++)rank[i]=0,parent[i]=i,sz[i]=1;
    }

    int root(int n){return (parent[n]==n?n:parent[n]=root(parent[n]));}

    void unite(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return;
        (rank[x]>rank[y])?parent[y]=x,sz[x]+=sz[y]:parent[x]=y,sz[y]+=sz[x];
        rank[root(x)]+=(rank[x]==rank[y]);
    }

    bool same(int x,int y){return root(x)==root(y);}

    int size(int n){return sz[root(n)];}
};

int main(){
    cin>>N>>M>>K;
    disjointset ds(N);
    int friends[N];memset(friends,0,sizeof(friends));
    for(int i=0;i<M;i++){
        cin>>A>>B;
        friends[A-1]++;
        friends[B-1]++;
        ds.unite(A-1,B-1);
    }
    int block[N];memset(block,0,sizeof(block));
    for(int i=0;i<K;i++){
        cin>>C>>D;
        if(ds.same(C-1,D-1))block[C-1]++,block[D-1]++;
    }
    for(int i=0;i<N;i++)cout<<ds.size(i)-friends[i]-block[i]-1<<" ";
    return 0;
}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007
typedef pair<li, li> PI;

li cnt[100100];

int main(void)
{
	li n;
	cin >> n;
	rep(i, n) {
		li a;
		cin >> a;
		cnt[a]++;
	}

	li res = 0;
	for (li i = 1; i < 99999; ++i) {
		res = max(res, cnt[i - 1] + cnt[i] + cnt[i + 1]);
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1152
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>

using namespace std;

int main(){
	int A[101], D, N, X, i, ans = 0;
	scanf("%d", &N);
	scanf("%d %d", &D,&X);
	for (i = 1; i <= N; i++){
		scanf("%d", &A[i]);
	}

	for (i = 1; i <= N; i++){
		if (D%A[i] == 0){
			ans += D / A[i];
		}
		else{
			ans = ans + D / A[i] + 1;
		}
	}
	printf("%d", X + ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        for (int i = 0; i < n; i++) b[i] = sc.nextInt();
        for (int i = 0; i < n; i++) c[i] = sc.nextInt();
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);
        long ans = 0;
        for (int i = 0; i < n; i++) {
            long aNum = binarySearchMax(a, b[i]) + 1;
            long cNum = c.length - binarySearchMin(c, b[i]);
            ans += aNum * cNum;
        }
        System.out.println(ans);
        sc.close();
    }

    public static int binarySearchMin(int[] array, int key){
        int ok = array.length;
        int ng = -1;
        while(1 < Math.abs(ok - ng)){
            int mid = (ok + ng) / 2;
            if(key < array[mid]) ok = mid;
            else ng = mid;
        }
        return ok;
    }

    public static int binarySearchMax(int[] array, int key){
        int ok = -1;
        int ng = array.length;
        while(1 < Math.abs(ok - ng)){
            int mid = (ok + ng) / 2;
            if(key > array[mid]) ok = mid;
            else ng = mid;
        }
        return ok;
    }

}


Measured memory_bytes: 94304
#include <iostream>
using namespace std;
int main(){
    int a,b,h,i=3;
    cin>>a>>b>>h;
    if(a==b&&a==h)i=i-2;
    if(a==h&&a!=b)i=i-1;
    if(a==b&&a!=h)i=i-1;
    if(b==h&&b!=a)i=i-1;
    cout<<i<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

const ll MX = 1e18;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    rep(i,n){
        if((MX+1)/ans < a[i]){
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
    }
    if(ans > MX) ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3996
use proconio::input;
use proconio::marker::Chars;
use std::collections::BTreeSet;

fn main() {
    input! {
        s: Chars,
        mut k: usize,
    }
    let mut ss = BTreeSet::new();

    for i in 0..s.len() {
        for j in i+1..=std::cmp::min(i+k, s.len()) {
            ss.insert(s[i..j].iter().collect::<String>());
        }
    }

    if let Some(ans) = ss.into_iter().skip(k-1).next() {
        println!("{}", ans);
    } else {
        unreachable!();
    }
}


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

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

        int ls[][] = new int[m][n];
        for (int i = 0; i < m; i++) {
            Arrays.fill(ls[i], 0);
            int k = in.nextInt();
            for (int j = 0; j < k; j++) {
                ls[i][j] = in.nextInt();
            }
        }

        int p[] = new int[m];
        for (int i = 0; i < m; i++) {
            p[i] = in.nextInt();
        }

        int count = 0;
        for (int comb = 0; comb <= powLong(2, n) - 1; comb++) {
            boolean all = true;
            for (int i = 0; i < m; i++) {
                int j = 0;
                int light = 0;
                while (j < n && ls[i][j] != 0) {
                    int pos = ls[i][j];
                    if (((comb >> (pos - 1)) & 0x1) == 1) {
                        light++;
                    }
                    j++;
                }

                if (light % 2 != p[i]) {
                    all = false;
                    break;
                }
            }

            if (all) {
                count++;
            }
        }

        System.out.println(count);
    }

    static final long powLong(long a, long e) {
        long r = 1;
        while (e > 0) {
            if ((e & 1) == 1) {
                r *= a;
            }
            e = e >> 1;
            a *= a;
        }

        return r;
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int op(int a, int b){
    return max(a, b);
}

int e(){
    return 0;
}

int main(void){
	int N,K,x,i,ans=0;
	segtree <int, op, e> seg(300010);
	
	cin >> N >> K;
	
	REP(i,N){
		scanf("%d", &x);
		int L = max(x - K, 0);
		int R = min(x + K, 300000);
		int tmp = seg.prod(L, R+1) + 1;
		ans = max(ans, tmp);
		seg.set(x, tmp);
	}
	
	cout << ans << endl;
	
	return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long int lli;
typedef long long ll;

int main(){
    string s; cin >> s;
    int n = s.size();

    vector<int> a(n);
    rep(i,n){
        a[i] = s[i]-'0';
    }

    int ans = inf;
    rep(i,n-2){
        int num = abs(a[i]*100+a[i+1]*10+a[i+2] - 753);
        ans = min(ans, num);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
x = int(n/1.08)
n_x = int(x*1.08)
ans_list = [int(x-1), x, int(x+1)]
for key, i in enumerate(ans_list):
  checker = int(i*1.08)
  if checker == n:
    print(i)
    break
  elif key==2:
    print(":(")

Measured memory_bytes: 3060
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, T, *t = map(int, read().split())

    ans = 0
    for i in range(N - 1):
        if t[i] + T > t[i + 1]:
            ans += t[i + 1] - t[i]
        else:
            ans += T
    ans += T

    print(ans)

    return


if __name__ == '__main__':
    main()


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

int main(){
    string s;
    long long int k;
    cin >> s >> k;

    int n = s.length();
    string s2 = s;
    long long int ans1 = 0, ans2 = 0;
    for(int i=0; i+1<n; i++){
        if(s[i] == s[i+1]){
            ans1 += 1;
            s[i+1] = '.';
        }
    }
    if(s2[n-1] == s2[0]){
        s2[0] = '.';
        ans2 += 1;
    }
    for(int i=0; i+1<n; i++){
        if(s2[i] == s2[i+1]){
            ans2 += 1;
            s2[i+1] = '.';
        }
    }
    long long int ans;
    if(s[n-1] != s[0]) ans = k * ans1;
    else if(s2[n-1] == '.') ans = (k/2) * (ans1 + ans2) + (k%2) * ans1;
    else ans = ans1 + (k-1) * ans2;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define N 1000001
#define M 1001
using namespace std;
typedef pair<int,int>P;
typedef pair<P,P> PP;
int h,w,n;
string mp[M],str;

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

int getCost(int x,int dir,int ndir){
  while(x<n&&dir!=ndir){
    if(str[x] == 'L') dir = (dir+3)%4;
    else dir = (dir+1)%4;
    x++;
  }
  if(dir!=ndir) return -1;
  return x;
}

bool dijkstra(int sy,int sx){
  for(int i=0;i<4;i++)
    for(int j=0;j<h;j++)
      for(int k=0;k<w;k++) D[i][j][k] = 1e9;
  
  priority_queue<PP,vector<PP>,greater<PP> > Q;
  Q.push(PP(P(0,0),P(sy,sx)));
  D[0][sy][sx] = 0;

  while(!Q.empty()){
    PP t = Q.top();Q.pop();
    int cost = t.first.first;
    int dir = t.first.second;
    int y = t.second.first;
    int x = t.second.second;
    
    if(mp[y][x] =='G') return 1;    
    if(D[dir][y][x]<cost) continue;

    
    for(int i=0;i<4;i++){
      int ncost = getCost(cost,dir,i);
      if(ncost == -1 || D[i][y][x]<=ncost)continue;
      Q.push(PP(P(ncost,i),P(y,x)));
      D[i][y][x] = ncost;
    }

    int ny = y+dy[dir]; 
    int nx = x+dx[dir];
    if(nx<0||ny<0||nx>=w||ny>=h||mp[ny][nx]=='#'||D[dir][ny][nx]<=cost)continue;
    D[dir][ny][nx] = cost;
    Q.push(PP(P(cost,dir),P(ny,nx)));
    
  }  
  
  return 0;
}

int main(){

  while(1){
  cin>>h>>w>>n;
  if(!h&&!w&&!n)break;
  cin>>str;
  for(int i=0;i<h;i++)cin>>mp[i];

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(mp[i][j] == 'S') cout<<(dijkstra(i,j)?"Yes":"No")<<endl;

  }
  return 0;
}

Measured memory_bytes: 21628
fun main(args:Array<String>) {
    val s = readLine()!!
    var curA = '0'
    var curB = '1'
    var cntA = 0
    var cntB = 0
    for(i in s) {
        if(i != curA) {
            cntA++
        }
        if(i != curB) {
            cntB++
        }
        curA = flip(curA)
        curB = flip(curB)
    }
    val ans = Math.min(cntA,cntB)
    println(ans)
}

fun flip(cur:Char):Char {
    if(cur == '0') {
        return '1'
    } else {
        return '0'
    }
}

Measured memory_bytes: 34168
a,b,c,x,y = map(int, input().split())

if (a+b) > c*2:
  tmp = min(x,y)
  if x > y:
    print(min(c*2*tmp + a*(x-y), c*2*x))
  else:
    print(min(c*2*tmp + b*(y-x), c*2*y))
else:
  print(a*x + b* y)
  

Measured memory_bytes: 3060
using System;
class Program{
	static void Main(){
		long n=long.Parse(Console.ReadLine());
		int a=(int)Math.Sqrt(n);
		long ans=long.MaxValue;
		for(int i=a;i>0;i--){
			if(n%i==0){
				ans=(n/i).ToString().Length;
				break;
			}
		}
		Console.WriteLine("{0}",ans);
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define rgi register int
#define ll long long
#define int ll
using namespace std;
 
int a,b,c,d;
inline ll solve()
{
	--a,--b,--c,--d;
	int res=abs(a-c)+abs(b-d),t=1LL;
	for(rgi i=1;i<=33;++i) t*=3LL;
	for(rgi i=33;i>=0;--i)
	{
		for(rgi j=0;j<2;++j)
		{
			if(a/t==c/t&&(a/t)%3LL==1LL&&abs(b/t-d/t)!=1&&abs(b-d)>=t)
			{
				int mn=min(a,c),mx=max(a,c);
				return res+min(mn-mn/t*t+1LL,(mx/t+1LL)*t-mx)*2LL;
			}
			swap(a,b),swap(c,d);
		}
		t/=3LL;
	}
	return res;
}
 
signed main()
{
	rgi q;
	cin>>q;
	while(q--)
	{
		cin>>a>>b>>c>>d;
		cout<<solve()<<endl;
	}
	return 0;
}
// ----------------------------
// by imzzy

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

int main()
{
	int N;
	scanf("%d", &N);
	std::vector<std::pair<int, int>> A(N);
	for (int i{}; i < N; i++)
	{
		scanf("%d", &A[i].first);
		A[i].second = i;
	}
	std::sort(A.rbegin(), A.rend());

	for (int i{}; i < N; i++)
	{
		if (A.front().second != i) printf("%d\n", A.front().first);
		else printf("%d\n", A[1].first);
	}

	return 0;
}

Measured memory_bytes: 3200
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

class DPowerfulDiscountTickets {
public:
    void solve(std::istream &cin, std::ostream &cout) {
        int n, m;
        cin >> n >> m;
        vector<long long int> a_vec(n);
        for (int i = 0; i < n; ++i) {
            cin >> a_vec[i];
        }
        priority_queue<long long int, vector<long long int>> que;
        for (const auto &item : a_vec) {
            que.push(item);
        }
        while (m != 0) {
            long long int tmp = que.top();
            que.pop();
            tmp /= 2;
            que.push(tmp);
            m -= 1;
        }
        long long int ans = 0;
        while (!que.empty()) {
            ans += que.top();
            que.pop();
        }
        cout << ans << endl;
    }
};


int main() {
    DPowerfulDiscountTickets solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
#define Imax 1e9+5
#define LLmax 1e18
#define Imin -1e9-5
#define LLmin -1e18
string day [] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
vector <string> v;
bool sortByFirst(const pair<int,int>&a,const pair<int,int>&b){
    return a.first>b.first;
}
void dfs (string str, string t = "", int cnt = 0) {
    if (cnt == 2) {
        v.push_back (t);
        return;
    } else {
        for (int i = 0; i <str.size (); i ++) {
            dfs (str, t + str [i], cnt + 1);
        }
    }
}
int main () {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string str;
    while(cin>>str){
        int a=0,z=str.length()-1;
        while(str.at(a)!='A')++a;
        while(str.at(z)!='Z')--z;
        cout<<z-a+1<<endl;

    }
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<stack>
#include<queue>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
#define int long long
using namespace std;
signed main(){
    int k,n; cin>>k>>n;
    vector<int>data(n);
    for(int i=0;i<n;++i) cin>>data[i];
    int m=1000000000;
    for(int i=0;i<n-1;++i) m=min(m,k+data[i]-data[i+1]);
    m=min(m,data[n-1]-data[0]);
    cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

int D;
vector<int> c(26);
vector<vector<int>> s;

int64_t calc_score(const vector<int>& t) {
  int64_t result = 0;
  vector<int> last(26, -1);
  rep(i, D) {
    const int j = t[i];
    result += s[i][j];
    last[j] = i;
    rep(k, 26) { result -= c[k] * (i - last[k]); }
  }
  return result;
}

int main() {
  cin >> D;

  rep(i, 26) { cin >> c[i]; }

  s.resize(D, vector<int>(26));
  rep(i, D) rep(j, 26) { cin >> s[i][j]; }

  vector<vector<int>> last;
  vector<int> parent;
  vector<int> kind;

  using P = pair<int64_t, int>;
  priority_queue<P, vector<P>, greater<P>> q;

  last.push_back(vector<int>(26, -1));
  parent.push_back(-1);
  kind.push_back(-1);
  q.push(P(0, 0));

  const int width = 100;
  rep(i, D) {
    priority_queue<P, vector<P>, greater<P>> nxt;

    while (!q.empty()) {
      int64_t z;
      int idx;
      tie(z, idx) = q.top();
      q.pop();

      int64_t penalty = 0;
      rep(j, 26) { penalty += c[j] * (i - last[idx][j]); }

      rep(j, 26) {
        int nidx = last.size();
        int64_t w = z + s[i][j] - penalty + c[j] * (i - last[idx][j]);
        nxt.push(P(w, nidx));
        if (nxt.size() > width) {
          nxt.pop();
        }

        last.push_back(last[idx]);
        last[nidx][j] = i;
        parent.push_back(idx);
        kind.push_back(j);
      }
    }

    q = move(nxt);
  }

  while (q.size() > 1) {
    q.pop();
  }

  int64_t score;
  int idx;
  tie(score, idx) = q.top();
  vector<int> sln;
  while (idx != 0) {
    sln.push_back(kind[idx]);
    idx = parent[idx];
  }
  rrep(i, D) { cout << sln[i] + 1 << "\n"; }
  cerr << score << "\n";

  return 0;
}

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

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> a = new ArrayList<Integer>();
		for(int i=0;i<n;i++) {
			a.add(sc.nextInt());
		}
	//	System.out.println(a.get(0));
	//	System.out.println(a);
		Collections.sort(a);
	//	System.out.println(a);
		int alice = 0;
		int bob = 0;
		for(int i=0;i<n;i++) {
			if(i%2==0) {
				alice += a.get(n-i-1);
			}else {
				bob += a.get(n-i-1);
			}
		}
	//	System.out.println(alice);
	//	System.out.println(bob);
		System.out.println(alice-bob);
	}

}


Measured memory_bytes: 21844
function main(input) {
    var line = input.split(/\r?\n/g);
    var arr = line[0].split(" ");
    const S = arr[0], T = arr[1];
    arr = line[1].split(" ")
    var A = parseInt(arr[0]), B = parseInt(arr[1]);
    const U = line[2];
    if (S === U) {
        A--;
    } else {
        B--;
    }
    console.log(A + " " + B);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
a, b = map(int, input().split())
aS = str(a)*b
bS = str(b)*a

win = aS
for i in range(len(aS)):
  aF = aS[i]
  if (i >= len(bS)):
    win = aS
    break
  elif (int(aS[i]) > int(bS[i])):
    win = bS
    break
  elif (int(aS[i]) < int(bS[i])):
    win = aS
    break
  else:
    continue
print(win)
    

Measured memory_bytes: 61752
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll x,n;
    cin>>x>>n;
    V vec(n);
    rep(i,n)cin>>vec[i];
    sort(all(vec));
    ll res=0;
    rep(i,200){
        if(!binary_search(all(vec),x-i)){
            res=x-i;
            break;
        }
        if(!binary_search(all(vec),x+i)){
            res=x+i;
            break;
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3664
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
	int H,W,i=0,j=0,k=0;
	while(cin>>H>>W){
		if(H==0&&W==0) break;
		for(i=1;i<=H;i++){
			for(j=1;j<W;j++){
				if(i==1||i==H)cout<<"#";
				else {
					cout<<"#";
					for(k=0;k<W-2;k++){
						cout<<".";
						}
					break;
					}
			}
			cout<<"#"<<endl;
		}
	cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <algorithm>
    #include <bits/stdc++.h>
    #include <cctype>
    #include <cmath>
    #include <cstdio>
    #include <iomanip>
    #include <iostream>
    #include <list>

    #include <stack>
    #include <string>
    #include <vector>
    #include <bits/stdc++.h>
    #define INFINI (1000 * 1000 * 1000)

    using namespace std;
    //#define s(T) scanf("%d", &T)
    #define sl(T) scanf("%lld", &T)
    #define fill(a, val) memset(a, val, sizeof(a))
    #define mp make_pair
    #define pb push_back
    #define all(x) x.begin(), x.end()
    #define DREP(x) sort(all(x)); x.erase(unique(all(x)), x.end())
    #define INDEX(a, val) (lower_bound(all(a), val) - a.begin())
    #define mod ll(1e9+7)
    typedef long long ll;


    bool compare_first(pair<ll,ll >a,pair<ll,ll >b)
    {
        return a.first<b.first;
    }

     bool compare_second(pair<int,pair<int , int> > a,pair<int,pair<int , int> > b)
    {
        return a.second.first<b.second.first;
    }


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


    int main() {
      ios::sync_with_stdio(false);



string sa,sb,sc;
cin>>sa>>sb>>sc;

int posa=0,posb=0,posc=0;
int next=0;
while(posa<=sa.size()&&posb<=sb.size()&&posc<=sc.size())
{
  if(next==0)
  {

      next=(sa[posa]-'a');
       posa++;
  }
  else if(next==1)
  {

      next=(sb[posb]-'a');
      posb++;
  }
  else
  {

      next=(sc[posc]-'a');
      posc++;
  }
}


if(posa>sa.size())
    cout<<"A"<<endl;
else if(posb>sb.size())
    cout<<"B"<<endl;
else
    cout<<"C"<<endl;








return 0;
    }


/*

 }
 */


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


bool color2bool(char color){
    if(color=='.'){
        return false;
    }else{
        return true;
    }
}


std::vector<int> delete_row(std::vector<char>& grid, int column_size, int row_size){

    bool allthesame;
    std::vector<int> row_to_delete(column_size, 0);
    for(int i=0; i < column_size; i++){
        // printf("32");

        allthesame = true;
        for(int j=0; j < row_size; j++){
            if(color2bool(grid.at(i*row_size + j))){
                allthesame = false;
                break;
            }
        }
        if(allthesame){
            row_to_delete.at(i)=1;

        }
    }
    return row_to_delete;
}

std::vector<int> delete_column(std::vector<char>& grid, int column_size, int row_size){

    bool allthesame;
    std::vector<int> column_to_delete(row_size, 0);
    int dense_size = 0;
    for(int i=0; i < row_size; i++){

        allthesame = true;
        for(int j=0; j < column_size; j++){
            if(color2bool(grid.at(i + j*row_size))){
                allthesame = false;
                break;
            }
        }
        if(allthesame){
            column_to_delete.at(i) = 1;
        }
    }
    return column_to_delete;
}


int main() {
    int column_size, row_size;
    cin >> column_size >> row_size;
    std::vector<char> grid(column_size * row_size);
    string row;
    for(int i = 0; i < column_size; i++){
        cin >> row;
        for(int j=0; j < row_size; j++){
            grid.at(i*row_size + j) = row.at(j);
        }
    }
    std::vector<int> column_to_delete(row_size);
    std::vector<int> row_to_delete(column_size);

    row_to_delete = delete_row(grid, column_size, row_size);
    column_to_delete = delete_column(grid, column_size, row_size);
    for(int i=0; i < column_size; i++){
        if(row_to_delete.at(i)){
                continue;
        }else{
            for(int j=0; j < row_size; j++){
                if(column_to_delete.at(j)){
                    continue;
                }else{
                    cout << grid.at(i*row_size+j);
                }

            }
            cout << endl;
        }
    }

    return 0;
  // リンゴ・パイナップルをそれぞれ1つずつ購入するとき合計S円になるような買い方が何通りあるか
  // ここにプログラムを追記
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int a;
  int b;
  
  cin >> a >> b;
  if(-1000<=a && b<=1000)
    {
    if(a>b)
    cout << "a > b\n";
    if(a<b)
    cout << "a < b\n";
    if(a==b)
    cout << "a == b\n";
    }
} 

Measured memory_bytes: 1124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;

int dp[100010];

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

    int pow6=1,pow9=1;
    dp[0] = 0;

    rep2(i,1,100010){
        if(i == 6*pow6) pow6 *= 6;
        if(i == 9*pow9) pow9 *= 9;
        int A = dp[i-1] + 1;
        int B = dp[i-pow6] + 1;
        int C = dp[i-pow9] + 1;
        dp[i] = min(min(A,B),C);
    }

    cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <sstream>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

#define pb push_back
#define pbk pop_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define foreach(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define len(a) ((int) (a).size())

#ifdef CUTEBMAING
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

using namespace std;

typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;

const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;

int main() {
#ifdef XCODE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n; cin >> n;
    vector<int> a(2 * n);
    for (auto &i : a) {
        cin >> i;
    }
    sort(all(a));
    int ans = 0;
    for (int i = 0; i < 2 * n; i += 2) {
        ans += min(a[i], a[i + 1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
	int n,k;
    cin>>n>>k;
    vector<int> h(n);
    REP(i,n){
        cin>>h[i];
    }
    sort(ALL(h));
    ll ans=0;
    REP(i,max(n-k,0)){
        ans+=h[i];
    }
    OUT(ans);
	return 0;
}

Measured memory_bytes: 1024
import sys
for e in sys.stdin:
 a=b=0;n=int(e)
 if n:
  for i in[0]*n:
   s,t=map(int,input().split())
   if s>t:a+=s+t
   elif s<t:b+=s+t
   else:a+=s;b+=t
  print(a,b)


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
/******************************************
* AUTHOR : PANDRAVISAM SHIVA SANTHOSH *
* Handle : santhosh_80 *
* INSTITUTION : IIT Palakkad *
******************************************/
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
#define ll long long int 
#define mod 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define S(x) scanf("%d",&(x))
#define P(x) printf("%d\n",(x))
#define Sl(x) scanf("%lld",&(x))
#define Pl(x) printf("%lld\n",(x))
#define pb push_back
#define f first
#define s second

ll dp[100003];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,W ;cin >> n >> W ;
	ll w[n+3] , v[n+3] ;
	ll max_val = 0 ;
	for(int i = 1; i <= n ; i++ ){
		cin >> w[i] ;
		cin >> v[i] ;
		max_val+=v[i] ;
	} 
	for(int j = 0; j <= max_val ; j++){
		 dp[j] = LLONG_MAX; ;
	}

	dp[0] = 0 ;

	for(int i = 1 ;i <= n ; i++){
		for(int j = max_val; j >= 0; j--){

				if(dp[j] != LLONG_MAX){
					dp[j+v[i]] = min(dp[j]+w[i],dp[j+v[i]]) ;
				}

		}

	}
	ll ans = -1;
	for(int  i = max_val ; i >= 0; i--){
		if(dp[i] <= W) {
			ans = i ;
			break ;
		}
	}
	cout << ans ;

 	return 0;
}

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

using namespace std;

int main(){
	ios::sync_with_stdio(false);	
	cin.tie(0);
	long w, h, x, y;
	cin >> w >> h >> x >> y;
	cout << fixed << setprecision(6) << (double)(w*h*0.5);
	cout << " " << (2*x == w && 2*y == h);
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
#define mod 1000000007

ll mul(ll a, ll b) {
  return a * b % mod;
}

ll rev(ll a) {
  ll ans = 1, b = mod - 2;
  while(b) {
    if(b & 1) ans = mul(ans, a);
    a = mul(a, a), b >>= 1;
  }
  return ans;
}
    

int main(void) {
  ll i, j, n, m, now = 1, c = 1, ans = 0, t = 1;
  scanf("%lld", &n);
  char s[1000010];
  scanf("%s", s);
  for(m = 0; s[m]; ++m);
  for(i = 0; i < n + 1; ++i) 
    ans += mul(now, c), ans %= mod, now = mul(now, 25), c = mul(c, mul(rev(i + 1), n + m - i));
  printf("%lld", ans);
  return 0;
}


Measured memory_bytes: 4772
N = int(input())
h = [int(i) for i in input().split()]

memo = []
for i in range(N):
  if i == 0:
    memo.append(0)
  elif i == 1:
    memo.append(memo[i - 1] + abs(h[i - 1] - h[i]))
  else:
    j1 = memo[i - 1] + abs(h[i - 1] - h[i])
    j2 = memo[i - 2] + abs(h[i - 2] - h[i])
    memo.append(j1 if j1 < j2 else j2)

print(memo[N - 1])

Measured memory_bytes: 14056
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	if (a + b == c || a + c == b || b + c == a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
#define fi first
#define se second
#define pb push_back
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
const int maxn = 100005;

int main(){
// ios::sync_with_stdio(false), cin.tie(0);

int N, cnt[maxn];
for(int i = 0; i < maxn; i++)cnt[i] = 0;	
cin >> N;

for(int i = 0; i < N; i++){
	int t; cin >> t;
	if(t > 0) cnt[t - 1]++;
	cnt[t]++, cnt[t + 1]++;
}
int mx = 0, ind;
for(int i = 0; i < maxn; i++)if(cnt[i] > mx){
	mx = cnt[i], ind = i;
}

cout << mx;
} 

Measured memory_bytes: 640
#include <stdio.h>

int main(){
	int k;
	scanf("%d",&k);
	if(k % 2 == 1)
		printf("%d",(k / 2 + 1)*((k - 1) / 2));
	else
		printf("%d",(k / 2) * (k / 2));
	return 0;	
}

Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n, N) for(ll i=(n);i<(N);i++)
#define RREP(i, n, N) for(ll i=(N-1);i>=(n);i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(), (v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll N;
ll x[110], y[110], h[110];

int main() {
    cin>>N;
    REP(i,0,N){
        cin>>x[i]>>y[i]>>h[i];
    }

    REP(cx,0,101){
        REP(cy,0,101){
            bool f = true;

            ll mxh = inf;
            ll th = -1;

            REP(i,0,N){
                if(h[i] == 0){ // 高さの制約を追加
                    mxh = min(mxh, abs(x[i]-cx) + abs(y[i]-cy));
                }else{  // 高さが１つに特定
                    ll ch = h[i] + abs(x[i]-cx) + abs(y[i]-cy);
                    if(ch < 1){
                        f = false;
                        break;
                    }

                    if(th != -1){
                        if(ch != th){   // 過去に決定した高さ(th)と異なる値
                            f = false;
                            break;
                        }
                    }else{
                        th = ch;    // 高さが初めて決定
                    }
                }

            }
            if (f && th <= mxh){
                if(th == -1){
                    cout<<cx<<" "<<cy<<" "<<mxh<<endl;
                }else{
                    cout<<cx<<" "<<cy<<" "<<th<<endl;
                }
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

#define ll long long
#define PII pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size))           \
  scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name)
#define DEBUG(...) debug(__LINE__,__VA_ARGS__)
#define MOD 1000000007

using namespace std;

string to_string(string s) { return s; }

template <class T>
string to_string(vector<T> v) {
	string ret = "{";
	FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
	if (v.size() > 0) {
		ret += to_string(LAST(v));
	}
	ret += "}";
	return ret;
}

void debug_print() { cerr << endl; }

template <class Head, class... Tail>
void debug_print(Head head, Tail... tail) {
	cerr << to_string(head) << " ";
	debug_print(tail...);
}

template <class... T>
void debug(T... args) {
	debug_print(args...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
	cout << to_string(head) << " ";
	print(tail...);
}

int main() {
	GI(N);
	GVI(a,N);
	int mx=*max_element(ALL(a)),mn=*min_element(ALL(a));
	bool f=1;
	for(int i=mn;i<=mx;++i){
		int ct=0;
		FOR(j,N){
			if(a[j]==i)ct++;
		}
		if((i!=mn&&ct<2)||(mx%2==0&&i==mn&&ct!=1)||(mx%2==1&&i==mn&&ct!=2)){
			f=0;
		}
	}
	print(f?"Possible":"Impossible");
	return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll x[5];
    rep(i, 5) { cin >> x[i]; }

    rep(i, 5) {
        if (x[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 3592
#include<stdio.h>

int sum5,sum7;

int main(void){
	for(int i=1,temp;i<=3;i++){
		scanf("%d",&temp);
		if(temp==5)
			sum5++;
		else if(temp==7)
			sum7++;
	}
	if(sum5==2&&sum7==1)
		puts("YES");
	else
		puts("NO");
	return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k, q;
    cin >> n >> k >> q;
    vi a(n, 0);
    forn(i, q) {
        int x;
        cin >> x;
        x--;
        a[x]++;
    }
    forn(i, n) if (k - (q - a[i]) > 0) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n,a[20],b[20],c[20],ans=0;
    cin >> n;
    rep(i,n)cin >> a[i];
    rep(i,n){cin >> b[i];ans+=b[i];}
    rep(i,n-1)cin >> c[i];
    
    rep(i,n){
        if(i!=0 and a[i]-1==a[i-1])ans+=c[a[i-1]-1];
    }
    
    cout << ans;
    
	return 0;
}

Measured memory_bytes: 3536