akhauriyash/Code-Regression huggingface dataset:
n, a, b, c = map(int, input().split())
ll = [int(input()) for _ in range(n)]

def dfs(cnt, x, y, z):
    if cnt == n:
        if x == 0 or y == 0 or z == 0:
            return float('INF')
        return abs(a - x) + abs(b - y) + abs(c - z) - 30
    r0 = dfs(cnt + 1, x, y, z)
    r1 = dfs(cnt + 1, x + ll[cnt], y, z) + 10
    r2 = dfs(cnt + 1, x, y + ll[cnt], z) + 10
    r3 = dfs(cnt + 1, x, y, z + ll[cnt]) + 10
    return min(r0, r1, r2, r3)

print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ) {
    if ( L[i].value <= R[j].value ) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  int mid;
  if ( left + 1 < right ) {
    mid = ( left + right ) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ ) {
    if ( A[j].value <= x.value ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  }
  t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
  return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if ( p < r ) {
    q = partition(A, n, p, r);
    quickSort(A, n, p, q - 1);
    quickSort(A, n, q + 1, r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n - 1);

  for ( i = 0; i < n; i++ ) {
    if ( A[i].suit != B[i].suit ) stable = 0;
  }

  if ( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ ) {
    printf("%c %d\n", B[i].suit, B[i].value);
  }

  return 0;
}

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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  int N;
  string S;

  CIN(N >> S);

  if (N % 2 == 1) {
    COUT("No");
    return 0;
  }

  for (int i = 0; i < N / 2; i++) {
    if (S[i] != S[i + N / 2]) {
      COUT("No");
      return 0;
    }
  }
  COUT("Yes");

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  int N,L;cin>>N>>L;
  vector<int> l(N),r(N);
  for(int i=0;i<N;i++)cin>>l[i]>>r[i];
  map<int,int> m;
  for(int i=0;i<N;i++){
    m[l[i]]=0;
    m[r[i]]=0;
  }
  int cnt=0;
  for(auto &p:m)p.second=cnt++;
  for(int i=0;i<N;i++){
    l[i]=m[l[i]];
    r[i]=m[r[i]];
  }
  int ans=0;
  vector<int> d(500000,-1);
  for(int i=0;i<N;i++)d[l[i]]=max(d[l[i]],r[i]);
  int now=0;int mx=0;cnt--;
  for(int i=0;i<cnt;i++){
    if(now>i){
      mx=max(mx,d[i]);
      continue;
    }
   
    ans++;
    now=max(d[i],mx);
    //cout<<i<<" "<<ans<<" "<<now<<endl;
  }
  cout<<ans<<" ";
  vector<int> imos(cnt+10,0);
  for(int i=0;i<N;i++){
    imos[l[i]]++;
    imos[r[i]]--;
  }
  for(int i=1;i<cnt;i++)imos[i]+=imos[i-1];
  ans=100000000000000;
  for(int i=0;i<cnt;i++)ans=min(ans,imos[i]);
  cout<<N-ans+1<<endl;
  return 0;
}



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

int main(){
  ll n, v;
  cin >> n >> v;
  ll a[n], b[n], c[n], d[n];
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  rep(i,n) cin >> c[i];
  rep(i,n) cin >> d[i];
  map<ll,ll> mab, mcd;
  rep(i,n) rep(j,n) mab[a[i]+b[j]]++;  
  rep(i,n) rep(j,n) mcd[c[i]+d[j]]++; 
  ll ans = 0;
  for(auto x : mab) ans += x.second*mcd[v-x.first];
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 190576
x,n = map(int, input().split())
p = list(map(int, input().split()))

if x not in p:
    print(x)
else:
    for i in range(100):
        Ans1 = x - i
        Ans2 = x + i
        if Ans1 not in p:
            print(Ans1)
            break
        if Ans2 not in p:
            print(Ans2)
            break

Measured memory_bytes: 9180
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

// dist[i][j] := i ?????????????????°??????????????? j ??§????????¨???????????????????°????
int dist[110][110];
int N, M, L, K, A, H;
bool cool[110];

struct Elem {
    int point, fresh, cost;
};

bool operator<(const Elem &a, const Elem &b) {
    return a.cost > b.cost;
}

signed main() {
    while(cin >> N >> M >> L >> K >> A >> H, N) {
        memset(cool, false, sizeof(cool));
        rep(i,0,110) rep(j,0,110) dist[i][j] = INF;
        dist[A][M] = 0;

        rep(i,0,L) {
            int p; cin >> p;
            cool[p] = true;
        }

        vector< vector<pii> > G(N);
        rep(i,0,K) {
            int x, y, t; cin >> x >> y >> t;
            G[x].push_back(pii(y, t));
            G[y].push_back(pii(x, t));
        }

        priority_queue<Elem> q;
        q.push(Elem{A, M, 0});
        while(!q.empty()) {
            Elem t = q.top(); q.pop();
            int p = t.point, f = t.fresh, c = dist[p][f];
            for(auto to : G[p]) {
                int nxt = to.first, ecost = to.second;
                if(cool[p]) {
                    repq(i,0,M) {
                        int tm = -1;
                        if(i + ecost <= M) tm = i - f + 2 * ecost;
                        else continue;
                        if(tm < ecost) continue;
                        if(dist[nxt][i] > c + tm) {
                            dist[nxt][i] = c + tm;
                            q.push(Elem{nxt, i, c+tm});
                        }
                    }
                }
                else {
                    if(f - ecost < 0) continue;
                    if(dist[nxt][f-ecost] > c + ecost) {
                        dist[nxt][f-ecost] = c + ecost;
                        q.push(Elem{nxt, f-ecost, c + ecost});
                    }
                }
            }
        }

        int ans = INF;
        repq(i,0,M) chmin(ans, dist[H][i]);
        if(ans >= INF) cout << "Help!" << endl;
        else cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
 
int frog(int *a,int i, int n, int *dp){
    if(i>=n-1){
        return 0;
    }
    if(dp[i]!=-1) return dp[i];
 
    int op1=frog(a,i+1,n,dp) + abs(a[i]-a[i+1]);
    int op2=frog(a,i+2,n,dp) + abs(a[i]-a[i+2]);
 
    dp[i] = min(op1,op2);
    return dp[i];
}
 
int main() {
    int n;cin>>n;
    int a[n]={0};
    for(int i=0;i<n;i++) cin>>a[i];
    int dp[n]={0};
    memset(dp, -1, sizeof(dp));
    // for(int i=0;i<n;i++) cout<<a[i]<<" ";
    cout<<frog(a,0,n,dp)<<endl;
    // for(int i=0;i<n;i++) cout<<dp[i]<<" ";
}
 

Measured memory_bytes: 8960
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

//前提:解は必ず存在する
int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }

  int M;
  cin >> M;
  int P[M], X[M];

  for (int i = 0; i < M; i++) {
    cin >> P[i] >> X[i];
  }

  //答え格納
  vector<int> answer(M, 0);

  for (int i = 0; i < M; i++) {
    for (int j = 0; j < N; j++) {
      if (j + 1 == P[i])
        answer[i] += X[i];
      else
        answer[i] += T[j];
    }
    cout << answer[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp33 {
    class Program {
        static void Main(string[] args) {
            var X = Console.ReadLine().Split(' ').ToArray();
            string A = X[0];
            string B = X[1];
            string C = X[2];

            //各文字列の長さ
            int len_A = X[0].Length;
            int len_B = X[1].Length;
            int len_C = X[2].Length;

            if (A[len_A - 1] == B[0] && B[len_B - 1] == C[0]) {
                Console.WriteLine("YES");
            } else {
                Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 13268
def main():
  S=int(input())
  a=S//100
  b=S%100
  if 1<=a<=12 and 1<=b<=12:
    print("AMBIGUOUS ")
  elif 1<=a<=12 and (b==0 or 13<=b<=99):
    print("MMYY")
  elif 1<=b<=12 and (a==0 or 13<=a<=99):
    print("YYMM")
  else:
    print("NA")
main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
 int A,B,C,D;
 cin >> A >> B >> C >> D;
  if(A + B > C + D){
  cout << "Left" << endl;}
  if(A + B == C + D){
  cout << " Balanced" << endl;}
  else if(A + B < C + D){
  cout <<"Right"<< endl;}
}


Measured memory_bytes: 256
N = int(input())
A1 = {}
for i in range(N):
  s = input()
  if s in A1:
    A1[s] += 1
  else:
    A1[s] = 1
sai = max(A1.values())
for j in sorted(k for k in A1 if A1[k] == sai):
  print(j)
  

  

Measured memory_bytes: 35284
import sys
input = sys.stdin.readline
from collections import Counter

n = int(input())
A = sorted(map(int, input().split()), reverse=True)
C = Counter(A)
ans = 0
for a in A:
  if not C[a]:
    continue
  r = (1<<a.bit_length()) - a
  if r != a:
    if r in C and C[r] > 0:
      ans += 1
      C[r] -= 1
  else:
    if C[r] >= 2:
      ans += 1
      C[r] -= 1
  C[a] -= 1
print(ans)

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

lint nb[51],np[51];

lint solve(int n,lint x){
	if(n==0) return 1;

	if(x<=1)
		return 0;
	else if(x<=1+nb[n-1]+np[n-1])
		return solve(n-1,x-1);
	else if(x<=1+nb[n-1]+np[n-1]+1)
		return np[n-1]+1;
	else if(x<=1+nb[n-1]+np[n-1]+1+nb[n-1]+np[n-1])
		return solve(n-1,x-(1+nb[n-1]+np[n-1]+1))+1+np[n-1];
	else
		return np[n];
}

int main(){
	np[0]=1;
	rep(i,50) nb[i+1]=1+nb[i]+nb[i]+1, np[i+1]=np[i]+1+np[i];

	int n;
	lint x; cin>>n>>x;
	cout<<solve(n,x)<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());

        int d[] = new int[n];
        for(int i = 0; i < n; i++){
            d[i] = Integer.parseInt(sc.next());
        }

        int num[] = new int [101];
        for(int i = 0; i < n; i++){
            num[d[i]]++;
        }

        int cnt = 0;
        for (int i = 0; i < 101; i++) {
            if(num[i] > 0){
                cnt++;
            }
        }

        System.out.println(cnt);
    }
}

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

using namespace std;

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

void solve()
{
	vector<int> primes(1, 2);
	for(int i = 3; i < 100; i += 2)
	{
		bool check = true;
		for(auto&& j : primes)
		{
			if (i % j == 0) {
				check = false;
				break;
			}
		}
		if(check)
		{
			primes.push_back(i);
		}
	}
	int n, ans = 0;
	cin >> n;
	map<int, int> m;
	for(int i = 2; i <= n; i++)
	{
		int k = i;
		for(auto j : primes)
		{
			if (k == 1) break;
			while(k % j == 0)
			{
				m[j]++;
				k /= j;
			}
		}
	}
	int over25 = 0, over5 = 0, over3 = 0, over15 = 0;
	for(auto&& i : m)
	{
		if (i.second >= 74) ans++;
		if (i.second >= 24) over25++;
		if (i.second >= 14) over15++;
		if (i.second >= 4) over5++;
		if (i.second >= 2) over3++;
	}
	ans += over25 * (over3 - 1);
	ans += over15 * (over5 - 1);
	ans += over5 * (over5 - 1) / 2 * (over3 - 2);
	cout << ans << "\n";

}

int main()
{
	solve();
}


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

using namespace std;
using ll = long long;

int main() {

	string s;
	cin>>s;
	int N = s.length();
	string t1 = s.substr(0, (N-1)/2);
	string t2 = s.substr((N+3)/2 - 1, (N - (N+3)/2) + 1);
	//cout<<t1<<" "<<t2<<endl;

	function<bool(string)> ispal = [&] (string t) {
		for (int i = 0, j = t.length() - 1;i < j;++i, --j) {
			if (t[i] != t[j]) {
				return false;
			}
		}

		return true;
	};

	if (ispal(s) && ispal(t1) && ispal(t2)) {
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}

	return 0;
}


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

int main()
{
	int a,s1,s2,s3;
	cin >> a;

	s3 = a % 10;
	s2 = (a - s3) % 100 * 0.1;
	s1 = (a - s2 * 10 - s3) * 0.01;
	cout << (s1+s2+s3) ;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void insertionSort(int A[], int N) {
    int v, j;

    for (int i = 0; i < N; i++) {
        if (i) {
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;

    for (int i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;

        }
        A[j + 1] = v;
        for (int i = 0; i < N; i++) {
            if (i) {
                cout << " ";
            }
            cout << A[i];
        }
        cout << endl;
    }


}

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

    insertionSort(A, N);
}

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

vector<int>adj_list[1000005];
vector<int>flag(1000005,-1);
vector<int>arr;

void DFS(int v,vector<int>&flag,int* kitna)
{
    *kitna=*kitna+1;
    flag[v]=1;
    for(auto p : adj_list[v])
    {
        if(flag[p]==-1)
        DFS(p,flag,kitna);
    }
}

int main() 
{
    int t=1;
    while(t--)
    {
        int n;cin>>n;
        int k;cin>>k;
        while(k--)
        {
            int u;int v;cin>>u>>v;
            adj_list[u].push_back(v);
            adj_list[v].push_back(u);
        }
        int count=0;
        for(int v=0;v<n;v++)
        {
            if(flag[v]==-1)
            {
                int kitna=0;
            DFS(v,flag,&kitna);
            arr.push_back(kitna);
            count++;
            }
        }
        int ans=*max_element(arr.begin(),arr.end());
        cout<<ans<<endl;
    }
	return 0;
}


Measured memory_bytes: 46188
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    /*ll N;
     cin>>N;
     
     vll A(N+1);
     for(ll i=0;i<=N;i++)cin>>A[i];
     if(N==0){
     if(A[0]==1){
     cout<<1<<endl;
     return 0;
     }else {
     cout<<-1<<endl;
     return 0;
     }
     }
     if(A[0]!=0){
     cout<<-1<<endl;
     return 0;
     }
     
     
     vll B(N+1);
     for(ll i=0;i<=N;i++){
     if(i==0){
     B[0]=1;
     }else{
     B[i]=(B[i-1]-A[i-1])*2;
     if(B[i]<A[i]){
     cout<<-1<<endl;
     return 0;
     }
     }
     }
     
     vll C(N+1);
     for(ll i=N;i>=0;i--){
     if(i==N){
     C[i]=A[i];
     }else{
     C[i]=C[i+1]+A[i];
     }
     }
     
     ll ans=0;
     for(ll i=0;i<=N;i++){ans+=min(B[i],C[i]);
     }
     cout<<ans<<endl;
     
     return 0;
     }
     
     int main() {*/
    //ll n,a[100005]={0},b[100005],c[100005],pv,ans=0;
    ll n,pv;
    
    //vll a(100005),b(100005),c(100005);
    bool ok=false;
    cin >> n;
    vll a(n+2),b(n+2),c(n+2);
    for(ll i=0;i<=n;i++){
        cin >> a[i];
    }
    for(ll i=0;i<=n;i++){
        if(i==0){
            if(a[i]>1){
                cout << -1 << endl;
                return 0;
            }
            b[0]=1;
        } else {
            if(ok) b[i]=2*1e17;
            else b[i]=(b[i-1]-a[i-1])*2;
            if(b[i]>=1e17) ok=true;
            if(a[i]>b[i]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    b[n+1]=1;
    for(ll i=n;i>=0;i--){
        if(i==n){
            c[i]=a[i];
        } else {
            c[i]=c[i+1]+a[i];
        }
    }
    c[n+1]=0;
    for(ll i=0;i<=n+1;i++){
        if(b[i]>c[i]){
            pv=i;
            break;
        }
    }
    ll ans=0;
    for(ll i=0;i<=n;i++){
        if(i<pv){
            ans+=b[i];
        } else {
            ans+=c[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5556
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(vi) (vi.begin(),vi.end())
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}

int main() {
    int n,x;
    int t1=0,t2=0,t3=0;
    si(n);
    
    for(int i=0;i<n;i++){
        si(x);
        
        if(x%2==1) t1++;
        else if(x%2==0 && x%4!=0) t2++;
        else if(x%4==0) t3++;
    }
    
    if(t2==0){
        if(t1-t3<=1) cout<<"Yes\n";
        else cout<<"No\n";
    }
    else{
        if(t1<=t3) cout<<"Yes\n";
        else cout<<"No\n";
    }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int h, w ;
  cin >> h >> w ;
  while( h != 0 ) {
    int i, n ;
    for( i=0 ; i<h ; i++ ) {
      for( n=0 ; n<w ; n++ ) {
    cout << "#" ;
      }
      cout << endl ;
    }
    cout << endl;
    cin >> h >> w ;
  }
  return 0 ;
}


Measured memory_bytes: 3096
#include <stdio.h>
#include <algorithm>

int N;
char S[112];
int x, ans;

int main(void)
{
	scanf("%d%s", &N, &S);
	
	for (int i = 0; i < N; ++i)
	{
		if (S[i] == 'I')
		{
			++x;
		}
		if (S[i] == 'D')
		{
			--x;
		}
		ans = std::max(ans, x);
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    //-------------------------------------------------------------//
    public static final void main(String[] args) {
        new Main().solve();
    }
    //-------------------------------------------------------------//
    private final Scanner sc = new Scanner(System.in);

    void solve() {
        int N = sc.nextInt();
        PriorityQueue<Long> left = new PriorityQueue<>();
        PriorityQueue<Long> right = new PriorityQueue<>(Comparator.reverseOrder());
        long[] center = new long[N];

        long sumLeft = 0;
        for (int i = 0; i < N; i++) {
            long x = sc.nextLong();
            left.add(x);
            sumLeft += x;
        }

        for (int i = 0; i < N; i++) {
            center[i] = sc.nextLong();
        }

        long sumRight = 0;
        for (int i = 0; i < N; i++) {
            long x = sc.nextLong();
            right.add(x);
            sumRight += x;
        }

        long[] max = new long[N + 1];
        max[0] = sumLeft;
        for (int i = 0; i < N; i++) {
            sumLeft += center[i];
            left.add(center[i]);
            sumLeft -= left.poll();
            max[i + 1] = sumLeft;
        }

        long[] min = new long[N + 1];
        min[N] = sumRight;
        for (int i = N - 1; i >= 0; i--) {
            sumRight += center[i];
            right.add(center[i]);
            sumRight -= right.poll();
            min[i] = sumRight;
        }

        long ans = -Long.MAX_VALUE;
        for (int i = 0; i <= N; i++) {
            ans = Math.max(ans, max[i] - min[i]);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 103000
#include <stdio.h>
int main(){
  double N;
  double ans;
  
  
  scanf("%lf",&N);
  
  for(int i=1;i<=N;i++){
    if(N==1){
        ans = N;
        printf("%f",ans);
        break;
    }else if(N==2*i){
       ans = (N/2)/N;
       printf("%f",ans);
       break;
     }else if(N == 2*i+1){
       ans = (((N/2)-0.5)+1)/N;
       printf("%f",ans);
       break;
    }
  }
  return 0;
}
  

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
string itos(int x){
  string r;
  while(x){
    r+=x%10+'0';
    x/=10;
  }
  reverse(r.begin(),r.end());
  return r;
}
 
int main(){
  int n,cnt;
  string s;
  cin>>n;
  while(n--){
    cin>>s;
    cnt=0;
    for(int i=0;i<s.size()-1;i++){
      int cal=s[i]-'0'+s[i+1]-'0';
      string sub=s.substr(i+2,s.size()-i);
      string ts=itos(cal);
      s=ts+sub;
      cnt++;
      if(s.size()==1)break;
      i=-1;
    }
    if(cnt%2)cout<<"Fabre wins."<<endl;
    else cout<<"Audrey wins."<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long LL;

int main()
{
    string s,t;
    LL k;
    while(cin>>s>>k){
        if(s.size()==1){
            cout<<s[0]<<endl;
        }
        else{
            LL sum=0;
            for(int i=0;i<s.size();i++){
                if(s[i]=='1') sum++;
                else break;
            }
            if(k<=sum) cout<<s[0]<<endl;
            else cout<<s[sum]<<endl;
        }
    }
    return 0;
}


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

int main(){
    int N,A,B;
    int result=0;
    cin >> N >> A >> B;
    rip(a,10){
        rip(b,10){
            rip(c,10){
                rip(d,10){
                    rip(e,10){
                        int number=a*10000 + b*1000 + c*100 + d*10 + e*1;
                        if((number<=N)&&(number>=1)){
                            int num=a+b+c+d+e;
                            if((num>=A)&&(num<=B)){
                                result+=number;
                            }
                        }
                    }
                }
            }
        }
    }
    cout << result << endl;
    return 0;
}



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

const int MAX = 100005;

int main() {
	int n;
	cin >> n;
	vector<ll> cnt(MAX, 0);
	long long sum = 0;
	rep(i, n) {
		int a;
		cin >> a;
		cnt[a] ++;
	}
	rep(i, MAX) sum += i * cnt[i];

	int q;
	cin >> q;
	rep(i, q) {
		int b, c;
		cin >> b >> c;
		sum += (c - b) * cnt[b];
		cnt[c] += cnt[b];
		cnt[b] = 0;
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 4056
a=gets.chomp.split("").map(&:to_s)
b=gets.chomp.split("").map(&:to_s)
c=gets.chomp.split("").map(&:to_s)

v=a.shift
while v!=nil
    if v=="a"
        v=a.shift
        if v.nil?
            puts"A"
        exit
        end
    elsif v=="b"
    v=b.shift
    if v.nil?
        puts"B"
    exit
    end
    else
    v=c.shift
    if v.nil?
        puts"C"
    exit
    end
    end
   
  
  
end

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

using namespace std;

vector<bool> vis(200006,false);

int count1;

void dfs(int v,vector<vector<int> > &adj){
	count1++;
	vis[v]=true;
	for(auto u:adj[v]){
		if(vis[u]==false){
			dfs(u,adj);
		}
	}
}

int main(){
	int n,m;
	cin>>n>>m;
	vector<vector<int> > adj(n+1);
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(vis[i]==false){
			count1=0;
			dfs(i,adj);
			ans=max(ans,count1);
		}
	}
	cout<<ans<<endl;
}

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

ll dp[3030][3030];

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i, n) cin >> A[i];
    if(n % 2 == 0){
        rep(i, n) dp[i][i] = -A[i];
        rep(w, n) {
            if (w == 0) continue;
            rep(i, n - w) {
                if(w % 2 == 1) dp[i][i + w] = max(dp[i][i + w - 1] + A[i + w], dp[i + 1][i + w] + A[i]);
                else dp[i][i + w] = min(dp[i][i + w - 1] - A[i + w], dp[i + 1][i + w] - A[i]);
            }
        }
    }
    else {
        rep(i, n) dp[i][i] = A[i];
        rep(w, n) {
            if (w == 0) continue;
            rep(i, n - w) {
                if(w % 2 == 0) dp[i][i + w] = max(dp[i][i + w - 1] + A[i + w], dp[i + 1][i + w] + A[i]);
                else dp[i][i + w] = min(dp[i][i + w - 1] - A[i + w], dp[i + 1][i + w] - A[i]);
            }
        }
    }
    cout << dp[0][n - 1] << endl;
    return 0;
}

Measured memory_bytes: 71936
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

n,x,m = mp()
u = [0]*m
kaime = [0]*m
a = [x%m]
u[x%m] += 1
kaime[x%m] = 1
t = 0
for i in range(2, n+1):
    x = x**2 % m
    if u[x] == 1:
        t = x
        break
    else:
        u[x] += 1
        a.append(x)
        kaime[x] = i
if n == len(a):
    print(sum(a))
else:
    loop_array = a[kaime[t]-1:]
    loop = (n-kaime[t]+1)//len(loop_array)
    amari = (n-kaime[t]+1)%len(loop_array)
    print(sum(a[:kaime[t]-1])+ loop*sum(loop_array)+sum(loop_array[:amari]))

#sum(sa[:n%len(a)])



Measured memory_bytes: 70484
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let n:i64 = read();
    let m:i64 = read();
    let x:i64 = read();
    let a:Vec<i64> = (0..m).map(|_| read()).collect();

    println!("{}", min(a.iter().filter(|&b| *b<x).count(), a.iter().filter(|&b| *b>x).count()));

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

class union_find {
private:
    vector<ll> par;
    vector<ll> ran;
    vector<ll> m_size;
public:
    union_find(ll n);
    ll find(ll x);
    void unite(ll x, ll y);
    bool same(ll x, ll y);
    ll size(ll x);
};

union_find::union_find(ll n){
    par.resize(n);
    ran.resize(n, 0);
    m_size.resize(n, 1);
    rep(i,n) par[i] = i;
};

ll union_find::find(ll x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    ll t = size(x)+size(y);
    m_size[x] = m_size[y] = t;
    if (ran[x] < ran[y]) {
        par[x] = y;
        //size[y] += size[x];
    } else {
        par[y] = x;
        //ize[x] += size[y];
        if (ran[x]==ran[y]) ran[x]++;
    }
};

ll union_find::size(ll x) {
    if (par[x] == x) return m_size[x];
    return size(par[x] = find(par[x]));
}

bool union_find::same(ll x, ll y) {
    return (find(x) == find(y));
};

constexpr int M = 114514;

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<P> a(n);
    union_find uf(M*2);
    map<ll,ll> mx, my;
    ll res = 0;

    rep(i,n) {
        cin>>a[i].first>>a[i].second;
        uf.unite(a[i].first,a[i].second+M);
    }

    rep(i,M) {
        mx[uf.find(i)]++;
    }
    for (int i = M; i < M*2; ++i) {
        my[uf.find(i)]++;
    }

    rep(i,M*2) {
        res += mx[i]*my[i];
    }

    cout << res-n << '\n';
    return 0;
}

Measured memory_bytes: 35840
program Sum_of_Large_Numbers;
const
  m: int64 = 1000000007;
  h: int64 = 500000004;
  s: int64 = 166666668;
var
  n, k: int64;
function f(i: int64): int64;
begin
  f := i*(((n+1)*(h*(i+1) mod m)-(s*((i+1)*(i*2+1) mod m) mod m)+1) mod m);
end;
begin
  read(n, k);
  writeln((m+(f(n+1)-f(k-1)) mod m) mod m);
end.

Measured memory_bytes: 1388
def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 100**6
	for i in range(-100, 101):
		tmp = 0
		for j in a:
			if i == j:
				continue
			tmp += (j - i)**2
		if tmp < ans:
			ans = tmp
	print(ans)
resolve()

Measured memory_bytes: 38768
fun main(args: Array<String>) {
    val n = readLine()?.split(" ")?.get(0)?.toInt() ?: 0
    val x = Array(n) {
        it to (readLine()?.split(" ")?.map(String::toInt) ?: listOf())
    }.toList()
    println(
        x.map { xi ->
            x.filter { xi.first < it.first }
                .map {
                    getDist(xi.second, it.second)
                }
        }.flatten()
            .count {
                it.toInt().toDouble() == it
            }
    )
}

fun getDist(a: List<Int>, b: List<Int>): Double {
    val pairs = a.zip(b)
    return Math.sqrt(
        pairs.fold(0) { r, t ->
            val tmp = (t.first - t.second)
            r + tmp * tmp
        }.toDouble()
    )
}

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 110, M = 6, mod = 1e9 + 7;

int n;
int f[N][M][M][M];

int main()
{
	cin >> n;
	
	f[0][0][0][0] = 1;
	for (int i = 0; i < n; i ++ )
		for (int x = 0; x <= 4; x ++ )
			for (int y = 0; y <= 4; y ++ )
				for (int z = 0; z <= 4; z ++ )
					for (int j = 1; j <= 4; j ++ )
					{
						if (y == 1 && z == 2 && j == 3) continue;
						if (y == 1 && z == 3 && j == 2) continue;
						if (y == 2 && z == 1 && j == 3) continue;
						if (x == 1 && z == 2 && j == 3) continue;
						if (x == 1 && y == 2 && j == 3) continue;
						f[i + 1][y][z][j] = (f[i + 1][y][z][j] + f[i][x][y][z]) % mod;
					}
	
	int res = 0;
	for (int x = 1; x <= 4; x ++ )
		for (int y = 1; y <= 4; y ++ )
			for (int z = 1; z <= 4; z ++ )
				res = (res + f[n][x][y][z]) % mod;
	cout << res << endl;
	return 0;
}

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

int main(void){
   int H,W;
   while(true) {
       cin >> H >> W;
       if (H == 0 && W == 0) {
           break;
       }
       for(int j = 0; j < W; j++){
           cout << '#';
       }
       cout << endl;
       for(int i = 1; i < H-1; i++){
            cout << '#';
            for(int j = 1; j < W-1; j++){
                cout << '.';
            }
            cout << '#' << endl;
       }
       for(int j = 0; j < W; j++){
           cout << '#';
       }
       cout << endl << endl;
   }
}


Measured memory_bytes: 3084
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc  = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int h = Integer.parseInt(sc.next());
    int[][] damage = new int[n][2];
    
    for(int i=0;i<n;i++){
      damage[i][0] = Integer.parseInt(sc.next());
      damage[i][1] = Integer.parseInt(sc.next());
    }
    Arrays.sort(damage,new Comparator<int[]>(){
      @Override
      public int compare(int[] o1,int[] o2){
        return o2[1]-o1[1];
      }
    });
   	int maxa = 0;
    int idx = 0;
    for(int i=0;i<n;i++){
      if(damage[i][0] >= maxa){
        maxa = damage[i][0];
        idx = i;
      }
    }
    int count = 0;
    for(int i=0;i<n;i++){
      if(damage[i][1] > maxa && i!=idx){
        h-=damage[i][1];
        count++;
      }
      if(h <= 0){
        break;
      }
    }
    if(h <= 0){
      System.out.println(count);
    }else if(h<=damage[idx][1]){
      System.out.println(count + 1);
    }else{
      
      System.out.println(count + 1 + (h-damage[idx][1]+maxa-1)/maxa);
    }
  }
}

Measured memory_bytes: 62396
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization_level 3
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(){
	double l;
	cin>>l;

	l /= 3;
	l=l*l*l;
	// cout<<l;
	printf("%.12f",l);
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
int n, q, com, x, y; int group[10000]; vector<int> f[10000];
int main() {
	scanf("%d%d", &n, &q);
	for(int i = 0; i < n; i++) group[i] = i, f[i].push_back(i);
	for(int i = 0; i < q; i++) {
		scanf("%d%d%d", &com, &x, &y);
		if(com == 0) {
			if(group[x] == group[y]) continue;
			x = group[x], y = group[y];
			if(f[x].size() > f[y].size()) {
				for(int j = f[y].size() - 1; j >= 0; j--) {
					group[f[y][j]] = group[x];
					f[x].push_back(f[y][j]);
					f[y].pop_back();
				}
			}
			else {
				for(int j = f[x].size() - 1; j >= 0; j--) {
					group[f[x][j]] = group[y];
					f[y].push_back(f[x][j]);
					f[x].pop_back();
				}
			}
		}
		else {
			printf("%d\n", (group[x] == group[y] ? 1 : 0));
		}
	}
	return 0;
}

Measured memory_bytes: 3976
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]
    
    a, b, x = (int(_) for _ in input().split())
    a_d = a//x
    b_d = b//x
    ans = b_d - a_d
    if(a%x == 0):
        ans += 1
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  char *s = (char *) calloc (n + 1, sizeof (char));
  scanf ("%s", s);
  i32 q;
  scanf ("%" SCNi32, &q);
  while (q--) {
    i32 k;
    scanf ("%" SCNi32, &k);
    i64 ans = 0;
    i32 cntD = 0;
    i32 cntM = 0;
    i64 cntDM = 0;
    for (i32 i = 0; i < k; ++i) {
      if (s[i] == 'D') {
	cntD++;
      } else if (s[i] == 'M') {
	cntM++;
	cntDM += cntD;
      } else if (s[i] == 'C') {
	ans += cntDM;
      }
    }
    for (i32 i = k; i < n; ++i) {
      if (s[i - k] == 'D') {
	cntDM -= cntM;
	cntD--;
      } else if (s[i - k] == 'M') {
	cntM--;
      }
      if (s[i] == 'D') {
	cntD++;
      } else if (s[i] == 'M') {
	cntM++;
	cntDM += cntD;
      } else if (s[i] == 'C') {
	ans += cntDM;
      }
    }
    printf("%" PRIi64 "\n", ans);
  }
}

int main (void) {
  run ();
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
    int n,m;cin >>n>>m;
    VV g(n);
    for (int i = 0; i < m; ++i) {
        int a,b;cin >>a>>b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<bool>used(n,false);
    queue<int>que;
    ll ans=-1;
    for (int i = 0; i <n; ++i) {
        if(used[i])continue;
        que.push(i);
        used[i]=true;
        ll now=0;
        while(que.size()){
            int t=que.front();que.pop();
            used[t]=true;
            now++;
            for(auto e:g[t]) {
                if (used[e])continue;
                que.push(e);
                used[e]=true;
            }
        }
        ans=max(ans,now);
    }
    cout <<ans <<endl;
}


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

int main()
{
  int n;
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;

    int x = n/2, y = n/2+1;
    vector<vector<int > > ms(n, vector<int>(n, -1));
    for (int i = 1; i <= n*n; ++i) {
      while (x < 0 || x >= n || y >= n || ms[y][x] != -1) {
	if (x < 0)
	  x = n-1;
	if (x >= n)
	  x = 0;
	if (y >= n)
	  y = 0;

	if (ms[y][x] != -1) {
	  x -= 1;
	  y += 1;
	}
      }
      ms[y][x] = i;
      x += 1;
      y += 1;
    }

    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
	printf("%4d", ms[i][j]);
      }
      puts("");
    }
  }
  return 0;
}

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

typedef long long ll;
typedef int64_t i6;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define repb(i, l, n) for (int64_t i = l; i < n; ++i)
#define repb2(i, l, n) for (int64_t i = l; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define Push_back(p, a, b) (p).push_back( make_pair( (a), (b) ) )

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;  }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }

int main() {
    int64_t n, m, k;
    cin >> n >> m >> k;
    int64_t ans = n/m;
    if (n%m != 0) ans++;
    cout << ans*k << endl;
    return 0;
}


Measured memory_bytes: 3420
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;
typedef long long int lli;

int A, B;
string S;
int main() {
	cin >> A >> B >> S;
	bool ad = true;
	rep(i, A)
		if (S[i] == '-') ad = false;
	if (S[A] != '-') ad = false;
	rep(i, B)
		if (S[i + A + 1] == '-') ad = false;
	if (ad) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n;
bool valid = true;
pair < int, pii > point[100100];
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;i++){
        int t,xi,yi;
        cin>>t>>xi>>yi;
        point[i] = mp(t , mp(xi,yi) );
    }
    point[0] = mp(0, mp(0,0));
    sort(point+1,point+1+n);
    for(int i=1;i<=n;i++){
        int time = point[i].fi - point[i-1].fi;
        int m = abs(point[i].sf - point[i-1].sf) + abs(point[i].ss - point[i-1].ss);
        if(m>time){valid=false;break;}
        else{
            int temp = time - m;
            if(temp%2==1){valid=false;break;}
        }
    }
    if(valid)cout<<"Yes\n";
    else cout<<"No\n";

}


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

t = a[0]
ans = 0
r = 1

for l in range(n):
  while r<n and t^a[r] == t+a[r]:
    t+=a[r]
    r+=1
  if r==l:
    l=r+1
  ans += r-l
  t -= a[l]

print(ans)

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

int W, H;
int M[110][110];
bool visited[110][110];

int f(int x, int y) {
  if (x > W+1 || y > H+1 || x < 0 || y < 0) return 0;
  if (visited[y][x]) return 0;
  if (M[y][x] == 1) return 1;
  visited[y][x] = true;
  int ret = 0;
  ret += f(x-1, y);
  ret += f(x+1, y);
  if (y % 2 == 0) {
    ret += f(x-1, y-1);
    ret += f(x,   y-1);
    ret += f(x-1, y+1);
    ret += f(x,   y+1);
  }
  else {
    ret += f(x,   y-1);
    ret += f(x+1, y-1);
    ret += f(x,   y+1);
    ret += f(x+1, y+1);
  }
  return ret;
}

int main() {
  cin >> W >> H;
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      cin >> M[i+1][j+1];
    }
  }
  int ans = 0;
  for (int i=0; i<=W+1; i++) {
    ans += f(i,   0);
    ans += f(i, H+1);
  }
  for (int i=0; i<=H+1; i++) {
    ans += f(0,   i);
    ans += f(W+1, i);
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3408
//ABC059B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	string a, b;
	cin >> a >> b;
	if(a.size() > b.size()){
		cout << "GREATER" << endl;
		return 0;
	}else if(a.size() < b.size()){
		cout << "LESS" << endl;
		return 0;
	}else{
		for(int i=0;i<a.size();i++){
			if(a.at(i) > b.at(i)){
				cout << "GREATER" << endl;
				return 0;
			}else if(a.at(i) < b.at(i)){
				cout << "LESS" << endl;
				return 0;
			}else{
				continue;
			}
		}
	}
	cout << "EQUAL" << endl;
	return 0;
}

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

int solve(vector<int> &vect,int n,vector<int> &dp){
	if(n==0) return 0;
    if(dp[n]!=-1) return dp[n];
  	int left = INT_MAX, right = INT_MAX;
    if(n>=1){
    	left = solve(vect,n-1,dp) + abs(vect[n] - vect[n-1]);
    }
    if(n>=2){
    	right = solve(vect,n-2,dp) + abs(vect[n] - vect[n-2]);
    }
    return dp[n] = min(left,right);
}

int main(){
	int n;
    cin>>n;
    vector<int> vect(n);
    vector<int> dp(n,-1);
    for(int i=0;i<n;i++) cin>>vect[i];
    cout<<solve(vect,n-1,dp);
    return 0;
}

Measured memory_bytes: 10384
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
char s[N];
int cnt[26];
int main() {
	scanf("%s", s);
	int n = (int) strlen(s);
	for (int i = 0; i < n; ++ i) cnt[s[i] - 'a'] ++;
	int tmp = *max_element(cnt, cnt + 26);
	if ((tmp - 1) * 3 > n - 1) puts("NO"); else puts("YES");
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		string s=Console.ReadLine();
		long[,] dp=new long[n,n+1];
		for(int i=1;i<=n;i++){dp[0,i]=i;}
		for(int i=1;i<n;i++){
			for(int j=1;j<=n-i;j++){
				if(s[i-1]=='<'){dp[i,j]=dp[i-1,j];}
				else{dp[i,j]=(mod+dp[i-1,n-i+1]-dp[i-1,j])%mod;}
				dp[i,j]=(dp[i,j]+dp[i,j-1])%mod;
			}
		}
		Console.WriteLine("{0}",dp[n-1,1]);
	}
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int r, g, b;
  cin >> r >> g >> b;
  int res = r * 100 + g * 10 + b;
  if (res % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
point = [0, 0]
current = 0
flag = False
for _ in range(N):
    t, x, y = map(int, input().split())
    tmp = abs(point[0]-x)+abs(point[1]-y)
    dif_time = t - current
    dif = dif_time - tmp
    if tmp > dif_time:
        flag = True
    elif tmp == dif_time:
        flag = False
    elif tmp % 2 == 0 and dif_time % 2:
        flag = True
    else:
        flag = False
    if flag:
        print("No")
        break
    point = [x, y]
    current = t
else:
    print("Yes")


Measured memory_bytes: 3188