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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

template<typename T>
T mypow(T a, int n){
  if(n == 0) return 1;
  if(n%2 == 0){
    T res = mypow(a, n/2);
    return res * res;
  }
  return a * mypow(a, n-1);
}

int main(){
  int d, n;
  cin >> d >> n;
  if(n == 100) n++;
  int ans = mypow(100, d) * n;
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main
{
    public static void main(String args[])
    {
        Scanner scan = new Scanner(System.in);
        
        int S = scan.nextInt();
        int h = S/3600;
        int m = (S%3600)/60;
        int s = (S%3600)%60;
        System.out.println(h+":"+m+":"+s);
    }
}


Measured memory_bytes: 26188
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;

int ar[10]={0};

int main()
{
    idfc;
    int a,b,c;
    cin>>a>>b>>c;
    int r=0;
    for(int i=1;i<=b;i++)
    {
        r+=a;
        if((r%b)==c){cout<<"YES";return 0;}
    }
    cout<<"NO";
    
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

long long inf = 2e9;

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

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

	vector<int> dp(n + k + 2, inf);
	dp[0] = 0;

	for (int i = 0; i < n - 1; i++) {
		for (int j = 1; j <= k; j++) {
			dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
		}
	}

	int ans = dp[n - 1];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
    int i;
    int a[3];
    int q=0;
    int output;
    
    for(i=0;i<3;i++){
    if (scanf("%d",&a[i])==1){
    }else{
    }
    }
    
    
    while(a[0]>a[1]){
        a[0]=a[0]-a[1];
        q++;
    }

    if(a[0]!=0){
    output=(q+1)*a[2];
    }
    
    if(a[0]=0){
    output=q*a[2];
    }
    

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

    return 0;
}


Measured memory_bytes: 1716
#include<bits/stdc++.h>
using namespace std;
int main(void){
  	char a;
  cin >> a;
  if(a == 'a' || a == 'i' || a == 'u' || a == 'o' || a == 'e'){
		cout << "vowel" << endl;
  }else{
    	cout << "consonant" << endl;
  }
}


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

int dat[100005];

int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) scanf("%d", &dat[i]);

	bool firstwin = false;

	for (bool first = true;; first ^= true)
	{
		int even = 0, one = 0;
		for (int i = 0; i < n; i++)
		{
			if (dat[i] % 2 == 0) even++;
			else if (dat[i] == 1) one++;
		}

		if (one)
		{
			if (even % 2) firstwin = first;
			else firstwin = !first;
			break;
		}

		if (even % 2)
		{
			firstwin = first;
			break;
		}

		if (even != n - 1)
		{
			firstwin = !first;
			break;
		}

		int g = 0;

		for (int i = 0; i < n; i++)
		{
			if (dat[i] % 2) --dat[i];
			g = gcd(dat[i], g);
		}

		for (int i = 0; i < n; i++) dat[i] /= g;
	}

	if (firstwin) printf("First\n");
	else printf("Second\n");
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
const long long Mod = 1000000007LL;
long long dp[1010][2];
vector <int> g[1010],g2[1010];
int use[1010];
int in[1010];
int u[1010],v[1010];
void f(int x)
{
    dp[x][0]=1;
    dp[x][1]=1;
    for (int i=0;i<g[x].size();i++)
    {
        int y=g[x][i];
        f(y);
        dp[x][0]=dp[x][0]*dp[y][0]%Mod;
        dp[x][1]=dp[x][1]*(dp[y][0]+dp[y][1])%Mod;
    }
}
int lea[1010];
int from[1010],tStamp;
void dfs(int x)
{
    use[x]=1;
    for (int i=0;i<g[x].size();i++)
    {
        int v=g[x][i];
        if (use[v]) continue;
        dfs(v);
    }
    lea[tStamp++]=x;
}
void dfs2(int x,int col)
{
    from[x]=col;
    use[x]=1;
    for (int i=0;i<g2[x].size();i++)
    {
        int v=g2[x][i];
        if (use[v]) continue;
        dfs2(v,col);
    }
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for (int i=0;i<m;i++)
    {
        scanf("%d%d",&u[i],&v[i]);
        g[u[i]].push_back(v[i]);
        g2[v[i]].push_back(u[i]);
    }
    memset(use,0,sizeof(use));
    tStamp=0;
    for (int i=1;i<=n;i++)
    {
        if (use[i]) continue;
        dfs(i);
    }
    int col=0;
    memset(use,0,sizeof(use));
    for (int i=tStamp-1;i>=0;i--)
    {
        int u=lea[i];
        if (use[u]) continue;
        dfs2(u,col++);
    }
    for (int i=1;i<=n;i++)
        g[i].clear();
    memset(in,0,sizeof(in));
    for (int i=0;i<m;i++)
    {
        int pu=from[u[i]];
        int pv=from[v[i]];
        if (pu==pv) continue;
        g[pv].push_back(pu);
        in[pu]++;
    }
    long long ans=1;
    for (int i=0;i<col;i++)
    {
        if (in[i]!=0) continue;
        f(i);
        ans=ans*(dp[i][0]+dp[i][1])%Mod;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1188
#include <cstdio>
#include <cstdlib>

using namespace std;

int main(){
	long N;
	long long K;
	long long n[100000];

	scanf("%ld",&N);
	scanf("%lld",&K);

	for(long i=0;i<100000;i++) n[i] = 0;

	for(long i=0;i<N;i++){
		long a,b;
		scanf("%ld %ld",&a,&b);
		a--;
		n[a] += b;
	}



	long long cnt = 0;
	long j;
	for(j=0;cnt<K;j++){
		cnt += n[j];
	}
	printf("%ld\n",j);


	return 0;
}


Measured memory_bytes: 896
#include<string>
#include<cstdio>
#include<cctype>
#include<iostream>
#include <algorithm>
#include<cmath>
#include<queue>
using namespace std;

    unsigned long long int dp[105][25]={0};
int main(){
    int num[110]={0},n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>num[i];
    }
    dp[0][num[0]]=1;
    for(int i=1;i<n-1;i++){
        for(int j=0;j<=20;j++){
            if(dp[i-1][j]>0){
                int sum=j+num[i];

                if(sum<=20)dp[i][sum]+=dp[i-1][j];

                sum=j-num[i];

                if(sum>=0)dp[i][sum]+=dp[i-1][j];
            }
        }
    }
    cout<<dp[n-2][num[n-1]]<<endl;
    return 0;
}

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

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        P[] ps = new P[n];

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

        Arrays.sort(ps);
        for (int i = 0; i < n; i++) {
            if (t > ps[i].b) t = ps[i].b;
            if (t - ps[i].a < 0) {
                System.out.println("No");
                return;
            }
            t -= ps[i].a;
        }

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

    class P implements Comparable<P> {
        int a, b;
        P(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(P o) {
            return o.b - b;
        }
    }


    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 103184
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int h1, s1, h2, s2;
	cin >> h1 >> s1 >> h2 >> s2;
	while (1) {
		if (s1 >= h2) {
			cout << "Yes\n";
			break;
		}
		h2 -= s1;
		if (s2 >= h1) {
			cout << "No\n";
			break;
		}
		h1 -= s2;
	}

	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int N, W;
int v[100], w[100];
int dp[10001];

int main(void){
    cin >> N >> W;
    for(int i = 0; i < N; i++) cin >> v[i] >> w[i];

    for(int i = 0; i < N; i++){
        for(int j = w[i]; j <= W; j++){
            dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
            // printf("dp(%d, %d) = %d\n", i, j, dp[j]);
        }
    }

    cout << *max_element(dp, dp + W + 1) << '\n';

    return 0;
}


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

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

	int ans1 = A + B;
	int ans2 = A - B;
	int ans3 = A * B;

	cout << max({ ans1,ans2,ans3 }) << endl;
}






Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);



