akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// clang-format off
using i64 = int64_t;
using i32 = int32_t;
#define all(x) x.begin(), x.end()
#define int i64
template <class T, typename U> constexpr inline bool exist(const T &s, const U &e) { return s.find(e) != s.end(); }
template <class T> constexpr inline i32 SZ(const T &x) { return x.size(); }
template <class T> constexpr inline bool rmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> constexpr inline bool rmx(T &a, T b) { return a < b ? (a = b, true) : false; }
const char el = '\n'; const i32 MOD = 1e9 + 7, INF = 0x3f3f3f3f; const i64 INFLL = ((i64)INF << 32) | INF;

#ifdef LOCAL // debugging swiss knife
template <typename Ostream, typename Cont> enable_if_t<is_same<Ostream, ostream>::value, Ostream &> operator<<(Ostream &os, const Cont &v) { os << "{"; for (const auto &x : v) os << x << ", "; return os << "}"; }
template <typename Ostream, typename... Ts> Ostream &operator<<(Ostream &os, const pair<Ts...> &p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class... Args> void dbg_out(Args... args) { ((std::cerr << "\033[32m" << args << "\033[37m, "), ...); }
#define dbg(...) cerr << "\033[1;31m" << __LINE__ << ": [" << #__VA_ARGS__ << "]\033[37m  = ", dbg_out(__VA_ARGS__), cerr << "\033[0m" << endl;
#else
#define dbg(...) ;
#endif
// clang-format on
////////////////////////////////// TEMPLATE ENDS /////////////////////////////////
vector<vector<i32>> adj;
vector<i32> vis, color;

int32_t main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(13), cerr << fixed << setprecision(3);

    int n;
    cin >> n;
    using pii = pair<int, int>;
    vector<pii> v(n);
    int ans = n * (n + 1) / 2;
    for (i64 i = 1; i < n; ++i) {
        ans += i * (i + 1) / 2;
        int l, r;
        cin >> l >> r;
        if (l > r) swap(l, r);
        ans -= l * (n + 1 - r);
    }
    cout << ans << el;

    return 0;
}

Measured memory_bytes: 5932
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include<bits/stdc++.h>

#define int long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz size()   
#define tak return
#define rep(i,k,n) for(int i = k ; i <= n ; ++i)
#define per(i,k,n) for(int i = k , i >= n ; --i)
#define sv_cheats ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string S;                                                                
typedef double D;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<pair<int,int> >PII;
typedef map<int,int> MII;
typedef unsigned long long ull;

const int blyat = 0 ;
const int N = 1e5 + 17;
const int mod = 1e9 + 7;
const int INF = 2e9 - 19;
const int P = 37;
const double p = 3.141592653589793238462643383279 ;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll MX=(ll)1e10,MN=(ll)-1e10;

 // varibles

int a[300000] ,used[300000];

