akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,k;


int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    cin>>n>>k;
    n %= k;
    print(min(n,k-n));
    return 0;
}

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

using namespace std;
using ll = long long;

struct edge{
    int len;
    int to;
    edge(){}
    edge(int len,int to):len(len),to(to){}
};

int main() {
    using graph = vector<vector<edge>>;

    int n,m,k;
    cin>>n>>m>>k;

    graph G(n);
    for(int i = 0;i < m;++i) {
        int a,b,l;
        cin>>a>>b>>l;
        --a;--b;
        G[a].emplace_back(l,b);
        G[b].emplace_back(l,a);
    }

    priority_queue<pair<int,int>> pq;
    vector<int> mdist(n,300000000);

    for(int i = 0;i < k;++i) {
        int a;
        cin>>a;
        --a;
        pq.emplace(0,a);
        mdist[a]=0;
    }


    while(!pq.empty()) {
        auto t=pq.top();
        pq.pop();
        int tl=-t.first;
        int tv=t.second;

        for(auto px:G[tv]) {
            int ndist=tl+px.len;
            if(mdist[px.to]<ndist)continue;
            mdist[px.to]=ndist;
            pq.emplace(-ndist,px.to);
        }
    }

    int ld=0;
    for(int i = 0;i < n;++i) {
//cerr<<mdist[i]<<endl;
        ld=max(ld,mdist[i]);
    }

    for(int i = 0;i < n;++i) {
        for(auto e:G[i]) {
            //if(abs(mdist[i]-mdist[e.to])==e.len)continue;

            int a=mdist[i];
            int b=mdist[e.to];
            int l=e.len;

            if(a<b)swap(a,b);
            int td=b+l-a;
            td=(td+1)/2;
            ld=max(ld,td+a);
        }
    }
    cout<<ld<<endl;
    return 0;
}



Measured memory_bytes: 5948
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

  string s;
  cin >> s;

  if(s.length() != 26){
    for(char ch = 'a'; ch <= 'z'; ch++){
      bool contains = false;
      for(int i = 0; i < s.length(); i++){
        if(s[i] == ch){
          contains = true;
          break;
        }
      }
      if(!contains){
        s.push_back(ch);
        cout << s << endl;
        return 0;
      }
    }
  }
  else{
    for(int i = s.length() - 1; i >= 0; i--){
      for(char ch = 'a'; ch <= 'z'; ch++){
        bool contains = false;
        for(int j = 0; j <= i; j++){
          if(s[j] == ch){
            contains = true;
            break;
          }
        }
        if(!contains && s[i] < ch){
          string ans = s.substr(0, i);
          ans.push_back(ch);
          cout << ans << endl;
          return 0;
        }
      }
    }
  }

  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 256
num = int(input())
str_line = input().split(" ")
num_line = [int(n) for n in str_line]

ave = 0
for i in range(num):
    ave += num_line[i]

if ave%num == 0:
    ave //= num

else:
    if ave%num <= num/2:
        ave //= num
    else:
        ave = -(-ave//num)

wa = 0
for i in range(num):
    temp = num_line[i] - ave
    wa += temp*temp
    
print(wa)

Measured memory_bytes: 9200
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		char[] str = sc.next().toCharArray();
		
		int changed = 0;
		for(int i = 1; i < str.length; i++) {
			if(str[i] != str[i - 1]) {
				changed++;
			}
		}
		
		System.out.println(changed);
	}

}


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

int main()
{
    long long int n;
    cin>>n;
    long long int sum=0;
    long long int minn=0x3f3f3f3f;
    for(long long int i=0;i<n;i++)
    {
        long long int a,b;
        cin>>a>>b;
        sum+=a;
        if(a>b)
            minn=min(minn,b);
    }
    minn!=0x3f3f3f3f?cout<<sum-minn<<endl:cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
int main() {
	string s;
	cin >> s;
	int a = s[0] - '0';
	int b = s[1] - '0';
	int c = s[2] - '0';
	int d = s[3] - '0';
	if (a + b + c + d == 7)cout << a << "+" << b << "+" << c << "+" << d << "=" << 7 << endl;
	else if (a + b + c - d == 7)cout << a << "+" << b << "+" << c << "-" << d << "=" << 7 << endl;
	else if (a + b - c + d == 7)cout << a << "+" << b << "-" << c << "+" << d << "=" << 7 << endl;
	else if (a + b - c - d == 7)cout << a << "+" << b << "-" << c << "-" << d << "=" << 7 << endl;
	else if (a - b + c + d == 7)cout << a << "-" << b << "+" << c << "+" << d << "=" << 7 << endl;
	else if (a - b + c - d == 7)cout << a << "-" << b << "+" << c << "-" << d << "=" << 7 << endl;
	else if (a - b - c + d == 7)cout << a << "-" << b << "-" << c << "+" << d << "=" << 7 << endl;
	else if (a - b - c - d == 7)cout << a << "-" << b << "-" << c << "-" << d << "=" << 7 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN=100005;
const int INF=0x3f3f3f3f;
vector<int> e[MAXN];
int dis[MAXN],pre[MAXN];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        e[a].push_back(b);
        e[b].push_back(a);
    }
    for(int i=1;i<=n;i++)
        dis[i]=INF;
    queue<int> q;
    q.push(1);
    dis[1]=0;
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        for(auto &v:e[u])
            if(dis[v]>dis[u]+1)
            {
                dis[v]=dis[u]+1;
                pre[v]=u;
                q.push(v);
            }
    }
    for(int i=1;i<=n;i++)
        if(dis[i]==INF)
            return 0*printf("No\n");
    printf("Yes\n");
    for(int i=2;i<=n;i++)
        printf("%d\n",pre[i]);
    return 0;
}