signed main(){
    int n,smin=INF,sum=0;cin>>n;

    for(int i=0;i < n;i++)
    {
        int s;cin>>s;
        sum+=s;
        if(s%10)smin=min(smin,s);
    }
    
    if(sum%10)cout<<sum<<endl;
    else if(smin==INF)cout<<0<<endl;
    else cout<<sum-smin<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    unordered_map<char, int> m;

    for (int i = 0; i < S.size(); ++i) {
        m[S[i]]++;
    }

    for (auto&& p : m) {
        if (p.second != 1) {
            cout << "no" << endl;
            return 0;
        }
    }

    cout << "yes" << endl;

    return 0;
}


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

int main(){
  
  string S;
  cin >> S;
  
  bool flag=1;
  
  for (int i=0;i<S.size();i++){
    if (i%2==0 && !(S.at(i)=='R' || S.at(i)=='U' || S.at(i)=='D') )
      flag=0;
    if (i%2==1 && !(S.at(i)=='L' || S.at(i)=='U' || S.at(i)=='D') )
      flag=0;
  }
  
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RANGE(i,n) for(int i=0;i<n;i++)
typedef long long ll;

using namespace std;

struct status{
    ll oishisa;
    ll now_x;
    ll now_y;
    ll now_z;
};

//bool already[X][Y][Z];
bool already[1000][1000][1000];

signed main() {
    ll X,Y,Z,K;
    cin >>X>>Y>>Z>>K;
    vector<ll> A(X);
    vector<ll> B(Y);
    vector<ll> C(Z);

    RANGE(i,X) cin >> A[i];;
    RANGE(i,Y) cin >> B[i];;
    RANGE(i,Z) cin >> C[i];;

    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());
    sort(C.begin(), C.end(), greater<ll>());

    ll now_A = 0;
    ll now_B = 0;
    ll now_C = 0;

    auto c = [](status a, status b){
        return a.oishisa < b.oishisa;
    };

    priority_queue<status, vector<status>, decltype(c)> q(c);
    status init_s = {A[0]+B[0]+C[0], 0,0,0};
    
    q.push(init_s);

    RANGE(i,K){
        status now = q.top();
        cout << now.oishisa << endl;
        //cout << now.now_x << "-" << now.now_y << "-" << now.now_z << " oishisa:" << now.oishisa << endl;
        q.pop();

        ll x = now.now_x;
        ll y = now.now_y;
        ll z = now.now_z;

        if(now.now_x < X-1 && !already[x+1][y][z]){
            status plus_x = {A[x+1]+B[y]+C[z], x+1,y,z};
            q.push(plus_x);
            already[x+1][y][z] = true;
        }

        if(now.now_y < Y-1 && !already[x][y+1][z]){
            status plus_y = {A[x]+B[y+1]+C[z], x,y+1,z};
            q.push(plus_y);
            already[x][y+1][z] = true;
        }

        if(now.now_z < Z-1 && !already[x][y][z+1]){
            status plus_z = {A[x]+B[y]+C[z+1], x,y,z+1};
            q.push(plus_z);
            already[x][y][z+1] = true;
        }
    }
}


