akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
      int a,b,ar[5];
      ar[1]=0;
      ar[2]=0;
      ar[3]=0;
      cin>>a>>b;
      ar[a]=1;
      ar[b]=1;
      for(int i=1;i<=3;i++)
      {
        if(ar[i]==0)
           {
             cout<<i<<endl;
             break;
           }
           }
    }

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

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            long K = sc.nextLong();
            long[] A = new long[N];
            for (int i = 0; i < N; i++) {
                A[i] = sc.nextLong();
            }

            Arrays.sort(A);

            long max = 1000000000L * 1000000000L;
            long min = -max;
            long mid = 0;

            while (true) {
                long c = count(A, mid);

                //System.out.println(mid + " : " + c + " (" + min + ", " + max + ")");

                if (c < K * 2) {
                    min = mid;
                } else {
                    max = mid;
                }

                long mid2 = (min + max) / 2;
                if (mid == mid2) {
                    while (true) {
                        c = count(A, mid);
                        if (c >= K * 2) {
                            break;
                        }
                        mid++;
                    }
                    break;
                }

                mid = mid2;
            }

            System.out.println(mid);
        }
    }

    static long count(long[] A, long key) {
        int N = A.length;

        long count = 0;
        for (int i = 0; i < N; i++) {
            if (A[i] == 0) {
                if (key >= 0) {
                    count += (N - 1);
                }
                continue;
            }

            long target = key / A[i];

            if (key < 0) {
                if (key % A[i] != 0) {
                    if (A[i] < 0) {
                        target += 1;
                    } else {
                        target -= 1;
                    }
                }
            }

            if (A[i] < 0) {
                int c = countLessThan(A, target);
                count += (N - c);
                if (i >= c) {
                    count -= 1;
                }
            } else {
                int c = countLessThan(A, target + 1);
                count += c;
                if (i < c) {
                    count -= 1;
                }
            }
        }

        return count;
    }

    static int countLessThan(long[] array, long key) {
        int low = 0;
        int high = array.length - 1;

        if (array[low] >= key) {
            return 0;
        }

        if (array[high] < key) {
            return array.length;
        }

        while (low <= high) {
            int mid = (low + high) / 2;

            if (array[mid] < key) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }

        return low;
    }

}


Measured memory_bytes: 92968
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

print((pow(10, N, mod)-2*pow(9, N, mod)+pow(8, N, mod))%mod)


Measured memory_bytes: 9932
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;

typedef vector<lint> vl;
typedef pair<lint,lint> pll;

#define mpr make_pair



int main()
{
    ios_base::sync_with_stdio(0);    cin.tie(NULL);    cout.tie(NULL);

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

    vi a(m);
    int sum = 0;
    for (int &v : a) {
        cin>>v;
        sum += v;
    }
    if (sum>n) cout<<-1;
    else cout<<n-sum;


}


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

#define N_MAX   (100000)

int main()
{
    // 整数の入力
    int N , K;
    int result;
    cin >> N >> K;
    int h[N_MAX];

    for (int i = 0; i < N; i++) cin >> h[i];

    sort(h, h + N);

    for (int i = 0; i <= N - K; i++) {
        int min = h[i];
        int max = h[i + K - 1];
        int resultcmp = max - min;
        if (i == 0) {
            result = resultcmp;
        } else if (result > resultcmp) {
            result = resultcmp;
        }

    }
    cout << result << endl;
    return 0;

}

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