Measured memory_bytes: 10968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int dijkstra(const vector<vector<int>> edge) {
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
  vector<int> dist(edge.size(),INF);
  dist[0] = 0;
  q.push(mp(0,0));
  while(!q.empty()) {
    auto p = q.top();
    q.pop();
    if(p.first > dist[p.second]) break;
    for(int i = 0;i < edge[p.second].size(); ++i){
      int to = edge[p.second][i];
      if(dist[to] > dist[p.second]+1) {
        dist[to] = dist[p.second]+1;
        q.push(mp(dist[to],to));
      }
    }
  }
  return dist[edge.size()-1];
}

int main(void) {
  int n;
  cin >> n;
  vector<int> ary(n);
  vector<int> jmp(n);
  vector<int> ok(n,0);
  REP(i,n)cin>>ary[i];
  REP(i,n) {
    if(ary[i] != 0) {
      if(ok[i] == 0) {
        set<int> s;
        s.insert(i);
        int j = i;
        bool f = true;
        while(f) {
          j += ary[j];
          f = false;
          switch(ok[j]) {
            case 0:
              if(s.find(j) != s.end()) {
                for(int k : s)
                  ok[k] = -1;
              } else if(ary[j] == 0) {
                jmp[j] = j;
                ok[j] = 1;
                for(int k : s) {
                  ok[k] = 1;
                  jmp[k] = j;
                }
              } else {
                s.insert(j);
                f = true;
              }
              break;
            case 1:
              for(int k : s) {
                ok[k] = 1;
                jmp[k] = jmp[j];
              }
              break;
            case -1:
              for(int k : s)
                ok[k] = -1;
              break;
          }
        }
      }
    } else {
      ok[i] = 1;
      jmp[i] = i;
    }
  }
  vector<vector<int>> edge(n);
  REP(i,n) {
    if(ok[i] >= 0) {
      FOR(j,1,7) {
        if(i+j>=n)
          edge[i].push_back(n-1);
        else if(ok[i+j] >= 0)
          edge[i].push_back(jmp[i+j]);
      }
    }
  }
  int l = dijkstra(edge);
  cout<<l<<endl;
  return 0;
}