Measured memory_bytes: 973312
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
using namespace std;

int main() {
	int n;
	while(cin >> n, n) {
		vector<int> v;
		map<string,int> index;
		bool f[128] = {0};

		for(int i = 0; i < n; i++) {
			string s;
			int c;
			cin >> s >> c;
			v.push_back(c);
			index[s] = i;
		}

		int m;
		int edge[128][128] = {0};
		cin >> m;
		for(int i = 0; i < m; i++) {
			int k;
			string s0, s1;
			cin >> s0 >> k;
			for(int j = 0; j < k; j++) {
				string s1;
				cin >> s1;
				edge[index[s0]][index[s1]] = 1;
//				cout << index[s0] << " " << index[s1] << endl;
				f[index[s0]] = true;
			}
		}

		for(int i = 0; i < v.size(); i++) {
			for(int j = 0; j < v.size(); j++) {
				if(f[j]) {
					int cost = 0;
					for(int k = 0; k < v.size(); k++) {
						if(edge[j][k]) {
							cost += v[k];
						}
					}
					v[j] = min(v[j], cost);
				}
			}
		}

		string want;
		cin >> want;

		cout << v[index[want]] << endl;
	}
}

Measured memory_bytes: 1308
N,s=map(int, input().split())
*X,=map(int, input().split())
X.sort()
X = [s] + X

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

g=0
for i in range(N):
    g = gcd(g, abs(X[i+1]-X[i]))
print(g)

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

int main()
{
    int h;
    int w;
    long temp;
  	cin >> h >> w;
    vector<vector<int> > a(h, vector<int>(w, 0));
    vector<vector<int> > b(h, vector<int>(w, 0));

    char s;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> s;
            if(s=='.'){
                b[i][j]=1;
            }else if(s=='#'){
                b[i][j]=0;
            }
            else{
                printf("err\n");
            }
        }
    }
//    printf("test\n");
    for(int i=0;i<h;i++){
        temp=0;
        for(int j=0;j<w;j++){
            temp=(temp + 1)*b[i][j];
            a[i][j] += temp;
        }
    }
    for(int i=0;i<h;i++){
        temp=0;
        for(int j=w-1;j>=0;j--){
            temp=(temp + 1)*b[i][j];
            a[i][j] += temp;
        }
    }
    for(int j=0;j<w;j++){
        temp=0;
        for(int i=0;i<h;i++){
            temp=(temp + 1)*b[i][j];
            a[i][j] += temp;
        }
    }
    for(int j=0;j<w;j++){
        temp=0;
        for(int i=h-1;i>=0;i--){
            temp=(temp + 1)*b[i][j];
            a[i][j] += temp;
        }
    }
    long answer=3;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(answer<a[i][j]){
                answer= a[i][j];
            }
        }
    }
    printf("%ld\n",answer-3);
}



Measured memory_bytes: 33664
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long t,n,i,ans,cnt,j,k;
       cin>>i>>j;
       if(j%2!=0)
        cout<<"No";
        else
       {
           if(j>4*i||j<2*i)
            cout<<"No";
           else
            cout<<"Yes";
       }

}


Measured memory_bytes: 3612
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fromIntegral . fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

limit :: [[Int]] -> Int -> Int -> Int
limit [] mi ma = ma - mi + 1
limit (lr : lrs) mi ma
  | mi <= ma = limit lrs mi' ma'
  | otherwise = 0
  where
    l = head lr
    r = last lr
    mi' = maximum [l, mi]
    ma' = minimum [r, ma]

main = do
  [n, m] <- getIntList
  lrs <- getIntNList m
  print $ limit lrs 1 n


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