main(){
	int x,y,z;
	cin >> x >> y >> z ;
	if(x + y + z == 17 && x * y * z == 175 && (int)sqrt(x + y + z) == 4 )cout << "YES";
	else cout << "NO" ;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long A, long long B){
    long long R = A % B;
    while(R != 0){
        A = B;
        B = R;
        R = A % B;
    }
    return B;
}
int main(void){
    int N;
    cin >> N;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(),A.end());
    if(N == 1) cout << A[0] << endl;
    else{
    long long S = 1;
    if(A[1]%A[0] == 0) S = A[1];
    else S = A[1] / GCD(A[1],A[0]) * A[0];
    for(int i = 2; i < N; i++){
        if(max(S,A[i])%min(S,A[i]) == 0) S = max(S,A[i]);
        else S = S / GCD(max(S,A[i]),min(S,A[i])) * A[i];
    }
    cout << S << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(vv) vv.begin(), vv.end()
 
using namespace std;
const ll maxn=1e6+100,inf=1e18,LOG=23,mod=1e9 + 7;
 
#define int ll

int n, dp[maxn], k, a[maxn];

main()
{
	IOS
	cin >> n >> k;
	forn(1, i, n)
	{
		cin >> a[i];
	}
	dp[1] = 0;
	dp[2] = abs(a[1] - a[2]);
	forn(3, i, n)
	{
		dp[i] = 1e9;
		forn(max(1ll, i - k), j, i - 1)
		{
			dp[i] = min(dp[j] + abs(a[j] - a[i]), dp[i]);
		}
	}
	cout << dp[n];
}

Measured memory_bytes: 5120
#include <iostream>
#include <map>
#include <unordered_map>
#include <bits/stdc++.h>

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define PI 3.14159265358979323

using namespace std;


int dp[3010][3010];


string getlcs(string s, string t, int len)
{
    string ans="";
    int i=0,j=0;
    while(len){
        if(s[i]==t[j]) { ans.pb(s[i]); len--; i++; j++; }
        else if(dp[i+1][j]>dp[i][j+1]) { i++; }
        else j++;
    }
    return ans;
}

int lenLCS(string &s, string &t,int i,int j)
{
    if(i>=s.length() || j>=t.length() ) return 0;
    if(dp[i][j]!=-1) return dp[i][j];
    if(s[i]==t[j]) return dp[i][j]=1+lenLCS(s,t,i+1,j+1);
    else return dp[i][j]=max(lenLCS(s,t,i,j+1),lenLCS(s,t,i+1,j));
}

string lcs(string s, string t)
{
    memset(dp,-1,sizeof(dp));
    int len=lenLCS(s,t,0,0);
    return getlcs(s,t,len);
}

int main()
{
    string s,t,ans="",k;
    cin>>s>>t;

    ans=lcs(s,t);
    cout<<ans<<endl;

return 0;
}

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

using namespace std;

int solve(const std::vector<int>& as) {
  int const n = as.size();
  int ret = 1;
  int a = as[0];
  for (int i = 1; i < n;) {
    bool accending = true;
    for (; i < n; i++) {
      if (as[i] == a) {
        continue;
      }
      accending = as[i] > a;
      break;
    }
    for (; i < n; i++) {
      if (as[i] == as[i - 1] || (as[i] > as[i - 1]) == accending) {
        continue;
      }
      ret++;
      a = as[i];
      break;
    }
  }
  return ret;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> as(n);
  for (auto& a : as) {
    std::cin >> a;
  }
  std::cout << solve(as) << std::endl;
  return 0;
}

Measured memory_bytes: 640
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;  // aをbで更新
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/




int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	int n, t;
	cin >> n >> t;
	vector<int> T(n);
	
	for (int i = 0; i < n; i++)
	{
		cin >> T[i];
	}
	
	ll ans = 0;

	for (int i = 0; i < n - 1; i++)
	{
		if (T[i] + t <= T[i + 1]) {
			ans += t;
		}
		else
		{
			ans += T[i + 1] - T[i];
		}
	}
	ans += t;

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 1024
n,k = map(int,input().split())
ans = 0
for i in range(1,n+1):
    if i-k > 0:
        ans += (n//i)*(i-k) 
        if (n%i) >= k:
            ans += (n%i) - k + 1
if k == 0:
    print(ans-n)
else:
    print(ans)

Measured memory_bytes: 3060
N=int(input())

SP=[]
for i in range(N):
    SP.append(input().split())
    SP[i][1] = int(SP[i][1])
    SP[i].append(i)
    #print(SP)

SP = sorted(SP, key=lambda x:(x[0],-x[1]))

for j in range(N):
    print(SP[j][2]+1)


Measured memory_bytes: 3060
function Main(input) {
	if(input.length < 2) {
		console.log(0);
		return;
	}

	let result = 0;
	let nums = input.split('').map((n) => (parseInt(n, 10)));
	let n = nums.length;

	for(let i = 0; i < n-1; i++) {
		if(nums[i] + nums[i + 1] === 1) {
			result += 2;
			n -= 2;
			nums.splice(i, 2);
			if(i > 0) {
				i -= 2;
			} else {
				i--;
			}
		}
	}
	console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define ll long long

#define all(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define output_s(a) printf("%s\n",(a).c_str())

//library----------------------------------------------


int main(){
    int a,b; cin>>a>>b;
    int ans = (a+b)/2;
  	if((a+b)%2==0){
      	printf("%d\n",ans);
    }else{
    	printf("IMPOSSIBLE\n");
    }
    return 0;  
}

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

#define ll long long

const int maxn=1e5+10;

struct node
{
    int v,cost;
};

vector<node>tree[maxn];
ll depth[maxn];
int n;
int q,k;
int u,v,c;

void dfs(int u,int last,ll sum)
{
    depth[u]=sum;
    for(int i=0;i<tree[u].size();i++)
    {
        int x=tree[u][i].v;
        if(x==last)
            continue;
        else
            dfs(x,u,sum+tree[u][i].cost*1ll);
    }
}

int main()
{
    scanf("%d", &n);
    for(int i=0;i<n-1;i++)
    {
        scanf("%d%d%d",&u,&v,&c);
        tree[u].push_back({v,c});
        tree[v].push_back({u,c});
    }
    scanf("%d%d",&q,&k);
    int x,y;
    dfs(k,-1,0);
    while(q--)
    {
        scanf("%d%d",&x,&y);
        printf("%lld\n",depth[x]+depth[y]);
    }
    return 0;
}


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

long long n, m;
int a[100000];

int get_lower_limit() {
  int l = 0, r = 2 * 1e5 + 1;
  while (l < r - 1) {
    long long cnt = 0;
    int mid = (l + r) / 2;
    for (int i=0; i<n; i++) {
      auto it = lower_bound(a, a + n, mid - a[i]);
      cnt += (a + n - it);
    }
    if (cnt >= m) {
      l = mid;
    } else {
      r = mid;
    }
  }
  return l;
}
int main() {
  cin>>n>>m;
  for (int i=0; i<n; i++) cin>>a[i];
  sort(a, a + n);
  int lower_limit = get_lower_limit();
  long long acc[n+1];
  acc[0] = 0;
  for (int i=1; i<n+1; i++) {
    acc[i] = acc[i-1] + a[i-1];
  }
  long long ans = 0;
  long long cnt = 0;
  for (int i=0; i<n; i++) {
    auto it = upper_bound(a, a + n, lower_limit - a[i]);
    cnt += (a + n - it);
    int idx = it - a;
    ans += acc[n] - acc[idx] + 1LL * (a + n - it) * a[i];
  }
  ans += 1LL * (m - cnt) * lower_limit;
  cout<<ans<<endl;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main()
{
    int n,k;

    scanf("%d %d",&n,&k);
    int i = 1;
    double ans=0;
    int s=1;

     while(s*n<k)
        {
            s*=2;
        }

        ans += (1/(double)n)*(1/(double)s);

    for(i =n-1 ;i>0;i--)
    {
  while(s*i<k)
        {
            s*=2;
        }
        ans += (1/(double)n)*(1/(double)s);
    }

    printf("%.13f",ans);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000
#define endl '\n'
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; }
using namespace std;

int h,w,k;
int dp[110][10];
int what[10];

signed main(){
    cin>>h>>w>>k;
    dp[0][0]=1;
    what[0]=what[1]=1;
    for(int i=2; i<10; i++){
        what[i]=what[i-1]+what[i-2];
    }
    for(int i=1; i<=h; i++){
        rep(j,w){
            if(j>0){
                dp[i][j]=(dp[i][j]+dp[i-1][j-1]*(what[j-1]*what[w-j-1]))%mod;
            }
            if(j<w-1){
                dp[i][j]=(dp[i][j]+dp[i-1][j+1]*(what[j]*what[w-j-2]))%mod;
            }
            dp[i][j]=(dp[i][j]+dp[i-1][j]*(what[j]*what[w-j-1]))%mod;
        }
    }
    cout<<dp[h][k-1]<<endl;
}

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

int main(){
  int stas[3];
  while(cin >> stas[0] >> stas[1] >> stas[2],stas[0]){
    sort(stas,stas+3);
    int n,r,tmp = stas[0]*stas[0]+stas[1]*stas[1];
    cin >> n;
    for(int i=0;i<n;++i){
      cin >> r;
      if(r*r*4>tmp)cout << "OK" << endl;
      else cout << "NA" << endl;
    }
  }
}



Measured memory_bytes: 3168
class Node():
    right = None
    left = None
    def __init__(self, key, parent):
        self.parent = parent
        self.key = key

class Tree():
    def __init__(self):
        self.root = None

    def insert(self, v):
        y = None
        x = self.root
        while x != None:
            y = x
            if v < x.key:
                x = x.left
            else :
                x = x.right
        z = Node(v, y)

        if y == None: # Tが空の時
            self.root = z
        elif v < y.key:
            y.left = z
        else :
            y.right = z

    # 先行
    def printPreorder(self, parent): # 最初はRootを与え再帰的に。
        print( " " + str(parent.key), end="" )
        if parent.left != None:
            self.printPreorder(parent.left)
        if parent.right != None:
            self.printPreorder(parent.right)

    # 中間
    def printInorder(self, parent): # 最初はRootを与え再帰的に。
        if parent.left != None:
            self.printInorder(parent.left)
        print( " " + str(parent.key), end="" )
        if parent.right != None:
            self.printInorder(parent.right)

def main():
    T = Tree()
    Orders =[]
    tmp =[]
    N = int( input() )
    for i in range(N):
        tmp = [input().split()]
        Orders.extend( tmp )

    for order in Orders:
        if order[0] == "insert":
            T.insert( int( order[1] ) )
        elif order[0] == "print":
            T.printInorder( T.root )
            print("")
            T.printPreorder( T.root )
            print("")

if __name__ == '__main__':
    main()



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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int sum = 0;

  for(int i = 0; i < a; i++){
    sum++;
    if(i + 1 == k){
      break;
    }
  }

  if (a + b >= k) cout << sum;
  else{
    for(int j = a + b + 1; j <= k; j++){
      sum--;
    }
    cout << sum;
  }

  
}



Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>

using namespace std;

struct ta {
    long long x, y, h;
}t[100];

int main() {
    long long n;
    cin >> n;
    for (long long i = 0; i < n; ++i) {
        cin >> t[i].x >> t[i].y >> t[i].h;
    }

    long long maxx = 0, temp;
    ta ans;
    bool p;

    for (long long i = 0; i <= 100; ++i) {
        for (long long j = 0; j <= 100; ++j) {
            for (long long k = 0; k < n; ++k) {
                if (t[k].h != 0) {
                    temp = t[k].h + abs(i - t[k].x) + abs(j - t[k].y);
                    maxx = k;
                    break;
                }
            }

            p = true;
            for (long long k = maxx + 1; k < n; ++k) {
                if (t[k].h == 0) {
                    if (temp - abs(i - t[k].x) - abs(j - t[k].y) > 0) {
                        p = false;
                        break;
                    }
                }
                if (t[k].h != 0 && t[k].h + abs(i - t[k].x) + abs(j - t[k].y) != temp) {
                    p = false;
                    break;
                }
            }

            if (p) {
                ans.h = temp;
                ans.x = i;
                ans.y = j;
            }
        }
    }
    cout << ans.x << " " << ans.y << " " << ans.h <<endl;
}




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

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

  if (d==22)
  cout << "Christmas Eve Eve Eve" << endl;
  else if (d==23)
  cout << "Christmas Eve Eve" << endl;
  else if (d==24)
  cout << "Christmas Eve" << endl;
  else
  cout << "Christmas" << endl;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 200005, P = 1e9 + 7;
typedef long long LL;
int ans;
int power(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = (LL)res * a % P;
		a = (LL)a * a % P;
		b >>= 1;
	}
	return res;
}
int C(int a, int b) {
	int res = 1;
	for (int i = a, j = 1; j <= b; i--, j++) {
		res = (LL)res * i % P * power(j, P - 2) % P;
	}
	return res;
}
int main() {
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	ans = (((LL)power(2, n) - 1 - C(n, a) - C(n, b)) % P + P) % P;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1000000007LL;
vector<int> G[700];
bool is_c[700][700];
bool dp[2][701];
int color[700];
bool vis[700];
bool dfs(int v, int c) {
	color[v] = c;
	vis[v] = 1;
	for (int to : G[v]) {
		if (color[to] == c) return 0;
		if (!color[to] && !dfs(to, -c)) return 0;
	}
	return 1;
}
int main() {
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b; a--; b--;
		is_c[a][b] = is_c[b][a] = 1;
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (is_c[i][j]) continue;
			G[i].push_back(j);
			G[j].push_back(i);
		}
	}
	int k = 0;
	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		if (vis[i]) continue;
		memset(color, 0, sizeof(color));
		if (!dfs(i, 1)) {
			cout << -1 << endl;
			return 0;
		}
		int s = 0, t = 0;
		for (int j = 0; j < N; j++) {
			if (color[j] == 1) s++; else if (color[j] == -1) t++;
		}
		for (int j = 0; j + s <= N; j++) {
			if (!dp[k & 1][j]) continue;
			dp[(k + 1) & 1][j + s] = 1;
		}
		for (int j = 0; j + t <= N; j++) {
			if (!dp[k & 1][j]) continue;
			dp[(k + 1) & 1][j + t] = 1;
		}
		for (int j = 0; j <= N; j++) dp[k & 1][j] = 0;
		k++;
	}
	int ans = 1 << 30;
	for (int i = 0; i <= N; i++) {
		if (!dp[k & 1][i]) continue;
		ans = min(ans, i*(i - 1) / 2 + (N - i)*(N - i - 1) / 2);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3072
# AOJ 0102: Matrix-like Computation
# Python3 2018.6.17 bal4u

while True:
	n = int(input())
	if n == 0: break
	arr = [[0 for r in range(n+2)] for c in range(n+2)]

	for r in range(n):
		arr[r] = list(map(int, input().split()))
		arr[r].append(sum(arr[r]))

	for c in range(n+1):
		s = 0
		for r in range(n): s += arr[r][c]
		arr[n][c] = s

	for r in range(n+1):
		for c in range(n+1): print(format(arr[r][c], '5d'), end='')
		print()


Measured memory_bytes: 5636
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using std::cout;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int abs(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}


int main(){
  int n,k;
  cin >> n >> k ;
  
  int h[n];
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  ll dp[n+10];//(n+10)番目までのcostの最小値
  for(int i=0;i <n+10;i++){
    dp[i]=1000000000000;
  }
  dp[1] = abs( h[0] ,h[1] );
  dp[0] = 0;
  for(int i=2; i <= n-1; i ++){
    for(int j=1; j<= min(i,k) ; j++){
      dp[i] = min(dp[i-j] + abs(h[i-j] , h[i]) , dp[i] );
    }
  }
  
  cout <<dp[n-1] <<endl;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

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

    if (a.size() > b.size()) {
        cout << "GREATER" << endl;
    } else if (a.size() < b.size()) {
        cout << "LESS" << endl;
    } else {
        for (int i = 0; i < a.size(); ++i) {
            string sai, sbi;
            sai = a.at(i);
            sbi = b.at(i);
            int ai, bi;
            ai = stoi(sai);
            bi = stoi(sbi);
            if (ai > bi) {
                cout << "GREATER" << endl;
                break;
            } else if (ai < bi) {
                cout << "LESS" << endl;
                break;
            }
            if (i == a.size() - 1) {
                cout << "EQUAL" << endl;

            }
        }
    }
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] first = br.readLine().split(" ", 3);
        long h = Integer.parseInt(first[0]);
        long w = Integer.parseInt(first[1]);
        int n = Integer.parseInt(first[2]);
        HashMap<Long, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String[] line = br.readLine().split(" ", 2);
            int hh = Integer.parseInt(line[0]) - 1;
            int ww = Integer.parseInt(line[1]) - 1;
            for (int a = Math.max(hh - 2, 0); a <= hh && a + 2 < h; a++) {
                for (int b = Math.max(ww - 2, 0); b <= ww && b + 2 < w; b++) {
                    long key = a * w + b;
                    if (map.containsKey(key)) {
                        map.put(key, map.get(key) + 1);
                    } else {
                        map.put(key, 1);
                    }
                }
            }
        }
        long[] ans = new long[10];
        for (int x : map.values()) {
            ans[x]++;
        }
        ans[0] = (long)(h - 2) * (w - 2) - map.size();
        StringBuilder sb = new StringBuilder();
        for (long x : ans) {
            sb.append(x).append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 116080
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N;
    cin >> N;
    map<int, int> m;
    rep(i,N) {
        int n;
        cin >> n;
        m[n]++;
    }
    int c = 0;
    for (auto x : m) {
        if (x.first == x.second) continue;
        if (x.first > x.second) {
            c += x.second;
        } else {
            c += x.second - x.first;
        }
    }    
    cout << c << endl;
}


Measured memory_bytes: 4736
import math

#in1 = '5'
#in2 = ['1 2','2 1','1 1','3 1','1 1']
#n = int(in1)
n = int(input())

tall = 1
aall = 1
for idx1 in range(n):
    t, a = map(int, input().split())
    #t, a = map(int, in2[idx1].split())
    mul = max(-(-tall // t), -(-aall // a))
    tall, aall = t * mul, a * mul
    #print(tall, aall)

print(tall + aall)


Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {

	int i, j;
	int a, b, c;
	int counter = 0;

	scanf("%d %d %d", &a, &b, &c);
	
	for (i = a; i <= b; i++) {
		if (c%i == 0) {
			counter++;
		}
	}

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


	return 0;
}

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

a.sort(reverse=1)

aa = a[0]
for i in range(1, N):
    aa = gcd(aa, a[i])
    if aa == 1:
        break
print(aa)

Measured memory_bytes: 14252
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
//#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 1000000000

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void swap2(double* a, double* b)
{
	double tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)
{
	if (a < b)
		swap(&a, &b);

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

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

long power(long x, int n) { //x^n 計算量O(logn)
	long ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x;
		}
		x = x * x; //一周する度にx, x^2, x^4, x^8となる
		n >>= 1; //桁をずらす n = n >> 1
	}
	return ans;
}

int choose(int n, int k) {
	return k == 0 ? 1 : (long long)choose(n - 1, k - 1) * n % MOD * power(k, MOD - 2) % MOD;
}

void bubble_sort(int a[], int n)
{
	int i, j, tmp;

	for (i = 0; i < n; i++)
	{
		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (j = n - 1; j > i; j--)
		{
			if (a[j - 1] > a[j])
			{
				tmp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = tmp;
			}
		}
		printf("\n");
	}
}

void selection_sort(int a[], int n)
{
	int i, j, tmp, min, key;

	for (i = 0; i < n - 1; i++)
	{
		min = i;
		key = a[i];

		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (j = i + 1; j < n; j++)
		{
			if (a[j] < a[min])
			{
				min = j;
				key = a[j];
			}
		}

		tmp = a[i];
		a[i] = a[min];
		a[min] = tmp;

		printf("\n");
	}

	for (int k = 0; k < n; k++)
		printf("%d ", a[k]);
}

void insertion_sort(int a[], int n)
{
	int i, j, tmp;

	for (i = 1; i < n; i++)
	{
		j = i;

		while (j >= 1 && a[j - 1] > a[j])
		{
			tmp = a[j];
			a[j] = a[j - 1];
			a[j - 1] = tmp;
			j--;
		}
	}
}

void shell_sort(int a[], int n)
{
	int h, i, j;

	for (h = 1; h < n / 9; h = h * 3 + 1)
		;

	for (; h > 0; h /= 3)
	{
		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (i = h; i < n; i++)
		{
			j = i;
			while (j >= h && a[j - h] > a[j])
			{
				swap(&a[j - h], &a[j]);
				j -= h;
			}
		}
		printf("\n");
	}

	for (int k = 0; k < n; k++)
		printf("%d ", a[k]);
}

int partition(int a[], int l, int r)
{
	int i, j, pivot;

	i = l - 1;
	j = r;
	pivot = a[r];

	for (;;)
	{
		while (a[++i] < pivot)
			;
		while (i < j-- && pivot < a[j])
			;

		if (i >= j)
			break;

		swap(&a[i], &a[j]);
	}

	swap(&a[i], &a[r]);
	return i;
}

void quick_sort1(int a[], int l, int r)
{
	int v;

	if (l >= r)
		return;

	v = partition(a, l, r);

	quick_sort1(a, l, v - 1);
	quick_sort1(a, v + 1, r);
}

void quick_sort(int a[], int n)
{
	quick_sort1(a, 0, n - 1);
}

int main() {
	/*
	int a[50];

	for (int i = 0; i < 50; i++)
		a[i] = rand() % 100;

	quick_sort(a,50);


	for (int i = 0; i < 50; i++)
		printf("%d ", a[i]);
		*/

	char S[100];
	long long int K;

	scanf("%s%lld", S, &K);

	for (int i = 0; i<K; i++)
	{
		if (S[i] != '1')
		{
			printf("%c", S[i]);
			return 0;
		}
	}
	printf("1");
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <list>


constexpr int INF = 1050000000;
constexpr int MOD = 1000000007;
constexpr long long LONGINF = 1005000000000000000;
using namespace std;

using ll = long long;
/*    UnionFind


class UnionFind {
private:
	std::vector<int> parent;
	std::vector<int> height;
	std::vector<int> m_size;

public:
	UnionFind(int size_) : parent(size_), height(size_, 0), m_size(size_, 1) {
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	void init(int size_) {
		parent.resize(size_);
		height.resize(size_, 0);
		m_size.resize(size_, 1);
		for (int i = 0; i < size_; ++i) parent[i] = i;
	}
	int find(int x) {
		if (parent[x] == x) return x;
		return parent[x] = find(parent[x]);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		int t = size(x) + size(y);
		m_size[x] = m_size[y] = t;
		if (height[x] < height[y]) parent[x] = y;
		else parent[y] = x;
		if (height[x] == height[y]) ++height[x];
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		if (parent[x] == x) return m_size[x];
		return size(parent[x] = find(parent[x]));
	}
};


*/

int main() {
	

	while (1) {
		int n; cin >> n; if (n == 0) { return 0; }

		int imos[24 * 60 * 60 + 5] = {};

		for (int i = 0; i < n; i++) {
			char x;
			int a, b, c;
			cin >> a >> x >> b >> x >> c;
			imos[a * 3600 + b * 60 + c + 1] += 1;
			cin >> a >> x >> b >> x >> c;
			imos[a * 3600 + b * 60 + c + 1] -= 1;
		}

		int ans = 0;

		for (int i = 1; i < 24 * 60 * 60 + 5; i++) {
			imos[i] += imos[i - 1];
			ans = max(ans, imos[i]);
		}

		cout << ans << endl;

	}

}


Measured memory_bytes: 3384
// @ts-ignore
import * as fs from 'fs';

// メイン
var g_root: number[];
var g_count: number[];

function main(input: string[]) {
    var work0: number[] = input.shift().split(" ").map(x => Number(x));
    var n: number = work0[0];
    var m: number = work0[1];
    var node: number[][] = input.map(x => x.split(" ").map(x => Number(x) - 1));
    g_root = new Array(n).fill(-1);
    g_count = new Array(n).fill(1);
    node.forEach(value => {
        var a: number = value[0];
        var b: number = value[1];
        var roota: number = getRoot(a);
        var rootb: number = getRoot(b);
        if (roota == rootb) return;
        if (roota > rootb) [roota, rootb] = [rootb, roota];
        mergeRoot(roota, rootb);
    });
    // TODO Math.max(...)は使ってはダメ、スプレッド構文はスタックに展開するのでスタックがあふれる
    // console.log(Math.max(g_cound));
    console.log(Math_max(g_count));
}

function Math_max(arr: number[]) {
    return arr.reduce(function(x, y) {
        return Math.max(x, y);
    });
}
function getRoot(index: number) {
    if (g_root[index] < 0) {
        return index;
    } else {
        var work0: number = getRoot(g_root[index]);
        g_root[index] = work0;
        return work0
    }
}

function mergeRoot(root0: number, root1: number) {
    g_count[root0] += g_count[root1];
    g_count[root1] = 0;
    g_root[root1] = root0;
}

// エントリポイント
// - OSによるパラメタの処理の違いを吸収
function entrypoint() {
    try {
        var input = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        console.debug = function () { };
        main(input);
    }
    catch (ex) {
        console.log("----");
        console.log("file='%s'", __filename.split("\\").slice(-1)[0]);
        console.log("----");
        const lines: string[] = [];
        // @ts-ignore
        const reader = require('readline').createInterface({
            // @ts-ignore
            input: process.stdin,
            // @ts-ignore
            output: process.stdout
        });
        reader.on('line', function (line: string) {
            lines.push(line);
        });
        reader.on('close', function () {
            input = lines;
            console.log("input=%o", input);
            console.time();
            console.log("----")
            main(input);
            console.log("----")
            console.timeEnd();
        });
    }
}
entrypoint();


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

using namespace std;
int main(){
    int N;
    long long sum = 0;

    cin>>N;

    for(int i = 1; i<= N; i++){
        if(i%3 == 0 || i%5 == 0){
            sum = sum;
        }
        else{
            sum = sum + i;
        }
    }
    cout<<sum<<"\n";

    return 0;
}



Measured memory_bytes: 3640
import sys
from collections import Counter

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
A.sort()
B = [0] * (A[-1] + 1)
C = Counter(A)

res = 0
for a in A:
    if B[a] == 0 and C[a] == 1:
        res += 1
    for i in range(a, A[-1] + 1, a):
        B[i] += 1

print(res)


Measured memory_bytes: 43540
let
  N = parse(Int, readline())
  S = readline()
  a = 0
  r = 0
  g = 0
  b = 0
  for i = 1:N
    S[i] == 'R' && (r += 1)
    S[i] == 'G' && (g += 1)
    S[i] == 'B' && (b += 1)
  end
  a = r*g*b
  for l = 1:Int(ceil(N/2)-1), i = 1:N
    if i+2l <= N && S[i] != S[i+l] && S[i] != S[i+2l] && S[i+l] != S[i+2l]
      a -= 1
    end
  end
  println(a)
end


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

using namespace std;

int main(void){
    int n, l;
    int ii;
    int sum = 0;
    cin >> n >> l;
    rep(ii, n){
        sum += (l + ii);
    }
    if(l >= 1){
        sum -= l;
    }else if((l + n - 1) < 0){
        sum -= (l + n - 1);
    }
    cout << sum << endl;
    return 0;
}

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

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

const ll MOD = 1000000007;
const int SIZE = 110000;
ll inv[SIZE],fac[SIZE],finv[SIZE];
void make(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<SIZE;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll nCr(ll n,ll r){
    if(n<r) return 0;
    return fac[n] * finv[r] % MOD * finv[n-r] % MOD;
}

ll n,a[100010];
bool used[100010];
ll ka = 0;
ll cnt1,cnt2,cnt3;


int main() {
    make();
    std::cin >> n;
    for (int i = 0; i < n+1; i++) {
        std::cin >> a[i];
        if(!used[a[i]]){
            used[a[i]] = true;
        }else{
            ka = a[i];
        }
    }

    cnt1 = distance(a,find(a,a+n+1,ka));
    cnt2 = distance(a,find(a + cnt1+1,a+n+1,ka))-cnt1-1;
    cnt3 = n+1 - cnt1 - cnt2-2;
    
    for (int i = 1; i <= n+1; i++) {
        std::cout << (nCr(n+1,i) - nCr(cnt1+cnt3,i-1) + MOD*2)%MOD << std::endl;
    }
}


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

int main(){
    string s;
    cin >> s;
    if (s.size() >= 4 && s.substr(0,4) == "YAKI") cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	for i := 0; i < len(s)-1; i++ {
		if s[i] == s[i+1] {
			fmt.Println("Bad")
			return
		}
	}
	fmt.Println("Good")

}


Measured memory_bytes: 1768
#include<stdio.h>

int main()
{
  int a,b, i;
  scanf("%d%d" , &a, &b);
  i = 0;
  
  while(a>0){
    
  	a = a-b;
  	i = i + 1; 
   
  }
  
  printf("%d\n" , i);
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
struct UnionFind{
    vector<int> d;
    UnionFind(int n):d(n,-1){}
    int root(int x){
        if(d[x] < 0 ) return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x,int y){
        x = root(x),y = root(y);
        if(x == y) return false;
        if(d[x] > d[y])swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    
};
int main()
{
    int n,k,l;
    cin >> n >> k >> l;
    UnionFind road(n),rail(n);
    rep(i,k){
        int p,q;
        cin >> p >> q;
        p--;q--;
        road.unite(p,q);

    }
    rep(i,l){
        int r,s;
        cin >> r >> s;
        r--;s--;
        rail.unite(r,s);
    }
    map<P,int> dict;
    rep(i,n){
        dict[P(road.root(i),rail.root(i))]++;
    }
    rep(i,n){
        int ans = dict[P(road.root(i),rail.root(i))];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 13568
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a+b-3)/(a-1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    long long ta, ao;
    cin >> n >> ta >> ao;
    for(int i=1;i<n;i++){
        long long t, a;
        cin >> t >> a;
        long long ok = (ta + t - 1) / t;
        ok = max(ok, (ao + a - 1) / a);
        ta = t * ok;
        ao = a * ok;
    }
    cout << ta + ao << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<functional>
using namespace std;
int main() {
  int X,Y,Z;
  cin >> X >> Y >> Z;
  
  int space1 = Y + Z;
  int capa = X / space1;
  
  if (X % space1 >= Z) {
    cout << capa << endl;
  }
  else {
    cout << capa - 1 << endl;
  }
}

Measured memory_bytes: 256
# author:  Taichicchi
# created: 19.09.2020 00:06:44

import sys

K = int(input())

a = 7 % K

for k in range(K + 2):
    if a == 0:
        print(k + 1)
        break
    a = (a * 10 + 7) % K
else:
    print(-1)


Measured memory_bytes: 9096
#include <stdio.h>
#include <math.h>

int main(void)
{
  int debt = 100000;

  int n;
  scanf("%d", &n);

  int i;
  for(i=0; i<n; ++i){
    debt *= 1.05;
    debt = ceil(debt/1000.0)*1000;
  }

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

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	string s;
	pair<pair<string,ll>,ll> res[105];
	ll N,num;
	cin>>N;
	for(ll i=0;i<N;i++){
		cin>>s>>num;
		res[i]=make_pair(make_pair(s,-num),i);
	}
	sort(res,res+N);
	for(ll i=0;i<N;i++){
		cout<<res[i].second+1<<endl;
	}
}

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

using namespace std;

const int maxn = 100002;

int n, minv = INT_MAX, cnt = 0;
long long ans = 0;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		if (a < 0) {
			a = -a;
			++cnt;
		}

		minv = min(minv, a);
		ans += a;
	}

	if (cnt & 1)
		ans = ans - minv - minv;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  olymp
//
//  Created by Artur Sydoran on 26.09.2020.
//  Copyright © 2020 Artur Sydoran. All rights reserved.
//



#include "bits/stdc++.h"
#define fi first
#define se second

using namespace std;


#define int long long

int n, k;
int a[100005];

int check(int d){
    vector<int> r(n + 1);
    int sumR = 0;
    for (int i = 1; i <= n; i++){
        r[i] = a[i] % d;
        sumR += r[i];
    }
    if (sumR % d == 0){
        int k = n - sumR / d;
        sort(r.begin() + 1, r.begin() + n + 1);
        int ans = 0;
        for (int i = 1; i <= k; i++){
            ans += r[i];
        }
        if (ans <= ::k){
            return d;
        } else {
            return 0;
        }
    } else {
        return 0;
    }
}

signed main() {
    cin >> n >> k;
    int sum = 0;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        sum += a[i];
    }
    
    int ans = 0;
    for (int i = 1; i <= sqrt(sum); i++){
        if (sum % i == 0){
            ans = max(ans, check(i));
            ans = max(ans, check(sum / i));
        }
    }
    
    cout << ans << endl;
    
}

/*
1 1
 6 9 5
 0
 2 3
 4 5 4
 6 7 5
 0 1 2
 9
 1 60 100 60 100 60 100 60 1
 */


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

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  vector<int> c(n),b(m);
  vector<vector<int>> a(n,vector<int>(m));
  for(int i=0;i<n;i++){
    cin >> c.at(i);
    for(int j=0;j<m;j++){
      cin >> a.at(i).at(j);
      b.at(j) += a.at(i).at(j);
    }
  }
  
  int yes=0;
  for(int i=0;i<m;i++){
    if(b.at(i) < x){
      yes = -1;
      break;
    }
  }
  if(yes == -1) cout << -1 << endl;
  else {
    vector<int> t(n),k(5000);
    for(int i=0;i<5000;i++){
      vector<int> b(m);
      t.at(0) +=1;
      for(int j=0;j<n-1;j++){
        if(t.at(j) == 2){
          t.at(j+1) +=1;
          t.at(j) = 0;
        }
      }
      
      for(int j=0;j<n;j++){
        if(t.at(j) == 1){
          k.at(i) += c.at(j);
          for(int h=0;h<m;h++){
            b.at(h) += a.at(j).at(h);
          }
        }
      }
      for(int h=0;h<m;h++){
        if(b.at(h) < x){
          yes = -1;
          break;
        }
      }
      if(yes == -1) k.at(i) = 0;
      yes = 0;
      
      for(int i=0;i<n;i++){
        if(t.at(i) == 1) yes++;
      }
      
      if(yes == n) break;
      else yes = 0;
    }
    sort(k.begin(),k.end());
    for(int i=0;i<5000;i++){
      if(k.at(i) > 0){
        cout << k.at(i) << endl;
        break;
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a,b;
  cin>>n>>a>>b;
  int kotae=0;
  for(int i=1;i<=n;i++){
    int wa=0;
    int x=i;
    while(x>0){
      wa+=x%10;
      x/=10;
    }
    if(wa>=a&&wa<=b)kotae+=i;
  }
  cout<<kotae<<endl;
  return 0;
}



Measured memory_bytes: 256
#define rep(i, m, n) for(int i = m; i < n; i++)
#define repM(i, m, n) for(int i = n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll; using namespace std;
//typedef pair<int,int> pii;
// d = distance(lower_bound(all(x)), upper_bound(all(x)));
int INF = 1e9;
int m = 1e9+7;
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>

int main(){
  int N; cin >> N; int a[N]; rep(i, 0, N) cin >> a[i];
  ll dp[N][2]; fill(dp[0], dp[N], -1e18); dp[0][0] = a[0], dp[0][1] = -a[0];
  rep(i, 1, N) {
    dp[i][0] = max(dp[i-1][0] + a[i], dp[i-1][1] - a[i]);
    dp[i][1] = max(dp[i-1][0] - a[i], dp[i-1][1] + a[i]);
  }
  cout << dp[N-1][0] << endl;
}

Measured memory_bytes: 2176
use proconio::input;

#[allow(unused_variables)]
fn main() {
    input! {
      n: usize,
      la: [usize; n]
    };

    let mut ans = 0;

    for i in 0..n {
        for j in i + 1..n {
            for k in j + 1..n {
                if la[i] != la[j] && la[j] != la[k] && la[k] != la[i] {
                    if (la[i] + la[j]) > la[k] && (la[i] + la[k]) > la[j] && (la[j] + la[k]) > la[i]
                    {
                        ans += 1;
                    }
                }
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void solve()
{
	int a,b,c;
	cin>>a>>b>>c;
	if((a+b+c)>=22)
	cout<<"bust";
	else
	cout<<"win";
}
int main()
{
//	int t;cin>>t;
//	while(t--)
	solve();
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  char a; cin >> a;
  if('A' <= a && a <= 'Z') cout << "A" << endl;
  else cout << "a" << endl;
}

Measured memory_bytes: 3620
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0046
public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		double[] tmp = new double[100000];
		int cnt = 0;
		while (sc.hasNextDouble()) {
			tmp[cnt++] = sc.nextDouble();
		}
		
		double[] ds = new double[cnt];
		for (int i = 0; i < cnt; i++)
			ds[i] = tmp[i];
		
		sort(ds);
		System.out.println(ds[cnt - 1] - ds[0]);
	}
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Main m = new Main();
    m.input();
    m.check();
  }
  
    Scanner sc = new Scanner(System.in);
    int token  = sc.nextInt();
    int[] num = new int[token];
    int[] x   = new int[token];
    int[] y   = new int[token];

  public void input(){
  for(int i = 0 ; i < token ; i++){
    num[i] = sc.nextInt();
    x[i]   = sc.nextInt();
    y[i]   = sc.nextInt();
    }
  }
  
  public void check(){
      
    int lastNum = 0 , lastX = 0 , lastY = 0;
  
  for(int i = 0 ; i < token ; i++){
    int move = Math.abs(x[i]-lastX) + Math.abs(y[i]-lastY);

    if((num[i]-lastNum) < move || (num[i]-lastNum)%2 != move % 2){
        System.out.println("No");
        return;
    }else{
        
    lastNum = num[i];
    lastX = x[i];
    lastY = y[i];
    }    
  }
  System.out.println("Yes");
  return;
 }
}


Measured memory_bytes: 90736
import sys
input = sys.stdin.readline
from heapq import heappush,heappop

n,q=map(int,input().split())
a=[]
for i in range(n-1):
    heappush(a,list(map(int,input().split())))
p=[0]*q
x=[0]*q
c=[0]*n
for _ in range(q):
    p,x=map(int,input().split())
    c[p-1]+=x
ans=[0]*n
ans[0]=c[0]
for _ in range(n-1):
    l=heappop(a)
    ans[l[1]-1]=ans[l[0]-1]+c[l[1]-1]
print(*ans)

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

int main() {
  int n,m;
  cin >> n >> m;
  
  vector<int> data(2*m);
  for (int i = 0; i < 2*m; i++){
    cin >> data.at(i);
  }
  
  for (int i = 0; i < n; i++) {
    int c = 0;
    for (int j = 0; j < 2*m; j++) {
      if(data.at(j) == i+1){
        c += 1;
      }
    }
    cout << c << endl;
  }
}



Measured memory_bytes: 256