Measured memory_bytes: 14988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int x, y, ans = 0;
    cin >> x >> y;
    
    ans = abs(abs(x) - abs(y));
    
    if (((x < 0) && (y < 0)) || ((x > 0) && (y > 0))) {
        if (x > y) {
            ans += 2;
        }
    }
    else if (((x < 0) && (y == 0)) || ((x == 0) && (y > 0))) {
        // nop
    }
    else {
        ans++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
 
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  1000000007
const int N = 100005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
bool is_pali(string s)
{
     ll n = s.size();
     for(ll i=0;i<s.size();i++)
     {
          if(s[i]!=s[n-i-1])   return 0;
     }
     return 1;
}
void solve()
{
     string s;   
     cin >> s;
     bool chk = is_pali(s);
     ll n = s.size();
     string t = "";
     for(ll i=0;i<(n-1)/2;i++)  t+=s[i];
     chk &= is_pali(t);
     string a = "";
     for(ll i=(n+3)/2-1;i<n;i++)   a+=s[i];
     chk &= is_pali(a);
     if(chk)    cout<<"Yes\n";
     else       cout<<"No\n";     
}

int main()
{
     FAST;
     ll t = 1;
   //  cin >> t;
     while(t--)
     {
          solve();
     }
}


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

int main(void){
	
	int r, g, b; cin >> r >> g >> b;
	if((100*r+10*g+b)%4==0){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  string S;
  cin>>S;

  int N=S.size();
  if(N%2) cout<<"No"<<endl;
  else{
    for(int i=0;i<N;i+=2){
      if(S[i]=='h'&&S[i+1]=='i');
      else{
        cout<<"No"<<endl;
        return 0;
      }
    }
    cout<<"Yes"<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <tuple> 
#include <memory>

using namespace std;

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

	unsigned long long num = 0;
	unsigned long long halfN = N / 2;	//エラトステネスの篩、因数分解

	if (K == 0) {
		num = (unsigned long long)N * N;
	}
	else {
		for (int b = K; b <= N; b++) {
			int x = N / b;
			num += x * (b - K);

			int y = N % b;
			num += max(y - K + 1, 0);
		}
	}

	cout << num;

	return 0;
}

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

int main(){
    int N; cin >> N;
    int a[N];
    map<long long,long long> ma;
    for(int i=0;i<N;i++){
        cin >> a[i];
        ma[a[i]+i]++;
    }
    long long ans=0;
    for(int i=0;i<N;i++){
        ans+=ma[i-a[i]];
    }
    cout << ans << endl;
}

Measured memory_bytes: 26960
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    int max = 0;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        int temp = 0;
        cin >> temp;
        if (max < temp) max = temp;
        sum += temp;
    }
    cout << (((sum - max) > max) ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string in; cin >> in;
    int n = in.size();

    int res = 0;
    set<char> s = {'A', 'C', 'G', 'T'};

    rep(i, n){
        rep(j, 1, n+1){
            string cur = in.substr(i, j);
            bool ok = true;
            for(auto& c : cur){
                ok &= (s.find(c) != end(s));
            }
            if(ok){
                chmax(res, (int)cur.size());
            }
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
def main():
    a,b = input().split(' ')
    a = int(a)
    b = int(b)
    c = (a + b)/2
    if int(c%1*10) >0:
        print("IMPOSSIBLE")
    else:
        print(int(c))
        
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 2940
# 全探索で間に合う
from collections import deque

N,M=map(int,input().split())
friend=[[] for _ in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    friend[a-1].append(b-1)
    friend[b-1].append(a-1)

count=0
stack=deque([str(0)])
while stack:
    tmp=stack.pop()
    if len(tmp)==N:
        count+=1
    else:
        label=[-1]*N
        for i in range(len(tmp)):
            label[int(tmp[i])]=1
        for i in friend[int(tmp[-1])]:
            if label[i]==-1:
                stack.append(tmp+str(i))
print(count)

Measured memory_bytes: 3316
#include<iostream>

using namespace std;

typedef long long ll;

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

ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void) {
  int N, M;
  string S, T;
  cin >> N >> M >> S >> T;

  ll L = lcm(N, M);
  ll step = lcm(L / N, L / M);

  bool good = true;
  for (int i = 0, j = 0; i < N && j < M; i += step / (L / N), j += step / (L / M)) {
    if (S[i] != T[j]) {
      good = false;
      break;
    }
  }

  if (good) {
    cout << L << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
static const int INF =1000000;
static const int WHITE =0;
static const int GRAY =1;
static const int BLACK =2;
static const int N =100;

int n,A[N][N];

int d[N],p[N],color[N];

int prim(){
  //初期化
   for(int i =0;i<n;i++){
     color[i] =WHITE;
     d[i] = INF;
   }
  int mincost,u;
   d[0]=0;
   p[0]=-1;

   int sum =0;

   while(1){
     int mincost = INF;
     for (int i =0;i<n;i++){
       if(color[i]!=BLACK && d[i] < mincost){
         mincost = d[i];
         u =i;
       }
     }
     if(mincost == INF) break;
     sum += mincost;
     color[u] = BLACK;
     for(int j =0;j<n;j++){
       if(color[j] != BLACK && A[u][j] != INF){
         if(A[u][j] < d[j]){
           d[j] =A[u][j];
           p[j] =u;
           color[j] = GRAY;
         }
       }
     }
   }
   return sum;
}

int main(){
  cin >> n;

  for(int i=0;i<n;i++){
    for(int j =0;j<n;j++){
      cin >> A[i][j];
      if(A[i][j]==-1){
        A[i][j] = INF;
      }
    }
  }
  cout << prim() << endl;

  return 0;
}


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main()
{
    int N;
    int len;
    scanf("%d", &N);
    char S[N];
    scanf("%s", S);
    len = strlen(S);
    if (len % 2 != 0)
    {
        printf("No\n");
        return 0;
    }
    for (int i = 0; i < len / 2 ; i++)
    {
        if (S[i] != S[i + len / 2])
        {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}

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

using namespace std;

int main()
{
	long long a,b;
	cin >> a >> b;
	a=__gcd(a,b);
	int ans=0;
	for(long long i=2;i*i<=a;i++)
	{
		if(a%i==0) ans++;
		while(a%i==0) a/=i;
	}
	if(a>1) ans++;
	cout << ans+1 << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

static const int MAX = 100;
static const int INF = 1 << 30;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra(){
    int minv;
    int d[MAX], color[MAX];

    for (int i = 0; i < n; ++i){
        d[i] = INF;
        color[i] = WHITE;
    }

    d[0] = 0;

    while (true){
        minv = INF;
        int u = -1;
        for (int i = 0; i < n; ++i){
            if( minv > d[i] && color[i] != BLACK ){
                u = i;
                minv = d[i];
            }
        }
        if( u==-1){
            break;
        }

        color[u] = BLACK;

        for (int v = 0; v < n; ++v){
            if( color[v] != BLACK && M[u][v] !=INF){
                if(d[v] > d[u] + M[u][v]){
                    d[v] = d[u] +M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

    for (int i = 0; i < n; ++i){
        cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
    }
}

int main()
{
    cin >> n;

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

    int k, c, u, v;
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        for (int j = 0; j < k; j++){
            cin >> v >> c;
            M[u][v] = c;
        }
    }

    dijkstra();
    return 0;
}


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

public class Hello
{
    public static void Main()
    {
        // Your code here!
        
        int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int A = input[0];
        int B = input[1];
        int C = input[2];
        int X = input[3];
        int Y = input[4];
        
        int sum = 0;
        int t = Math.Abs(X - Y);
       
        if(C * 2 < A + B)
        {
            sum += (C * 2 * Math.Min(X,Y));
            
            if(X > Y)
            {
               sum += Math.Min(C * t * 2, A * t); 
            }
            else
            {
                sum += Math.Min(C * t * 2, B * t);
            }
        }
        else
        {
            sum += (A * Math.Min(X,Y));
            sum += (B * Math.Min(X,Y));
            
             if(X > Y)
            {
               sum += Math.Min(C * t * 2, A * t); 
            }
            else
            {
                sum += Math.Min(C * t * 2, B * t);
            }
        }
        
        Console.WriteLine(sum);
    }
}

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

int main(){
  int64_t N;
  cin >> N;
  vector<int64_t> d(N);
  for(int64_t i=0;i<N;i++){
    cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  int64_t ans=0;
  for(int64_t i=d.at(N/2-1)+1;i<=d.at(N/2);i++){
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
from collections import Counter

n = int(input())
l1 = list(map(int,input().split()))
l1_cnt = Counter(l1) 

m = int(input())
l2 = list(map(int,input().split()))
l2_cnt = Counter(l2) 
l2_set=set(l2)

for i in l2_set:
    if l2_cnt[i]<=l1_cnt[i]:
        continue
    else:
        print('NO')
        break
else:
    print('YES')



Measured memory_bytes: 65456
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define repll(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	int n, m, k;
	cin >> n >> m >> k;

	vector<int> a(n), b(m);
	vector<ll> cum_a(n+2), cum_b(m+2);
	rep(i,n) cin >> a[i];
	rep(i,m) cin >> b[i];

	cum_a[0] = 0; cum_a[n+1] = 1000000000;
	cum_b[0] = 0; cum_b[m+1] = 1000000000;
	rep(i,n) cum_a[i+1] = cum_a[i] + a[i];
	rep(i,m) cum_b[i+1] = cum_b[i] + b[i];

	// cum_b[i] == j冊読むのにかかる時間

	int ans = 0;

	rep(i, n+1){ // i:[0, n]
		int remaining = k - cum_a[i];
		if(remaining < 0) break; // '='は抜く(cum_a == k のピッタリもok)
		auto itr = upper_bound(all(cum_b), remaining);

		int j = distance(cum_b.begin(), itr)-1;
		ans = max(ans, i+j);
	}







	
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 7924
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <stdlib.h>
#include <string.h>
using namespace std;
#define ll long long

int main(){

    int n; cin >> n;
    int sum = 0;
    bool flag = false;

    for(int i=0;i <= n/4;i++){
        for(int j = 0;j <= n/7;j++){
            sum = i*4 + j*7;
            if(sum == n){
                flag = true;
                break;
            }
        }
    }
    if(!flag) cout << "No" << endl;
    else cout << "Yes" << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long
#define int long long
#define ld long double
#define endl '\n'
const int mod= 1e9+7;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define trace(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
#define reset(x,val) memset(x,val,sizeof(x))
#define flush fflush(stdout)
#define sz(a) a.size()
#define pii pair<int,int>
using namespace std;
const int N=3003;
int n,a[N],cache[N][N];
int dp(int i,int j,int turn)
{
 if(j<i)return 0;
 int &ans=cache[i][j];
 if(ans!=-1)return ans;
 
 if(turn==0)
 {
  ans=max(a[i]+dp(i+1,j,1),a[j]+dp(i,j-1,1));
 }
 else
 {
  ans=min( -a[i]+dp(i+1,j,0) , -a[j]+dp(i,j-1,0) );
 }
 return ans;
}
int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin>>n;
    reset(cache,-1);
    for(int i=1;i<=n;i++)cin>>a[i];
    cout<<dp(1,n,0);
    
    return 0;
}



Measured memory_bytes: 70912
#include <bits/stdc++.h>
#define ll long long int

using namespace std;
int main () {
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    unordered_map<ll,ll> m;
    int n;
    cin>>n;
	ll i;
    for(i=2;i<=n;i++)
    {
    	ll x;
    	cin>>x;
    	m[x]++;
	}
	for(i=1;i<n;i++)
	cout<<m[i]<<endl;
	cout<<0<<endl;
	return 0;
	
    
    
}


Measured memory_bytes: 11492
#include <stdio.h>

int main(void)
{
    int a,b;
    int out;

    scanf("%d %d",&a,&b);
    if(a>=13)
    {
        printf("%d",b);
    }
    else if(a>=6)
    {
        printf("%d",b/2);
    }
    else
    {
        printf("0");
    }
    return 0;   
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
  bool flag = false;
  char last = 'a';
  for (int i = 0; i < 4; ++i) {
    char d;
    cin >> d;
    if (last == d)
      flag = true;
    last = d;
  }
  cout << (flag ? "Bad" : "Good") << endl;
}

Measured memory_bytes: 3600
n=int(input())
w=[int(x) for x in input().split()]


m = 5000
l=[]
r=[]

for i in range(n-1):
    t = i+1
    l=w[0:t]
    r=w[t:n]  
    if abs(sum(l)-sum(r)) < m:
        m=abs(sum(l)-sum(r))
print(m)

        

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int A[50001], B[50001], O[50001];

int main() {

  for(int R, C, Q; cin >> R >> C >> Q && R && C && Q;) {
    rep(i, Q) {
      cin >> A[i] >> B[i] >> O[i];
    }

    set<int> vis[2];
    int rcnt = 0, ccnt = 0;
    ll sum = 0;

    for(int i=Q-1; i>=0; i--) {
      if(vis[A[i]].count(B[i])) continue;
      vis[A[i]].insert(B[i]);
      if(O[i]) {
        if(A[i]) sum += R - rcnt;
        else sum += C - ccnt;
      }
      if(A[i]) ccnt ++;
      else rcnt ++;
    }
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 5908
#include <iostream>
#include <numeric>
#include <vector>
#include <algorithm>
#include <string>
#include "math.h"

using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  int K;
  cin >> s >> K;
  for (size_t i = 0; i < s.size() && K > 0; i++) {
    if (K > 'z' - s[i]) {
      K -= ('z' - s[i] + 1) % 26;
      s[i] = 'a';
    }
  }
  if (K > 0) {
    s[s.size()-1] = 'a' + (s[s.size()-1] + K - 'a') % 26;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 888
N = gets.to_i
T = N.times.map { gets.split.map(&:to_i) }
current = [0,0,0]

def reach?(s,t)
  d = t[0] - s[0]
  l = (t[1] - s[1]).abs + (t[2] - s[2]).abs
  d >= l && (d - l).even?
end

ans = T.all? do |t|
  s = current
  if reach?(s, t)
    current = t
  end
end
puts ans ? 'Yes' : 'No'


Measured memory_bytes: 9596
#include <bits/stdc++.h>
#include <cstdlib>
#define ll long long
#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define MX 100010
using namespace std;

int A,B;
int ans;
int main(){
        cin >> A >> B;
        if(A==B) ans=2*A;
        else ans=2*max(A,B)-1;

        cout << ans << endl;

        return 0;
}


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

int main() {
  string N, Nreverse;
  cin >> N;
  
  reverse_copy(N.begin(), N.end(), back_inserter(Nreverse));
  
  if(N==Nreverse) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [ int(i) for i in input().split()]
B = [int(i) for i in input().split()]

score=0
for n in range(N):
    if A[n]>=B[n]:
       score+=B[n]
    else:
        B[n]-=A[n]
        score+=A[n]
        if A[n+1]>=B[n]:
            A[n+1]-=B[n]
            score+=B[n]
        else:
            score+=A[n+1]
            A[n+1]=0

print(score)


Measured memory_bytes: 18468
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve())
}

func resolve() int {
	str := scanString(sc)
	startWith0, startWith1 := 0, 0
	for i, c := range str {
		switch i % 2 {
		case 0:
			if c == '0' {
				startWith1++
			} else {
				startWith0++
			}
		case 1:
			if c == '1' {
				startWith1++
			} else {
				startWith0++
			}
		}
	}
	if startWith0 < startWith1 {
		return startWith0
	}
	return startWith1
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, x, m;
    cin >> n >> x;
    vector<int> arr(n + 1);
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    arr[n] = x;
    sort(arr.begin(), arr.end());
    
    m = arr[1] - arr[0];
    for(int i = 0; i < n; i++) {
        if(arr[i + 1] - arr[i] < m) m = arr[i + 1] - arr[i];
    }
    
    int ans = 1;
    for(int i = m; 1 < m; i--) {
        bool f = 1;
        for(int j = 0; j < n; j++) {
            if((arr[j + 1] - arr[j]) % i != 0) {
                f = 0;
                break;
            }
        }
        if(f) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 5e3+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------

void work(){
    int N; scanf("%d",&N);
    printf("%d\n",(N-1)/2);
}


///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}







Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String S = sc.next();
	String T = sc.next();
	int count = 0;
	for (int i=0;i<S.length();i++) {
	    if (S.charAt(i) != T.charAt(i)) count++;
	}
	System.out.print(count);
    }
}


Measured memory_bytes: 41380
#include<stdio.h>

#define r0(a,b) ((0)>(a-b)?0:(a-b));

int main(){
	long long a,b,c,ans=0;
	scanf("%lld%lld%lld",&a,&b,&c);
	ans+=b;
	if(c-1<=a+b)ans+=c;
	else ans+=a+b+1;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
# B - Maximum Difference
# https://beta.atcoder.jp/contests/abc102/tasks/abc102_b

# B_Maximum_Difference.py

N = int(input())
a = list(map(int, input().strip().split(" ")))

max_abs = -1
for i in range(N):
    for j in range(i+1, N):
        abs = a[i] - a[j]
        if abs <0:
            abs *= -1
        if max_abs < abs:
            max_abs = abs

print(max_abs)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
  const int MAX_PRIME = 1000000+1;

  bool p[MAX_PRIME];
  memset(p, true, sizeof(p));
  p[0] = p[1] = false;
  for (int i = 2; i*i <= MAX_PRIME; ++i) {
    if (p[i]) {
      for (int j = i+i; j < MAX_PRIME; j += i)
	p[j] = false;
    }
  }

  vector<int> prime;
  for (int i = 0; i < MAX_PRIME; ++i) {
    if (p[i])
      prime.push_back(i);
  }

  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int ans = 0;
    while (n--) {
      int p, m;
      cin >> p >> m;
      int X = upper_bound(prime.begin(), prime.end(), p+m) - lower_bound(prime.begin(), prime.end(), p-m);
      ans += X - 1;
    }

    cout << max(0, ans) << endl;
  }
  return 0;
}

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

using namespace std;
using ll = long long;

ll sum_digits(ll x)
{
    ll sum = 0;

    while(x > 0) {
        sum += (x % 10);
        x /= 10;
    }

    return sum;
}

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

    ll sum = sum_digits(N);

    if (N % sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)

n,q=map(int,input().split())
lis=[[] for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    lis[a-1].append(b-1)
    lis[b-1].append(a-1)
p_list=[0]*n
for _ in range(q):
    p,x=map(int,input().split())
    p_list[p-1]+=x
close=set()
def dfs(n):
    close.add(n)
    for e in lis[n]:
        if e not in close:
            p_list[e]+=p_list[n]
            dfs(e)
dfs(0)
for p in p_list: print(p,end=" ")

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;
const int Nmax=114514;
vi t[Nmax];

signed main(){
	int n=read();
	vi ans(n,-1);
	map<int,vi> ci;
	REP(i,n)ci[read()].PB(i);
	REP(i,n-1){
		int a=read()-1,b=read()-1;
		t[a].PB(b);
		t[b].PB(a);
	}
	for(auto kv:ci){
		vi idx;
		for(auto i:kv.second)if(ans[i]==-1)idx.PB(i);
		for(auto i:idx)ans[i]=0;
		for(auto i:idx)for(auto j:t[i])if(ans[j]==-1)ans[j]=1;
	}
	vi res;
	REP(i,n)if(ans[i])res.PB(i);
	REP(i,res.size())
		printf(i?" %lld":"%lld",res[i]+1);
	printf("\n");
}


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

#define pb push_back

#define mod 1000000007

unsigned long long ups[1000000];
unsigned long long downs[1000000];
unsigned long long qnt[1000000];


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

	if(k==n+1)
	{
		cout<<1<<endl;
		return 0;
	}

	downs[0] = 0;
	ups[0] = n+1;

	for(int i = 1; i<=n; i++)
	{
		downs[i] = (downs[i-1] + i);
		ups[i] = (ups[i-1] + n-i);
	}

	for(int i = 0; i<=n; i++)
	{
		qnt[i] = (ups[i]-downs[i])%mod;
	}

	unsigned long long result = 0;
	for(int j=k-1; j<=n; j++)
	{
		result+=qnt[j];
		result = result%mod;
	}

	cout<<result%mod<<endl;

	return 0;
}



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

#define mod 1000000007

int main(){
  int h,w;
  cin>>h>>w;
  char grid[h][w];
  for(int i=0;i<h;i++)
  {
    for(int j=0;j<w;j++)
      cin>>grid[i][j];
  }
  long dp[h+1][w+1];
  for(int i=0;i<=h;i++)
    dp[i][0]=0;
  for(int j=0;j<=w;j++)
    dp[0][j]=0;
  for(int i=1;i<=h;i++)
  {
    for(int j=1;j<=w;j++)
    {
      if(i==1&&j==1)
      {
        dp[i][j]=1;
        continue;
      }
      if(grid[i-1][j-1]=='#')
        dp[i][j]=0;
      else
      {
        dp[i][j]=(dp[i-1][j])%mod+(dp[i][j-1])%mod;
        dp[i][j]=(dp[i][j])%mod;
      }
    }
  }
  cout<<dp[h][w];
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

int main() {
    int n,k;
    cin>>n;
    if(n<10){
k=n;
    }
   else if(10<=n){
        k=n%10;
    }
   
if(k==2 || k==4 || k==5 || k==7 || k==9){
    cout<<"hon"<<endl;
}

else if(k==0 || k==1 || k==6 || k==8){
    cout<<"pon"<<endl;
}

else if(k==3){
    cout<<"bon"<<endl;
}
    return 0;
}

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

int main(){
  while(1){
  int n;
  cin>>n;
  if(n==0) break;
  int m[20][20]={};
  int na=(n*n)/2;
  int dx=n/2,dy=n/2+1;
  m[dy][dx]=1;
     int cnt=1;
    int nx=dx+1,ny=dy+1;
    int t=1;
  while(1){
      if(cnt==n*n) break;
      if(ny>=n){ny=0;continue;}//sita
      else if(nx>=n){nx=0;continue;}//migi
      else if(nx<0){nx=n-1;continue;}//hidari
      else if(m[ny][nx]>0){nx--,ny++;continue;}//aru
     else{cnt++;m[ny][nx]=cnt;nx++;ny++;}
  }
      
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) printf("%4d",m[i][j]);
  cout<<endl;
  }
  }
    
    
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

namespace NyaGadget
{	// DFSライブラリ

	struct DFSedge
	{
		ll v = 0;	// 頂点
		DFSedge(ll vindex) { v = vindex; }
	};

	template <class TE = DFSedge> struct DFS
	{
		using Graph = vector<vector<TE>>;
		Graph graph;

		DFS(ll size) { graph.resize(size); }
		// 頂点xと接続されている頂点を全て取得したいときに使う演算子
		vector<TE>& operator [](int x) { return graph[x]; }

		/**
		@brief 辺を追加する関数
		@note
		 頂点v1とv2を結ぶ辺を追加する。
		**/
		void CreateEdge(ll v1, ll v2)
		{	// 後戻りも出来るようにv1→v2とv2→v1の両方の辺を追加する
			graph[v1].push_back(DFSedge(v2));
			graph[v2].push_back(DFSedge(v1));
		}
	};

}

#define all(collection) (collection).begin(), (collection).end()  // begin to end
#define ceil(a, b) ceil((ld) a / (ld) b);                         // div ceiling
#define each(e, collection) for(auto& e: collection)              // for each
#define rep(i, begin, end) for (ll i = begin; i < end; i++)       // repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)      // repeat reverse
#define size(collection) ((ll) (collection).size())               // collection size

using namespace NyaGadget;

/**
@brief 深さ優先探索
@param r 根
@param v 頂点
@param dfs 処理するDFSグラフ
@param memo 前処理したメモ(加算するべきカウンタの値)
@param ans 出力する答えを格納する配列
@note
 DFSで全てのノードを処理する。
**/
void Solve(ll r, ll v, DFS<>& dfs, vector<ll>& memo, vector<ll>& ans)
{
	if (r != -1)
		ans[v] = ans[r] + memo[v];

	each(e, dfs[v])
	{	// 後戻りしないようにする
		if (e.v == r)
			continue;

		Solve(v, e.v, dfs, memo, ans);
	}
}

int main(void)
{
	ll a, b; cin >> a >> b;
	if (9 < a || 9 < b)
	{
		cout << -1;
		return 0;
	}
	cout << a * b;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N, D[2];
	cin >> N >> D[0] >> D[1];
	if(D[0]%4 != 0 && D[1]%4 != 0) {
		for(int i = 0; i < 2*N; i += 2) for(int j = 0; j < 2*N; j += 2)
			cout << i << " " << j << "\n";
		return 0;
	}
	if(D[0]%4 != 0) swap(D[0], D[1]);
	vector< pair<int, int> > V0;
	for(int i = -N; i <= N; i++) for(int j = -N; j <= N; j++)
		if(i*i+j*j == D[0]/4) V0.push_back({i, j});
	vector< vector<int> > lbl0(N, vector<int>(N, -1));
	queue< pair<int, int> > q;
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) if(lbl0[i][j] == -1) {
		q.push({i, j});
		lbl0[i][j] = 0;
		while(!q.empty()) {
			ALL_THE(V0, it) if(q.front().ff+it->ff >= 0 && q.front().ss+it->ss >= 0) {
				if(q.front().ff+it->ff >= N || q.front().ss+it->ss >= N) continue;
				if(lbl0[q.front().ff+it->ff][q.front().ss+it->ss] == -1) {
					lbl0[q.front().ff+it->ff][q.front().ss+it->ss] = 1-lbl0[q.front().ff][q.front().ss];
					q.push({q.front().ff+it->ff, q.front().ss+it->ss});
				}
			}
			q.pop();
		}
	}
	if(D[1]%4 != 0) {
		for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) {
			int x = 2*i, y = 2*j;
			if(D[1]%4 != 2) x += lbl0[i][j], y += lbl0[i][j];
			else x += lbl0[i][j];
			cout << x << " " << y << "\n";
		}
		return 0;
	}
	vector< pair<int, int> > V1;
	for(int i = -N; i <= N; i++) for(int j = -N; j <= N; j++)
		if(i*i+j*j == D[1]/4) V1.push_back({i, j});
	vector< vector<int> > lbl1(N, vector<int>(N, -1));
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) if(lbl1[i][j] == -1) {
		q.push({i, j});
		lbl1[i][j] = 0;
		while(!q.empty()) {
			ALL_THE(V1, it) if(q.front().ff+it->ff >= 0 && q.front().ss+it->ss >= 0) {
				if(q.front().ff+it->ff >= N || q.front().ss+it->ss >= N) continue;
				if(lbl1[q.front().ff+it->ff][q.front().ss+it->ss] == -1) {
					lbl1[q.front().ff+it->ff][q.front().ss+it->ss] = 1-lbl1[q.front().ff][q.front().ss];
					q.push({q.front().ff+it->ff, q.front().ss+it->ss});
				}
			}
			q.pop();
		}
	}
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) {
		int x = 2*i+lbl0[i][j], y = 2*j+lbl1[i][j];
		cout << x << " " << y << "\n";
	}
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 1792
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int seg_tree[seg_size * 2];
int seg_find(int now, int n_l, int n_r, int w_l, int w_r) {
    if (w_l <= n_l && n_r <= w_r) return seg_tree[now];
    if (w_r <= n_l || n_r <= w_l) return 0;
    return max(seg_find(now * 2, n_l, (n_l + n_r) / 2, w_l, w_r),
        seg_find(now * 2 + 1, (n_l + n_r) / 2, n_r, w_l, w_r));
}

void seg_set(int now) {
    seg_tree[now] = max(seg_tree[now * 2], seg_tree[now * 2 + 1]);
    if (now > 1) seg_set(now / 2);
    return;
}

void solve() {
    int n;
    cin >> n;
    vector<int> inputs(n);
    int ans = 0;
    REP(i, n) {
        cin >> inputs[i];
        ans += inputs[i];
    }
    REP(i, n) {
        seg_tree[(seg_size + inputs[i])] = seg_find(1, 0, seg_size, 0, inputs[i]) + inputs[i];
        seg_set((seg_size + inputs[i]) / 2);
    }
    cout << ans - seg_tree[1] << endl;
}

#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 5308
#include <stdio.h>

int main() {

  int m, f, r;
  int x;
  while(1) {

    scanf("%d %d %d", &m , &f , &r);
    x = m + f;
    if(m == -1 && f ==-1 && r == -1) {
      break;
    }

    if(m == -1 || f == -1) {
      printf("F\n");
    } else if(x >= 80) {
      printf("A\n");
    } else if (x >= 65) {
      printf("B\n");
    } else if(x >= 50) {
      printf("C\n");
    } else if ( x >=30) {
      if(r >= 50) {
	printf("C\n");
      } else {
	printf("D\n");
      }
    } else if (x < 30) {
      printf("F\n");
    }
  }
  return 0;
}



Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define vec vector<ll>
#define inf 10000000000000000
bool mark[100005];
vec adj[100005];
ll counter;
vec cnt;
ll pre[1000005]={0};
ll suff[1000005]={0};
ll dp[105][100006];


int main()
{    
 

	#ifdef APNA_IO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
		    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
ll n;
ll k;
cin>>n>>k;
ll a[n];
ll m=1000000007;

for(ll i=0;i<n;i++)
	cin>>a[i];

for(ll i=0;i<105;i++)
{
	for(ll j=0;j<100006;j++)
		dp[i][j]=0;
	
}

for(ll i=0;i<=a[0];i++)
{
	dp[0][i]=1;
}


for(ll i=1;i<n;i++)
{	
	ll c=0;

	for(ll j=0;j<=k;j++)
	{
		c+=dp[i-1][j];

		if(j>a[i])
			c-=dp[i-1][j-a[i]-1];

		c%=m;
		c+=m;
		c%=m;

		dp[i][j]=c;

	}
}

cout<<dp[n-1][k]<<"\n";

}

Measured memory_bytes: 87936