int main(){
    int a,b,c,x,y,ans=2000000000;
    cin>>a>>b>>c>>x>>y;
    int M=max(x,y);
    for(int i=0;i<=2*M;i+=2){
        int na=max(x-i/2,0);
        int nb=max(y-i/2,0);
        ans=min(ans,a*na+b*nb+c*i);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <set>
#include <cmath>
#include <cstring>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <iomanip>
#include <ctime>
#include <deque>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdlib>
#include <cassert>

#define nl "\n"
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define p_un(a) ((void)a)
#define p_st(a) string(a)
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define naj ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define NL cout << endl;
#define sqr(x) (sqrt(x) * 1LL)
#define pcnt(i) __builtin_popcount(i)
#define lcm(a,b) (a * b) / __gcd(a, b)
#define E 2.718281828459045
#define PI 3.141592653589793
#define up_b upper_bound
#define low_b lower_bound
#define FILE_NAME "A"
#define show(x) cout << (#x) << ": " << x << endl

using namespace std;

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;
typedef vector <llong> vl;
typedef vector <bool> vb;
typedef vector <char> vc;
typedef vector <int> vi;
typedef vector <string> vs;
typedef pair <llong, llong> pll;
typedef map <llong, llong> mll;
typedef set <llong> sl;
typedef set <char> sc;
typedef map <string, llong> msl;
typedef map <string, bool> msb;
typedef map <char, llong> mcl;
typedef map <string, string> mss;

const llong MXN = 1e6 + 1;
const llong MOD = 1e9 + 7;
const llong INF = 1e18;
const ldouble EPS = 1e-9;

#define int int64_t

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

int used[MXN], ans;

signed main() {

    naj;
#ifdef LOL
    freopen(FILE_NAME".in", "r", stdin);
    freopen(FILE_NAME".out", "w", stdout);
#endif
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        int k;
        cin >> k;
        for(int j = 1; j <= k; j++) {
            int x;
            cin >> x;
            used[x] ++;
        }
    }
    for(int i = 1; i <= m; i++) {
        ans += (used[i] == n ? 1 : 0);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  int N=0;
  int a[H][W];
  int b[H][W];
  int sum=0;
  int min=10;
  int mi,mj;
  REP(i,H){
    REP(j,W){
      cin>>a[i][j];
      b[i][j]=a[i][j];
      sum+=a[i][j];
      if(min>a[i][j]){
        min=a[i][j];
        mi=i;
        mj=j;
      };
    }
  }
  if(sum%2==0){
    mi=H;
    mj=W;
  }
  REP(i,H){
    REP(j,W){
      if(i==H-1 and j==W-1)break;
      if(a[i][j]%2==1 or (i==mi and j==mj and a[i][j]%2==0)){
        if(j!=W-1){
          N++;
          // cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
          a[i][j]--;
          a[i][j+1]++;
        }else{
          N++;
          // cout<<i+1<<" "<<j+1<<" "<<i+2<<" "<<j+1<<endl;
          a[i][j]--;
          a[i+1][j]++;
        }
      }
    }
  }
  cout<<N<<endl;
  REP(i,H){
    REP(j,W){
      if(i==H-1 and j==W-1)break;
      if(b[i][j]%2==1 or (i==mi and j==mj and b[i][j]%2==0)){
        if(j!=W-1){
          N++;
          cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
          b[i][j]--;
          b[i][j+1]++;
        }else{
          N++;
          cout<<i+1<<" "<<j+1<<" "<<i+2<<" "<<j+1<<endl;
          b[i][j]--;
          b[i+1][j]++;
        }
      }
    }
  }
  // REP(i,H){
  //   REP(j,W){
  //     cout<<a[i][j];
  //   }
  //   cout<<endl;
  // }
  return 0;
}


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

using namespace std;
using ll=long long;

ll f(ll i, ll n) {
    ll x = n;
    ll sum = 0;
    while (x) {
        sum += x%i;
        x /= i;
    }
    return sum;
}

void solve() {
    ll n, s;
    cin >> n >> s;
    if (n == s) {
        cout << (n+1); return;
    }
    if (n < s) {
        cout << -1; return;
    }
    for (ll i = 2; i*i <= n; i++) {
        if (f(i,n) == s) {
            cout << i; return;
        }
    }
    ll res = 1ll<<55;
    for (ll j = 1; j*j <= n; j++) {
        if ((n-s)%j) continue;
        ll i = (n-s)/j + 1;
        if (f(i, n) == s) {
            res = min(res, i);
        }
    }
    if (res > (1ll<<53)) res = -1;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

int main()
{
	int n,i;
	double ans=0.0,u[11];
	string s[11];

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

	for(i=0;i<n;i++){
		if(s[i]=="JPY"){
			ans+=u[i];
		}
		else{
			ans+=u[i]*380000.0;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> vs(n); cin >> vs;
    vector<int> cs(n); cin >> cs;
    int ans = 0;
    for(int i = 0; i < n; i++){
        ans += max(0, vs[i] - cs[i]);
    }
    cout << ans << '\n';
}


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

using namespace std;

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

    if(a+b >= 5.5){
        cout << (int)((a+b)+1)/2 << endl;
    }else{
        cout << (int)(a+b)/2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll mod = 998244353;
ll n, dp[3100][3100];
int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    FOR(i, a, c + 1){
        FOR(j, b, d + 1){
            if (i == a and j == b) continue;
            dp[i][j] += dp[i - 1][j] * j + dp[i][j - 1] * i;
            dp[i][j] -= dp[i - 1][j - 1] * (i - 1) % mod * (j - 1) % mod;
            dp[i][j] = (dp[i][j] + mod) % mod;
        }
    }
    cout << dp[c][d] << endl;
}


Measured memory_bytes: 76280
#include<iostream>
using namespace std;
int main(){
			int n;
			cin>>n;
			float a[n];
			for(int i=0;i<n;i++){
								cin>>a[i];
			}
			float sum=0;
			for(int i=0;i<n;i++){
									sum=sum+(1/a[i]);
								}
								float val=(1/sum);
								cout<<val;
								return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,b,c,x;
scanf("%d %d %d",&a,&b,&c);
if(a>b){
x=a;
a=b;
b=x;
}
if(b>c){
x=b;
b=c;
c=x;
}
if(a>b){
x=a;
a=b;
b=x;
}
printf("%d %d %d\n",a,b,c);
}

Measured memory_bytes: 1764
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,a[1200000]={},s[1200000]={},ans=0;
  cin >> n;
  a[0]=1;
  a[1]=1;
  s[0]=1;
  s[1]=2;
  FOR(i,2,1000001){
    a[i]=((s[i-1]-a[i-2])%MOD+MOD)%MOD;
    s[i]=((s[i-1]+a[i])%MOD+MOD)%MOD;
  }
  ans=((ans+s[n-2]*POW(n-1,2))%MOD+MOD)%MOD;
  ans=((ans+a[n-1]*(n-1)%MOD)%MOD+MOD)%MOD;
  ans=(ans+a[n])%MOD;
  rep(i,n-1)ans=((ans+a[i]*(i+1)%MOD)%MOD+MOD)%MOD;
  printf("%lld",ans);
}

Measured memory_bytes: 18944
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());



int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> tab(h+2,vector<char>(w+2,'.'));
  rep1(i,h) rep1(j,w) cin >> tab[i][j];
  rep1(i,h){
    rep1(j,w){ //i行j列目（1-indexed）
      int check = 0;
      if(tab[i][j] == '#') check ++;
      if(tab[i-1][j] == '.') check ++;
      if(tab[i+1][j] == '.') check ++;
      if(tab[i][j-1] == '.') check ++;
      if(tab[i][j+1] == '.') check ++;
      if(check == 5){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    int o = 1;
    for (int i=0; i<N ;i++){
        if(o > K){
            o =  o + K;
        }else{
            o = o * 2;
        }
    }
    cout << o << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

int n; string str;
bool ani[100000];

//1 is sheep, 0 is wolf
bool solve(bool a, bool b){
  ani[0]=a; ani[1]=b;
  int idx=2;
  while(idx <= n-1){
    if((ani[idx-1] == 1 && str[idx-1] == 'o') ||
    (ani[idx-1] == 0 && str[idx-1] == 'x')){
          ani[idx]=ani[idx-2];
    }else{
      ani[idx]=!(ani[idx-2]);
    }
    idx++;
  }

  if((ani[n-1] == 1 && str[n-1] == 'o') ||
  (ani[n-1] == 0 && str[n-1] == 'x')){
    if(ani[n-2] != ani[0]){
      return false;
    }
    else{
      if((ani[0] == 1 && str[0] == 'o') ||
      (ani[0] == 0 && str[0] == 'x')){
        if(ani[n-1] == ani[1]) return true;
        else return false;
      }else{
        if(ani[n-1] == ani[1]) return false;
        else return true;
      }
    }
  }else{
    if(ani[n-2] == ani[0]) return false;
    else{
      if((ani[0] == 1 && str[0] == 'o') ||
      (ani[0] == 0 && str[0] == 'x')){
        if(ani[n-1] == ani[1]) return true;
        else return false;
      }else{
        if(ani[n-1] == ani[1]) return false;
        else return true;
      }
    }
  }
}

void print(){
  for(int i=0;i<n;i++){
    if(ani[i]) cout << 'S';
    else cout << 'W';
  }
  cout << endl;
}

int main(){
  cin >> n >> str;
  if(solve(1, 1)){
    print();
  }else if(solve(0, 0)){
    print();
  }else if(solve(0, 1)){
    print();
  }else if(solve(1, 0)){
    print();
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define pi acos(-1.0)
#define pb push_back
#define vi vector<int>
#define mapii map<int , int>
#define mapci map<char, int>
#define mapsi map<string,int>
#define FOR(i,n) for(int i = 0;i<n;i++)
#define CP(n) cout<<"Case "<<n<<": "
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
#define MAX 1000007
#define all(x)(x.begin(),x.end())
#define debug(x,c) cout<<x<<": "<<c<<" ";
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
int par[200005];
mapii mp;
int find_parent(int a)
{
	if(par[a]==a)
		return a;
	return par[a] = find_parent(par[a]);
}
void dsu(int a, int b)
{
	int x = find_parent(a);
	int y = find_parent(b);
	if(y>x)
		par[y] = x;
	else
		par[x] = y;
	return;
}
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i =1;i<=n;i++)
		par[i] = i;
	for(int i = 0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		dsu(a,b);
	}
	int ans = 1;
	for(int i = 1;i<=n;i++)
		mp[find_parent(i)]++;

	for(auto x: mp)
		ans=max(ans,x.second);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 13680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  ll xs = 0;
  vl a(n);
  rep(i, n) {
    cin >> a[i];
    xs ^= a[i];
  }
  rep(i, n) cout << (xs ^ a[i]) << ' ';
  cout << endl;
}

Measured memory_bytes: 4828
#include <cstdio>

using namespace std;

int main()
{
    int d, s;
    scanf( "%d\n", &d );
    for( int i = 0; i < d; i++ )
    {
        scanf( "%d\n", &s );
        printf( "Case %d:\n", i + 1 );
        for( int j = 0; j < 10; j++ )
        {
            s = s * s;
            s /= 100;
            s %= 10000;
            printf( "%d\n", s );
        }
    }    
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    for(int i=0; i<=100; i++) {
        for(int j=0; j<= 100; j++){
            if(i * 4 + j * 7 == n) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void printDP(const int n, const int c, vector<vector<int> >& dp){
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= c; j++) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}

int knapsack01_a(const int n, const int c, const vector<int>& v, const vector<int>& w) {
    
    vector<vector<int>> dp(n + 1, vector<int>(c + 1, 0));
    
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= c; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j >= w[i - 1]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
            }
        }
    }
    //printDP(n, c, dp);
    return dp[n][c];
}

int knapsack01_b(const int n, const int c, const vector<int>& v, const vector<int>& w) {
    
    vector<vector<int>> dp(n + 1, vector<int>(c + 1, 0));
    
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j <= c; j++) {
            dp[i][j] = dp[i + 1][j];
            if (j >= w[i]) {
                dp[i][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
            }
        }
    }
    //printDP(n, c, dp);
    return dp[0][c];
}


int main() {
    int n, c;
    cin >> n >> c;
    vector<int> v(n, 0);
    vector<int> w(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> v[i] >> w[i];
    }
    int ans = knapsack01_b(n, c, v, w);
    cout << ans << endl;
}

Measured memory_bytes: 6744
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int main() {
  int N;
  cin>>N;
  vector<int>a(N),b(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  for(int i=0;i<N;i++){
    cin>>b[i];
  }
  int64_t cntp=0,cntm=0;
  for(int i=0;i<N;i++){
   if(a[i]>b[i]){cntp+=(a[i]-b[i]);}
   if(b[i]>a[i]){cntm+=(b[i]-a[i])/2;}
  }
  if(cntp<=cntm){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;
}

Measured memory_bytes: 3712
//「這い上がる」の定義があいまいなことから、エスパー力が本質っぽい問題だと思う。
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
typedef pair<int,int> P;

int h, w;
char data[114][514];
int dp[552194];
queue<P> que;

int dy[4] = {1,0,-1,0};
int dx[4] = {0,1,0,-1};
int main(){
	int i,j;
	while (cin >> w >> h) {
		int g;
		if (!h) break;
		for (i = 0; i < h; i++) cin >> data[i];
		for (i = 0; i < w*h; i++) dp[i] = 5642194;
		for (i = 0; i < h; i++)
			for (j = 0; j < w; j++) {
				if (i == 0 || i == h-1 || j == 0 || j == w-1)
					que.push(P(0, i*w + j));
				if (data[i][j] == '&')
					g = i * w + j;
			}
		while(!que.empty()) {
			int cost = que.front().first;
			int pos = que.front().second;
			que.pop();
			if (dp[pos] <= cost)
				continue;
			dp[pos] = cost;
			for (i = 0; i < 4; i++) {
				int ny = pos/w + dy[i];
				int nx = pos%w + dx[i];
				if (ny < 0 || ny >= h || nx < 0 || nx >= w)
					continue;
				que.push( P( cost + (data[ny][nx] != '#' && data[pos/w][pos%w] == '#'), ny*w + nx ) );
			}
		}
		cout << dp[g] << endl;
	}
	return 0;
}

Measured memory_bytes: 1332
#include<iostream>

using namespace std;

int H[1000000], W[1000000];

int main(){

	for (int a = 0; a < 1000000; a++){


		cin >> H[a] >> W[a];

		if (H[a] == 0 && W[a] == 0)   break;

		else	if (W[a] % 2 == 0 && H[a] % 2 == 0){
			for (int n = 1; n <= H[a]; n += 2){


				for (int s = 1; s <= W[a]; s += 2){

					cout << "#.";

				}
				cout << endl;
				for (int x = 1; x <= W[a]; x += 2){

					cout << ".#";

				}
				cout << endl;
			}
		}

		else if (W[a] % 2 == 0 && H[a] % 2 != 0){


			for (int n = 1; n < H[a]; n += 2){


				for (int s = 1; s <= W[a]; s += 2){

					cout << "#.";

				}
				cout << endl;
				for (int x = 1; x <= W[a]; x += 2){

					cout << ".#";

				}
				cout << endl;
			}
			for (int s = 1; s < W[a]; s += 2){

				cout << "#.";


			}
			cout << endl;
		}

		else if (H[a] % 2 == 0 && W[a] % 2 != 0){


			for (int n = 1; n <= H[a]; n += 2){



				for (int s = 1; s < W[a]; s += 2){
					cout << "#.";
				}
				cout << "#" << endl;
				for (int x = 1; x < W[a]; x += 2){
					cout << ".#";
				}
				cout << "." << endl;




			}
		}


		else if (H[a] % 2 != 0 && W[a] % 2 != 0){

			for (int n = 1; n < H[a]; n += 2){


				for (int s = 1; s < W[a]; s += 2){
					cout << "#.";
				}
				cout << "#" << endl;
				for (int x = 1; x < W[a]; x += 2){
					cout << ".#";
				}
				cout << "." << endl;
			}

			for (int s = 1; s < W[a]; s += 2){
				cout << "#.";
			}
			cout << "#" << endl;



		}


cout<<endl;



	}


	return 0;
}


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

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

  int ans = 0;
  rep(i, n-2){
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
      ans++;
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;
typedef pair<int,int> pr;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main(){
    int d[10][10],a;
    ll h,w; cin >> h >> w;
    ll ans = 0;
    int V = 10;

    rep(i,V){
        rep(j,V) cin >> d[i][j];
    }

    for(int k = 0; k < V; k++) {
        for(int i = 0; i < V; i++) {
            for(int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    rep(i,h){
        rep(j,w){
            cin >> a;
            if(a != -1 && a != 1)  ans += d[a][1];
        }
    }

    cout << ans;



}

Measured memory_bytes: 3632
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double w = sc.nextDouble();
		double h = sc.nextDouble();
		int x = sc.nextInt();
		int y = sc.nextInt();
		if (x == w / 2 && y == h / 2) {
			System.out.println(w * h / 2 + " " + 1);
		} else {
			System.out.println(w * h / 2 + " " + 0);
		}
	}
}



Measured memory_bytes: 23252
#include <stdio.h>

int main(void)
{
  int num;
  scanf("%d", &num);
  int numCopy = num;
  int numReverse = 0;
  int tmp;
  while (numCopy != 0)
  {
    tmp = numCopy % 10;

    numCopy = numCopy / 10;

    numReverse = numReverse * 10 + tmp;
  }

  if (num == numReverse)
  {
    printf("Yes\n");
  }
  else
  {
    printf("No\n");
  }

  return 0;
}

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

int main(){
	int a,b;
	cin >> a >> b;
	while(a != 0 or b != 0){
		if(b < a){
			swap(a,b);
			cout << a << " " << b << endl;
			cin >> a >> b;
		}
		else{
			cout << a <<" " << b << endl;
			cin >> a >> b;
	}
	}
	return 0;
}


Measured memory_bytes: 3000
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

char ss[25000][6];

int compare(const void *arg1, const void *arg2){
	return(strcmp(ss[*(int*)arg1], ss[*(int*)arg2]));
}

int main(){
	char s[5001];
	int k,g=0,i,j,c=0,l;
	scanf("%s%d",s,&k);
	while(s[g]!=0)g++;
	int num[25000];
	for(i=0;i<25000;i++)num[i]=i;
	for(i=0;i<g;i++){
		for(j=0;j<5&&i+j<g;j++){
			for(l=0;l<=j;l++)ss[c][l]=s[i+l];
			ss[c][5]='\0';
			c++;
		}
	}
	qsort(num,c,sizeof(int),compare);
	int count=0;
	for(i=0;i<c;i++){
		if(count==k-1){
			printf("%s\n",ss[num[i]]);
			return 0;
		}
		if(strcmp(ss[num[i]],ss[num[i+1]])<0)count++;
	}
}

Measured memory_bytes: 508
import java.util.*;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		long[][] gcd = new long[N][N];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				gcd[i][j] = GCD(i+1, j+1);
			}
		}
		long sum = 0;
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				for(int k = 0; k < N; k++) {
					sum += GCD(i+1, gcd[j][k]);
				}
			}
		}
		System.out.println(sum);
	}
	static private long GCD(long X, long Y) {
		while(Y != 0){
			long temp = X % Y;
			X = Y;
			Y = temp;
		}
		return X;
	}
}

Measured memory_bytes: 36052
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

//		System.out.println(a.length);

		for(int i=0;i<n;i++){
			a[i]=stdin.nextInt();
			b[i]=stdin.nextInt();
		}
		stdin.close();
		int max=0;
		List<Integer> bover=new ArrayList<>();
		int turn=0;
		for(int i=0;i<n;i++){
			max=Math.max(max, a[i]);
		}
		for(int i=0;i<n;i++){
			if(max<b[i])
				bover.add(b[i]);
		}
		Collections.sort(bover,Collections.reverseOrder());

		for(int i=0;i<bover.size();i++){
			if(h<=0){
				System.out.println(turn);
				return;
				}
			turn++;
			h=h-bover.get(i).intValue();
			}
		while(h>0){
			h=h-max;
			turn++;
		}
		System.out.println(turn);
	}
}