int main() {
  int x,y,a,b,c;
  cin >> x >> y >> a >> b >> c;
  vector<ll> p(a),q(b),r(c);
  rep(i,a)cin >> p[i];
  rep(i,b)cin >> q[i];
  rep(i,c)cin >> r[i];
  sort(p.rbegin(),p.rend());
  sort(q.rbegin(),q.rend());
  vector<ll> d;
  rep(i,x)d.push_back(p[i]);
  rep(i,y)d.push_back(q[i]);
  rep(i,c)d.push_back(r[i]);
  sort(d.rbegin(),d.rend());
  ll ans=0;
  rep(i,x+y)ans+=d[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e9;

int main(){
  double W,H,x,y;cin>>W>>H>>x>>y;
  bool is_center=((x+x==W)&&(y+y==H));
  cout<<(double(W*H/2))<<" "<<(is_center?1:0)<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	string s;
	cin >> s;
	string al = "abcdefghijklmnopqrstuvwxyza";
	int num[30] = {};
	int n = s.size();
  	for (int i = 0;i < s.size();++i)num[s[i] - 'a']++;
	if (n < 26) {//使ってない文字を数える
		cout << s;
		for (int i = 0;i < 26;++i) {//使ってなかったらsの後ろに付ける
			if (num[i] == 0) {
				cout << al[i] << endl;
				return 0;
			}
		}
	}
	else {
		for (int i = 24; i >= 0; --i) {
			num[s[i + 1] - 'a'] = 0;//s[i+1]を使えるようにした
			for (int j = 0; j < 26; ++j) {
				if ('a' + j > s[i] && num[j] == 0) {
					cout << s.substr(0, i) << (char)('a' + j) << endl;
					return 0;
				}
			}
		}
		cout << -1 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define LIMIT 50
#define INF 10000000
bool graph[LIMIT][LIMIT]; //graphの隣接行列
bool visited[LIMIT]; //visited[i]はgraphの節点iが探索済みか否かを示す
int n;
using namespace std;
void DFS(int v){
	visited[v]=true;
	for(int v2=0; v2<n; ++v2){
		if(!graph[v][v2]) continue;
		if(visited[v2]) continue;
		DFS(v2);
	}
}

int main(void)
{
	int i, j, m, count=0;

	cin>>n>>m;

	vector<vector<int>> c(m, vector<int>(2));

	for(i=0; i<n; i++){
		for(j=0; j<n; j++){
			graph[i][j]=false;
		}
	}

	for(i=0; i<m; i++){
		cin>>c[i][0]>>c[i][1];
		c[i][0]--; c[i][1]--;
		graph[c[i][0]][c[i][1]]=true;
		graph[c[i][1]][c[i][0]]=true;
	}

	for(i=0; i<m; i++){
		graph[c[i][0]][c[i][1]]=false;
		graph[c[i][1]][c[i][0]]=false;

		for(j=0; j<n; j++){
			visited[j]=false;
		}
		DFS(0);

		bool flag=false;
		for(j=0; j<n; j++){
			if(!visited[j]){
				flag=true; break;
			}
		}
		if(flag) count++;

		graph[c[i][0]][c[i][1]]=true;
		graph[c[i][1]][c[i][0]]=true;
	}
	cout<<count<<endl;
}

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

namespace AtCoder.Abc
{
    class QuestionI
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();

            if (s == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else if (s == "ARC")
            {
                Console.WriteLine("ABC");
            }


            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25880
#include "cstdio"

int main (){
    int i,x;
    scanf("%d",&i);
    for(int j=1;j<=i;j++){
        x=j;
        if(!(x%3)) {
            printf(" %d",j);
            continue;
        }else{
            while(x){
                if(x%10 == 3){
                  printf(" %d",j);
                  break;
                }
                x/=10;
            }
        }
    }
    printf("\n");
}


Measured memory_bytes: 2756
#include "bits/stdc++.h"
#include <boost/range/irange.hpp>
using namespace std;
using boost::irange;

// 定義
typedef long long           ll;
typedef pair<ll, ll>        P;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
const ll                    INF = 2e9;
const ll                    INF_LL = 1LL<<60;
const ll                    MOD = 998244353;

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// 処理
void Solve()
{
	string s;
	cin >> s;

	string t;
	for_each(ALL(s), [&t](ll one){ if (one != 'x') t += one; });
	
	ll len = t.size() / 2;
	string tRev = t;
	reverse(ALL(tRev));
	if (t.compare(0, len, tRev.substr(0, len)) != 0) {
		cout << -1 << endl;
		return;
	}

	auto execOne = [len](string s, string t) {
		ll idx = 0;
		vector<ll> xPos(len + 1, 0);
		for (ll i = 0; i <= len; i++) {
			while (s[idx] == 'x') {
				idx++; xPos[i]++;
			}
			idx++;
		}

		return xPos;
	};

	string sRev = s;
	reverse(ALL(sRev));
	vector<ll> xPos = execOne(s, t);
	vector<ll> xPosRev = execOne(sRev, tRev);

	ll ans = 0;
	REP(i, xPos.size()) {
		ans += abs(xPos[i] - xPosRev[i]);
	}

	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	rep(i,n) cin >> s[i];
	sort(s.begin(), s.end());
	rep(i,n) cout << s[i];
	cout << endl;
	return 0;
}

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

const int dy[] = {-1,0,1,0}, dx[] = {0,1,0,-1};
int h,w;
string g[100];

void dfs(int y, int x, vector<pii> &b){
  rep(i,b.size()){
    if(b[i] == pii(y,x))return;
  }
  b.push_back(pii(y,x));

  rep(i,4){
    int ny = y+dy[i], nx = x+dx[i];
    if(ny<0 || nx<0 || ny>=h || nx>=w)continue;
    if(g[ny][nx] == g[y][x])dfs(ny,nx,b);
  }
}

bool rec(int y, int x, int &mid, int &num){
  vector<pii> b;
  dfs(y,x,b);

  num = b.size(); mid = 0;
  int l = 99, r = -l;
  rep(i,4){
    int by = b[i].first+1, bx = b[i].second;
    if(by==h || (g[by][bx] != g[y][x] && g[by][bx] != '.')){
      l = min(l, bx); r = max(r, bx+1);
    }
    mid += bx;
    by -= 2;

    if(by>=0 && (g[by][bx] != g[y][x] && g[by][bx] != '.')){
      int tnum = 0, tmid = 0;
      if(!rec(by,bx,tmid,tnum))return false;

      num += tnum;
      mid += tmid;
    }
  }

  rep(i,4)g[b[i].first][b[i].second] = '.';
  return (l*num < mid + num/2 && mid + num/2 < r*num);
}

int main(){
  while(cin >> w >> h, h){
    rep(i,h)cin >> g[i];

    rep(i,w){
      int num = 0, mid = 0;
      if(g[h-1][i]!='.'){
	cout << (rec(h-1,i,mid,num)?"":"UN") << "STABLE\n";
	break;
      }
    }
  }
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
 
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0) (__VA_ARGS__)
#define rep_0(i, end) for (int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for (int i = (fr); i <= (ba); ++i)
#define overload_rep(arg_0, arg_1, arg_2, name, ...) name
#define all(box) box.begin(), box.end()
 
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

int main() {

  int N, K;
  std::cin >> N >> K;
  std::vector<int> A(N);
  rep (i, N) std::cin >> A[i];

  std::vector<int> answer;
  bool can = [&] {
    int back = -1, min_pos = -1;
    auto find_min = [&] {
      int min = 100000, res = -1;
      rep (i, N) {
        if (i != back && chmin(min, A[i])) {
          res = i;
        } 
      }
      return res;
    };
    auto add = [&] {
      rep (i, N) {
        if (i != back) {
          if (--A[i] < 0) {
            return false;
          }
          if (i != min_pos) {
            answer.emplace_back(i + 1);
          }
        }
      }
      answer.emplace_back(min_pos + 1);
      return true;
    };
    min_pos = find_min();
    add();
    rep (magic, K) {
      back = answer.back() - 1;
      min_pos = find_min();
      if (!add()) {
        return false;
      }
    }
    return true;
  } ();

  if (!can) {
    puts("-1");
  } else {
    int sz = answer.size();
    std::cout << sz << '\n';
    rep (i, sz) {
      std::cout << answer[i];
      std::cout << (i + 1 == sz ? '\n' : ' ');
    }
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define sp(x) fixed<<setprecision(x)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll mod = 1e9+7;

ll dp[22][(1<<22)];
int fun( vector<vector<int>>& comp, int i, int woman_bit, int N)
{
    //Base case
    if(i == N+1)
    {
        if(woman_bit == 0)
            return 1;
            return 0;
    }

    //Lookup
    if(dp[i][woman_bit] != -1)
        return dp[i][woman_bit];

    //Rec case
    ll ans = 0;
    for(int w = 0; w < N; w++)
    {
        bool is_avail = (( (1<<w) & (woman_bit) ) == 0) ? 0 : 1;
        if(is_avail && comp[i][w + 1])
        {
            ans = (ans + fun( comp, i+1, woman_bit ^ (1<<w), N)) % mod;
        }
    }
    return dp[i][woman_bit] = ans;
}

int main() {
   int n;
   cin >> n;
   vector<vector<int>> comp(n+1, vector<int>(n+1));
   memset(dp, -1, sizeof dp);
   for(int i = 1; i<=n; i++)
        for(int j = 1; j <= n; j++)
            cin >> comp[i][j];
   cout<<fun( comp, 1, ((1<<(n)) - 1), n);
   return 0;
}


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

ll memo[100];

ll lucas(ll n) {
  if (n == 0) return 2;
  if (n == 1) return 1;
  if (memo[n] != 0) return memo[n];
  return memo[n] = lucas(n-1) + lucas(n-2);
}

int main() {
  memset(memo, 0, 100);
  ll n;
  cin >> n;
  cout << lucas(n) << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int N=1009;
int h,n;
pair <int,int> a[N];
int dp[12*N];
int solve(int hh){
	if(hh<=0)return 0;
	if(dp[hh]!=-1)return dp[hh];
	int x=LONG_LONG_MAX;
	for(int i=0;i<n;i++){
		x=min(a[i].s+solve(hh-a[i].f),x);
	}
	return dp[hh]=x;
}
int32_t main(){
	if(fopen("input.txt", "r"))
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
	ios::sync_with_stdio(0),cin.tie(0);
	cin >> h >> n;
	for(int i=0;i<n;i++)
		cin >> a[i].f >> a[i].s;
	memset(dp,-1,sizeof dp);
	cout << solve(h);
}

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

long long a[100010]={0},dp[100010]={0};

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lld",a+i);
    }
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    }
    printf("%lld",dp[n-1]);
    return 0;
}



Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

def main():
    # N = int(input())
    # N, K = map(int, input().split())
    # a = list(map(int, input().split()))
    s = input().strip()

    count = 1
    pre = s[0]
    start = 1
    for i in range(2, len(s)+1):
        if pre != s[start:i]:
            count += 1
            pre = s[start:i]
            start = i
    print(count)
    

if __name__ == "__main__":
    main()

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

using namespace std;

int main()
{

    string s;

    while(cin>>s&&s!="0")
    {
        int sum=0;
        int len=s.length();

       for(int i=0;i<len;i++)
       {
           sum+=s[i]-'0';

       }
       cout<<sum<<endl;
    }
}



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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const char EOL = '\n';

void solve();

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

void solve() {
    int a, b;
    cin >> a >> b;
    if (a >= 10 || b >= 10) {
        cout << -1 << EOL;
    } else {
        cout << a * b << EOL;
    }
}


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

//---------------------------------------------------------------
// ------ graph ------ //
using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) { }
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // pqが降順のため
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = vector<Edge>;
struct Graph {
    vector<Edges> adj;
    Graph(int n) : adj(n) { }
    int size() { return adj.size(); }
    Edges operator [] (int v) { return adj[v]; }
    void add_edge(int a, int b, Weight w = 1) { // graph
        adj[a].emplace_back(a, b, w);
        adj[b].emplace_back(b, a, w);
    }
    void add_arc(int a, int b, Weight w = 1) {  // digraph
        adj[a].emplace_back(a, b, w);
    }
};
using Array = vector<Weight>;
using Matrix = vector<Array>;

// ------ Topological Sort (dfs) ------ //
vector<int> tsort(Graph &g) {
    int n = g.size();
    enum { YET, VISITED, DONE };
    vector<int> res, color(n, YET);
    static const function<bool(int)> dfs = [&](int v) {
        color[v] = VISITED;
        for (Edge &e : g[v]) {
            if (color[e.dst] == DONE) continue;
            if (color[e.dst] == VISITED) return false;
            if (!dfs(e.dst)) return false;
        }
        color[v] = DONE; res.push_back(v);
        return true;
    };
    for (int i = 0; i < n; ++i) if (color[i] == YET && !dfs(i)) return {};
    reverse(res.begin(), res.end());
    return res;
}
//---------------------------------------------------------------

int main() {
    int V, E; cin >> V >> E;
    Graph g(V);
    for (int i = 0; i < E; i++) {
        int s, t; cin >> s >> t;
        g.add_arc(s, t);
    }
    vector<int> ord = tsort(g);
    for (int i = 0; i < V; i++) cout << ord[i] << endl;
    return 0;
}


Measured memory_bytes: 4320
#include<stdio.h>
#define N 102
#define MAX 100001
static const int INFTY = (1<<21);
 
main(){
  int n, i, j, u, k, v, c;
  int M[N][N], d[N], p[N], q[N];
 
  scanf("%d", &n);
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
    d[i] = INFTY;
    q[i] = 0;
  }
  d[0] = 0;
  q[0] = 1;
  p[0] = 0;
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }
u = 1;
  for(c = 0; c < n - 1; c++){
    k = MAX;
    for(i = 0; i < u; i++){
      for(j = 0; j < n; j++){
        if(q[j] == 0){
          if(M[p[i]][j] < MAX && d[j] >= M[p[i]][j] + d[p[i]]){
            d[j] = M[p[i]][j] + d[p[i]];
            if(d[j] <= k){
              k = d[j];
              v = j;
            }
          }
        }
      }
    }
    u++;
    q[v] = 1;
    p[i] = v;
  }
  for ( i = 0; i < n; i++){
    printf("%d %d\n", i, d[i]);
  }
 
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll X,N;
    cin >> X >> N;
    map<int, int> p;
    rep(i,N) {
        ll j;
        cin >> j;
        p[j] = 1;
    }
    ll ans = -1;
    for (int i = -1; i < 102; i++)
    {
        if(p[i]!=1 && abs(ans - X) > abs(i - X))
            ans = i;
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

#define ll long long

const int mxN=50, M=1e9+7;
int n;
ll k;

struct mat {
	ll a[mxN][mxN];
	mat operator*(const mat &o) const {
		mat r={};
		for(int i=0; i<n; ++i)
			for(int k=0; k<n; ++k)
				for(int j=0; j<n; ++j)
					r.a[i][j]=(r.a[i][j]+a[i][k]*o.a[k][j])%M;
		return r;
	}
} b, r;

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

	cin >> n >> k;
	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			cin >> b.a[i][j];
	for(int i=0; i<n; ++i)
		r.a[i][i]=1;
	while(k) {
		if(k&1)
			r=r*b;
		b=b*b;
		k/=2;
	}
	ll ans=0;
	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			ans+=r.a[i][j];
	cout << ans%M;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int main()
{
	int n, k;
	long long h[200001], ans = 0;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; scanf("%lld", &h[i++]));
	sort(h, h + n);
	for(int i = 0; i < n - k; ++i)
	{
		ans += h[i];
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1792
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    char c = S[0];
    FOR(i, 1, 4, 1) {
        if (S[i] == c) {
            cout << "Bad" << endl;
            return 0;
        }
        c = S[i];
    }
    cout << "Good" << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "CONTINUE"
#define FALSE__ "GAMEOVER"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define YES(f) if((f)){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(f) if((f)){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))

#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
#define fcout cout << fixed << setprecision(12)

#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

int imos[1002][1002];

void init()
{
	int N;
	cin >> N;
	rep(i, N) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		imos[a][b]++;
		imos[c][d]++;
		imos[a][d]--;
		imos[c][b]--;
	}
	rep(i, 1002) {
		reps(j, 1, 1002) {
			imos[i][j] += imos[i][j-1];
		}
	}
	rep(j, 1002) {
		reps(i, 1, 1002) {
			imos[i][j] += imos[i-1][j];
		}
	}
	int ma = 0;
	rep(i, 1002) {
		rep(j, 1002) {
			chmax(ma, imos[i][j]);
		}
	}
	cout << ma << endl;
}


void solve()
{
}






Measured memory_bytes: 10980
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
using ll = long long;

// Fermat の小定理を用いた F_mod 上での逆元計算x^(mod-2), 蟻本p115
ll Inverse(ll x){
    ll res = 1;
    int n = mod - 2;
    while(n > 0){
        if(n & 1){
            res = res * x % mod;
        }
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

// iの階乗 = fact[i], main内の階乗計算をする必要がある
#define MAX_FACT 3000000
ll fact[MAX_FACT];

ll nCk(int n, int k){
    //　n_C_kの計算, Inverseの中身にもmodを入れないとオーバーフローするので注意, 蟻本p.263
    // n >= k でないと配列外参照するので注意
    ll ans = fact[n] * Inverse(fact[k] * fact[n-k] % mod);
    ans %= mod;
    return ans;
}

int main() {
    int N, M;
    cin >> N >> M;
    /*
     * 全部の組み合わせから不可能なものを引く
     * 不可能なのは
     * 1. ある値が2Mより大きい
     * 2. 値が奇数のものがM個より多い
     * のどちらか, これらは背反(和は3Mより)
     * 奇数に1を1回, 最大の数から2を割り振れば構成できる
     */

    // 階乗計算
    fact[0]=1;
    for(int i = 1; i < MAX_FACT; ++i) {
        fact[i] = fact[i-1] * i % mod;
    }

    ll ans = nCk(3*M+N-1, N-1);

    // ある値が2Mより大きい場合, 他の値の合計で回す
    ll over = 0;
    for (int i = 0; i < M; ++i) {
        over = over + nCk(i+N-2, N-2);
        over %= mod;
    }
    over = over * N; // 2Mより大きい値の自由度
    over %= mod;
    ans = ans + mod - over;
    ans %= mod;


    // 値が奇数のものがM個より多い場合, 奇数の個数で回す
    ll many = 0;
    for (int i = M+1; i <= N; ++i) {
        if(3 * M < i) break;
        if((3 * M - i) % 2 == 1) continue;
        ll temp = 0;
        int sum = (3 * M - i) / 2;
        temp = temp + nCk(sum+N-1, N-1);
        temp %= mod;
        temp = temp * nCk(N, i); // 奇数の位置の自由度
        temp %= mod;
        many += temp;
        many %= mod;
    }
    ans = ans + mod - many;
    ans %= mod;
    cout << ans;
    return 0;
}

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

int main() {
    int N, Q; cin >> N >> Q;
    string str; cin >> str;

    // 累積和
    vector<int> s(N+1, 0);//s(要素数、値)で初期化
    for (int i = 0; i < N; ++i) {
        if (i+1 < N && str[i] == 'A' && str[i+1] == 'C') s[i+1] = s[i] + 1;
        else s[i+1] = s[i];
    }

    // クエリ
    for (int q = 0; q < Q; ++q) {
        int l, r; cin >> l >> r;
        --l, --r; // 0-indexed にする
        cout << s[r] - s[l] << endl;
    }
}   
//けんちょんさんのコピー


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define sz size
#define se second
#define fe first
#define mper make_pair
#define all(x) x.begin(), x.end()
#define mal ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define saken string
#define erba continue
#define vl vector<ll>
#define vi vector<int>
#define vli vector <pair <ll, int> >
#define vll vector <pair <ll, ll> >
#define vii vector <pair <int, int> >
#define vil vector <pair <int, ll> >
using namespace std;

const ll MAXN = 2e5 + 100;
ll n, pref[MAXN];

map <ll, ll> ct;

int main(){

cin >> n;
ll ai;

pref[0] = 0;

for(ll i = 1; i <= n; ++i) {
    cin >> ai;
    pref[i] = pref[i - 1] + ai;
}

ll ans = 0;

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

    ct[pref[i]]++;

    ans += ct[pref[i]] - 1;

}

cout << ans;

return 0;
}



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

int main() {
    int n;
    cin>>n;
    vector<int> h(n+1, 0);
    for(int i=1; i<n+1; i++)
        cin>>h[i];
    vector<long long> sol(n+1,-1);
    sol[0] = INT_MAX;
    sol[1] = 0;
    for(int i=2; i<n+1; i++) {
        sol[i] = min(abs(h[i]-h[i-1])+ sol[i-1], abs(h[i]-h[i-2])+sol[i-2]);
    }
    cout<<sol[n]<<endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <set>
#include <cmath>
#include <map>
#include <algorithm>

using namespace std;

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

int main() {
	long long int n;
	cin >> n;
	vector<P> a(n);
	vector<long long int> b(n, 0);
	long long int aa;
	for (long long int i = 0; i < n; i++) {
		cin >> aa;
		a[i] = P(aa, i);
	}
	sort(a.begin(), a.end(), greater<P>());
	a.push_back(P(0, 0));
	long long int MIN = 1000000;
	for (long long int i = 0; i < n; i++) {
		MIN = min(MIN, a[i].second);
		b[MIN] += (a[i].first-a[i+1].first)*(i+1);
	}
	for (long long int i = 0; i < n; i++) {
		cout << b[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 5632
#include<iostream>

using namespace std;

int main() {
	int x, y;
	cin >> x;
	cin >> y;
	if (x < y) {
		cout <<"a < b"<< endl;
	}
	else if (x>y) {
		cout <<"a > b"<< endl;
	}
	else {
		cout <<"a == b"<< endl;
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int>data(100005);
  for(int i=0;i<n;i++){
    int x;
    cin >> x;
    data.at(x)++;
  }
  int ans=0;
  for(int i=1;i<100004;i++){
    ans=max(ans,data.at(i-1)+data.at(i)+data.at(i+1));
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdbool.h>

typedef double db;
typedef int in;
typedef long int li;
typedef long long int lli;
typedef long ld;
typedef long lld;

#define pi M_PI
#define in scanf
#define out printf
#define inf INT_MAX
#define rep(i,n) for(int i=0;i<n;++i)
#define debugd(d) printf("%d\n",d)
#define debugs(s) printf("%s\n",s)
#define debugc(c) printf("%c\n",c)
#define debugf(f) printf("%f\n",f)


int main (void)
{
  int k,n;
  in("%d\n%d\n",&n,&k);
  int sum;
  int tmp;
  rep(i,n)
  {
    in("%d ",&tmp);
    sum += 2*(tmp<abs(tmp-k)?tmp:abs(k-tmp));
  }
  in("\n");
  out("%d\n",sum);
  return 0;
}


Measured memory_bytes: 128
a,b=map(int,input().split())
s=input()
li=["0","1","2","3","4","5","6","7","8","9"]
if s[a]!="-":
    print("No")
    exit()
for i in range(a):
    if not s[i] in li:
        print("No")
        exit()
for i in range(b):
    if not s[-1-i] in li:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 9184
//AtCoder Beginner Contest 081
//A - Placing Marbles

#include <iostream>

using namespace std;

int main(){
    char s;
    int count = 0;

    for(int i=0;i<3;i++){
        cin >> s;
        if(s=='1') count ++;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<cctype>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stack>
#include<ctime>
#define mst(a,b) memset(a,b,sizeof(a));
const int N = 1e9;
const int mod=(int)1e9+7;
const int INF=0x3f3f3f3f;
typedef long long LL;
//#define LOCAL
const double PI = acos(-1.0);
const int maxn=100+5;
using namespace std;

int a[3];
bool cmp(int a, int b)
{
    return a>b;
}

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

#define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin())

int main()
{
#ifdef LOCAL
    freopen("test.txt", "r", stdin);
#endif // LOCAL
    int N, Y, is, x, y, z;
    is = 0;
    scanf("%d%d", &N, &Y);
    for(z = 0; z <= N;z++)
    {
        for(y = 0; y <= N - z;y++)
        {
            x = N-y-z;
            if(10000*x+5000*y+1000*z==Y){
                is = 1;
                break;
            }
        }
        if(is) break;
    }
    if(is) printf("%d %d %d", x, y, z);
    else printf("-1 -1 -1");
    return 0;
}

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

int main(){
  int n,a[1000007];
  cin>>n;
  for(int i=0;i<n;i++){
  cin>>a[i];
  }
  if(n==1)
  {
    cout<<0<<endl;
    return 0;
  }
  int dp[1000006];
  dp[0]=0;dp[1]=abs(a[0]-a[1]);
  for(int i=2;i<n;i++){
    dp[i]+= min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
//    cout<<dp[i]<<endl;
  }
      
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 4608
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	bool increasing = true;
	for (int i = 1; i < N; ++i) {
		if (A[i - 1] >= A[i]) increasing = false;
	}
	if (increasing) {
		cout << 1 << endl;
	}
	else {
		int L = 1, R = N + 1;
		while (R - L > 1) {
			int M = (L + R) >> 1;
			map<int, int> d;
			for (int j = 0; j < N; ++j) {
				if (d.lower_bound(A[j]) != d.end() && d[A[j]] == 0) d[A[j]] = 1;
				while (!d.empty() && (--d.end())->first > A[j]) {
					d.erase(--d.end());
				}
				if (d[A[j]] < M) {
					++d[A[j]];
				}
				else {
					int ptr = A[j];
					while (true) {
						d[ptr] = 1;
						if (d[ptr - 1] < M) {
							if (d[ptr - 1] == 0) d[ptr - 1] = 1;
							++d[ptr - 1];
							break;
						}
						else --ptr;
					}
				}
			}
			if (d.begin()->first <= 0) {
				L = M;
			}
			else {
				R = M;
			}
		}
		cout << R << endl;
	}
	return 0;
}

Measured memory_bytes: 3840
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	long long int n,a[200000],i,x=0,y=0;
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		x+=a[i];
		x%=1000000007;
	}
	for(i=0;i<n;i++){
		x-=a[i];
		if(x<0) x+=1000000007;
		y+=x*a[i];
		y%=1000000007;
	}
	printf("%lld\n",y);
	return 0;
}


Measured memory_bytes: 3252
#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

u_int64_t ceilDiv(u_int64_t a, u_int64_t b)
{
    return (a / b) + (a % b == 0 ? 0 : 1);
}

int main()
{
    int N;
    u_int64_t T = 1;
    u_int64_t A = 1;
    u_int64_t t;
    u_int64_t a;
    
    cin >> N;
    
    for (int i = 0; i < N; i++)
    {
        cin >> t >> a;
        
        u_int64_t v = max(ceilDiv(T, t), ceilDiv(A, a));
        
        T = t * v;
        A = a * v;
    }
    
    cout << T + A << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
typedef pair<xy_t, int> pci;
typedef vector<lint> poly;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

constexpr double eps=1e-9;

inline int sgn(double x){
    if(x<-eps) return -1;
    if(x>eps) return 1;
    return 0;
}

inline bool EQ(double x, double y){
    return sgn(x-y)==0;
}

inline bool GE(double x, double y){
    return sgn(x-y)==1;
}

inline bool LE(double x, double y){
    return sgn(x-y)==-1;
}

inline bool GEQ(double x, double y){
    return sgn(x-y)>=0;
}

inline bool LEQ(double x, double y){
    return sgn(x-y)<=0;
}

struct Point{
    double x, y;
    Point(double x, double y): x(x), y(y){}

    Point operator+(const Point &p){
        return {x+p.x, y+p.y};
    }

    Point operator-(const Point &p){
        return {x-p.x, y-p.y};
    }

    Point operator*(const double k){
        return {k*x, k*y};
    }

    Point operator/(const double k){
        return {x/k, y/k};
    }

    double operator*(const Point &p){
        return x*p.x+y*p.y;
    }

    double operator^(const Point &p){
        return x*p.y-y*p.x;
    }

    bool operator==(const Point &p){
        return EQ(x, p.x) && EQ(y, p.y);
    }
};

using Vec=Point;
using pdi=pair<double, int>;

double abs(Point p){
    return hypot(p.x, p.y);
}

double arg(Point p){
    return atan2(p.y, p.x);
}

constexpr int CCW_COUNTER_CLOCKWISE=1;
constexpr int CCW_CLOCKWISE=-1;
constexpr int CCW_ONLINE_BACK=-2;
constexpr int CCW_ONLINE_FRONT=2;
constexpr int CCW_ON_SEGMENT=0;

inline int ccw(Point a, Point b, Point c){
    Vec v=b-a, w=c-a;
    if(GE(v^w, 0)) return CCW_COUNTER_CLOCKWISE;
    if(LE(v^w, 0)) return CCW_CLOCKWISE;
    if(LE(v*w, 0)) return CCW_ONLINE_BACK;
    if(LE((a-b)*(c-b), 0)) return CCW_ONLINE_FRONT;
    return CCW_ON_SEGMENT;
}

Point getCrossPointLL(Point p, Vec v, Point q, Vec w){
    double s=((q-p)^w)/(v^w);
    return p+v*s;
}

int main(){
    double x, y;
    scanf("%lf%lf", &x, &y);
    Point p0(x, y);
    scanf("%lf%lf", &x, &y);
    Point p1(x, y);
    int q;
    scanf("%d", &q);

    while(q--){
        scanf("%lf%lf", &x, &y);
        Point p2(x, y);
        int flag=ccw(p0, p1, p2);
        if(flag==CCW_COUNTER_CLOCKWISE) printf("COUNTER_CLOCKWISE\n");
        if(flag==CCW_CLOCKWISE) printf("CLOCKWISE\n");
        if(flag==CCW_ONLINE_BACK) printf("ONLINE_BACK\n");
        if(flag==CCW_ONLINE_FRONT) printf("ONLINE_FRONT\n");
        if(flag==CCW_ON_SEGMENT) printf("ON_SEGMENT\n");
    }
}


Measured memory_bytes: 3240
main = do
  [n, y] <- map read . words <$> getLine
  let ny = [[a, b, c] | a <- [0..n], b <- [0..(n - a)], let c = n - (a + b), 10000 * a + 5000 * b + 1000 * c == y]
  putStrLn $ if null ny then "-1 -1 -1" else unwords $ map show $ head ny

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}

int n, m; char s[1111][1111];

int main(void) {
	read(n); read(m);
	rep (i, n) scanf("%s", s[i] + 1);
	rep (i, n) rep (j, m) {
		// cout << s[i][j] << " "; 
		s[i][j] = (s[i][j] == '.');
	}
	vector <pair <int, int> > vec;
	int tot = 0;
	rep (i, n) rep (j, m) if (!s[i][j]) {
		++tot; vec.emplace_back(i, j);
		// cout << i << " " << j << " " << tot << "\n";
	}
	int ans = 0;
	while (tot < n * m) {
		vector <pair <int, int> > v;
		auto add = [&](int x, int y) {
			// cout << x << " " << y << "\n";
			if (x < 1 || x > n || y < 1 || y > m || !s[x][y])
				return ;
			s[x][y] = 0;
			v.emplace_back(x, y);
			++tot;
		};
		for (auto i : vec) {
			add(i.first - 1, i.second);
			add(i.first, i.second - 1);
			add(i.first + 1, i.second);
			add(i.first, i.second + 1);
		}
		swap(v, vec);
		++ans;
	}
	cout << ans << "\n";

}



Measured memory_bytes: 14824
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int MAX = 2000;
const int INF = 10000000;

int cost(string& A, string& B, int N, vector < pair<pair<int, int>, int>>& p, int shift) {
	int d = abs(shift);
	int cost = d;
	int ma = 0;
	int sum = INF;

	for (int i = 0; i < p.size(); i++) {
		int j = p[i].second;
		int f = p[i].first.first;
		int s = p[i].first.second - d;
		s = s < 0 ? 0 : s;

		if (A[(j + shift + N) % N] != B[j]) {
			cost++;
			sum = min(sum, f + ma);
			ma = max(ma, s);
		}	
	}
	sum = min(sum, ma);
	return cost + sum * 2;
}

int main() {
	string A, B;
	int N;
	int L[MAX];
	int R[MAX];
	int begin = -1;
	int ans = INF;

	cin >> A >> B;
	N = A.length();
	for (int i = 0; i < N; i++) {
		if (B[i] == '1') {
			begin = i;
			break;
		}
	}

	if (A == B) {
		cout << 0 << endl;
		return 0;
	}
	if (begin == -1) {
		cout << -1 << endl;
		return 0;
	}

	int left = 0;
	int right = 0;
	int b1, b2;
	b1 = b2 = begin + N;
	for (int i = 0; i < N; i++) {

		if (B[b1 % N] == '1') {
			left = 0;
		}
		if (B[b2 % N] == '1') {
			right = 0;
		}

		L[b1 % N] = left++;
		R[b2 % N] = right++;

		b1++;
		b2--;
	}

	vector<pair<pair<int,int>, int>> p1, p2;
	for (int i = 0; i < N; i++) {
		p1.push_back(make_pair(make_pair(R[i], L[i]),i));
		p2.push_back(make_pair(make_pair(L[i], R[i]),i));
	}

	sort(p1.begin(), p1.end());
	sort(p2.begin(), p2.end());
	reverse(p1.begin(), p1.end());
	reverse(p2.begin(), p2.end());

	for (int shift = 0; shift <= N; shift++) {
		ans = min(cost(A, B, N, p1, -shift), ans);
		ans = min(cost(A, B, N, p2, shift), ans);
	}

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N, M, ans;
ans = 0;
cin >> N >> M;

while(true){
if(N == 0){
break;
}

N--;
ans += N;
}
while(true){
if(M == 0){
break;
}

M--;
ans += M;
}
cout << ans << endl;


}

Measured memory_bytes: 256
//هوالحق
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    int n, l, s = 0, r = 1000000000;
    cin >> n >> l;
    for(int i = 0; i < n; i++){
        s += l + i;
        if(abs(r) >= abs(l + i)) r = l + i;
    }
    cout << s - r;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 100
#define INF 1e9 + 5
using namespace std;
using ll = long long;
vector<ll> v;
vector<ll> w;
vector<vector<ll>> memo;
ll solve(int n, int k)
{
    if(n<0) return 0;
    ll best = -1;  
    if(memo[n][k]!=-1) return memo[n][k];
    if(k-w[n]>=0){
        best = max(best, solve(n-1,k-w[n])+v[n]);
    }
    best = max(best, solve(n-1,k));
    
    memo[n][k]=best;
    return best;
}

int main()
{
    int n, W;
    scanf("%d %d", &n, &W);
    v.resize(n + 1);
    w.resize(n + 1);
    memo.resize(n + 1, vector<ll>(W+1, -1));
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d", &w[i], &v[i]);
    }

    //solve 는 n번째 물건이고 무게가 W일때..
    cout << solve(n, W);

    return 0;
}


Measured memory_bytes: 80256
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

typedef long long ll;

#include <queue>
#include <cstdio>
inline ll getLL(){ ll s; scanf("%lld", &s); return s; }
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  vector<ll> a(n);
  REP(i,n) a[i] = getLL();
  sort(a.begin(), a.end());
  vector<ll> as(n);
  as[0] = a[0]; REP(i,n-1) as[i + 1] = as[i] + a[i + 1];

  const int m = getInt();
  vector<ll> b(m);
  vector<ll> c(m);
  REP(i,m) b[i] = getLL();
  REP(i,m) c[i] = getLL();

  REP(i,m){
    const int idx = lower_bound(a.begin(), a.end(), b[i] + 1) - a.begin();
    const ll g = idx == 0 ? 0 : as[idx - 1];
    puts(c[i] <= g ? "Yes" : "No");
  }

  return 0;
}

Measured memory_bytes: 10172
import java.util.Scanner;

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

        if (a % 2 != 0) {
            if (b % 2 != 0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } else {
            System.out.println("No");
        }

    }
}





Measured memory_bytes: 22612
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int sunuke[100];
 
int main() {

    int n,k;
    cin >> n >> k;
    vector<int> v;
    rep(i,k) {
        int d;
        cin >> d;
        rep(i,d) {
            int a;
            cin >> a;
            a--;
            v.push_back(a);
        }
    }
    rep(i,v.size()) {
        sunuke[v[i]]++;
    }
    int ans = 0;
    rep(i,n) {
        if(sunuke[i] == 0)  ans++;
    }

    cout<< ans << endl;

    
 return 0;
}

Measured memory_bytes: 3632