Measured memory_bytes: 66024
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>
#include <cstdlib>
using namespace std;

namespace zyt
{
	template<typename T>
	inline bool read(T &x)
	{
		char c;
		bool f = false;
		x = 0;
		do
			c = getchar();
		while (c != EOF && c != '-' && !isdigit(c));
		if (c == EOF)
			return false;
		if (c == '-')
			f = true, c = getchar();
		do
			x = x * 10 + c - '0', c = getchar();
		while (isdigit(c));
		if (f)
			x = -x;
		return true;
	}
	template<typename T>
	inline void write(T x)
	{
		static char buf[20];
		char *pos = buf;
		if (x < 0)
			putchar('-'), x = -x;
		do
			*pos++ = x % 10 + '0';
		while (x /= 10);
		while (pos > buf)
			putchar(*--pos);
	}
	typedef pair<int, int> pii;
	const int N = 1e5 + 10, INF = 0x3f3f3f3f;
	int n, k, l[N], r[N], tag[N];
	vector<int> g[N];
	void dfs(const int u, const int f)
	{
		for (auto v : g[u])
		{
			if (v == f)
				continue;
			dfs(v, u);
			l[u] = max(l[u], l[v] - 1), r[u] = min(r[u], r[v] + 1);
			if ((tag[u] >= 0 && tag[v] != -1 && tag[u] != (tag[v] ^ 1)) || l[u] > r[u])
			{
				puts("No");
				exit(0);
			}
			if (tag[v] != -1)
				tag[u] = (tag[v] ^ 1);
		}
	}
	void dfs2(const int u, const int f)
	{
		if (f)
			l[u] = max(l[u], l[f] - 1), r[u] = min(r[u], r[f] + 1);
		for (auto v : g[u])
		{
			if (v == f)
				continue;
			dfs2(v, u);
		}
	}
	int work()
	{
		read(n);
		for (int i = 1; i <= n; i++)
			l[i] = -INF, r[i] = INF, tag[i] = -1;
		for (int i = 1; i < n; i++)
		{
			int a, b;
			read(a), read(b);
			g[a].push_back(b), g[b].push_back(a);
		}
		read(k);
		while (k--)
		{
			int v, t;
			read(v), read(t);
			l[v] = r[v] = t;
			tag[v] = (t & 1);
		}
		dfs(1, 0);
		dfs2(1, 0);
		puts("Yes");
		for (int i = 1; i <= n; i++)
			write(l[i]), putchar('\n');
		return 0;
	}
}
int main()
{
	return zyt::work();
}

Measured memory_bytes: 13824
N, X = map(int, input().split())
A = list(map(int, input().split()))

answer = 0
for i in range(N - 1):
  d = A[i] + A[i+1] - X
  if d <= 0:
    continue
  if d > A[i+1]:
    A[i] -= d - A[i+1]
    A[i+1] = 0
  else:
    A[i+1] -= d
  answer += d

#print(A)
print(answer)

Measured memory_bytes: 63984
#include<bits/stdc++.h>
using namespace std;
long long int n,m;
long long int o,oj,a;
long long int z,nn,mm,y,x,flg;
int main(void)
{
	/*long long int n,m;
	long long int o,oj,a;
	long long int z,nn,mm,y,x,flg;*/
	
	cin>>n>>m;
	
	flg=0;
	for(y=0;y<=n;y++){
	
		nn=n-y,mm=m-y*5000;
		z=(mm-nn*1000)/9000;
		x=nn-z;
		
		if(x<0||z<0) continue;
		
		if(x*1000+z*10000+y*5000==m&&
			x+y+z==n){
			o=x,oj=y,a=z;
			flg=1;
			break;
		}
	}	
	
	if(flg==1) cout<<a<<" "<<oj<<" "<<o<<endl;
	else cout<<-1<<" "<<-1<<" "<<-1<<endl;
	
	return 0;
}	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int M, K;
  cin >> M >> K;
  int MM = 1 << M;

  if(K == 0){
    for(int i=0; i<MM; i++){
      if(i>0) cout << " ";
      cout << i << " " << i;
    }
    cout << endl;
  }else{
    if(M<=1 || MM <= K){
      cout << -1 << endl;
    }else{
      cout << K;
      for(int i=MM-1; i>=0; i--){
        if(i == K) continue;
        cout << " " << i;
      }
      cout << " " << K;
      for(int i=0; i<MM; i++){
        if(i == K) continue;
        cout << " " << i;
      }
      cout << endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 1792
// B - ROT N

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

char replace(char ch, int N) {
    if (ch + N > 'Z') {
        return 'A' + ch + N - 'Z' - 1;
    } else {
        return ch + N;
    }
}

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

    string S;
    cin >> S;

    for (char ch : S) {
        cout << replace(ch, N);
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

struct UnionFind {
    UnionFind() {}
    UnionFind(int n) {
        resize(n);
    }
    
    void resize(int n) {
        par.resize(n, -1);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
    
private:
    vector<int> par;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m), b(m);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    UnionFind uf(n);
    vector<ll> ans(m + 1);
    ans[m] = 0;
    rrep(i, m) {
        if (uf.is_same(a[i], b[i])) {
            ans[i] = ans[i + 1];
        }
        else {
            ans[i] = ans[i + 1] + uf.size(a[i]) * uf.size(b[i]);
            uf.merge(a[i], b[i]);
        }
    }
    rep(i, m) printf("%lld\n", n * (n - 1) / 2 - ans[i + 1]);
    return 0;
}


Measured memory_bytes: 4096