akhauriyash/Code-Regression huggingface dataset:
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


if __name__ == '__main__':
    a =[]

    max =0
    for i in range(5):
        b = int(input())
        a.append(b)

        c = 10 - b%10
        if c <10 and max < c:
            max =c

    sum =0

    for i in a:
        c = 10 - i % 10
        if max ==c:
            sum += i
            max = 11
        else:
            if c ==10:
                sum +=i
            else:
                sum+= i +c

    print(sum)


Measured memory_bytes: 5656
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
int main(){
	long long int x,y,z,a;
	scanf("%lld%lld%lld",&x,&y,&z);
	a=(x-z)/(y+z);
	printf("%lld\n",a);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
const int INF=1e9,MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int dp[302][180101];
int pw(int n,int k){
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  int sum=0;for(int i=0;i<N;i++)sum+=v[i];
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  for(int i=0;i<N;i++){
    for(int j=0;j<90000;j++){
      dp[i+1][j+v[i]]+=dp[i][j];
      dp[i+1][j]+=dp[i][j]*2;
      dp[i+1][j]%=MOD;
    }
  }
  int all=pw(3,N);
  int ho=0;
  for(int j=(sum+1)/2;j<=90000;j++)ho+=dp[N][j];
  ho*=3;
  int ans=((all-ho)%MOD+MOD)%MOD;
  if(sum%2==0){
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=0;i<N;i++){
      for(int j=0;j<90000;j++){
        dp[i+1][j+v[i]]+=dp[i][j];
        dp[i+1][j]+=dp[i][j];
        dp[i+1][j]%=MOD;
      }
    }
    ans+=3*dp[N][sum/2];
  }
  cout<<(ans%MOD+MOD)%MOD<<endl;
}


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

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 1;
    ans *= k;
    rep(i, n - 1) {
        ans *= k - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
while True:
    n,k = map(int, input().split())
    if n == 0 and k == 0:
        break
    a = []
    for i in range(n):
        a.append(int(input()))
        b = 0
    for i in range(k):
        b += a[i]
        s = b
    for i in range(k, n):
        b += a[i]
        b -= a[i - k]
        s = max(s, b)
    print(s)


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


def factorization(n):
    arr = dict()
    temp = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt

    if temp != 1:
        arr[temp] = 1

    if not arr and n != 1:
        arr[n] = 1

    return arr

def make_divisors(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n//i

ans = 1
for v in factorization(N - 1).values():
    ans *= (v + 1)

it = make_divisors(N)
next(it)

for k in it:
    tmp = N
    while not tmp % k:
        tmp //= k
    if tmp % k == 1:
        ans += 1
print(ans - 1)


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

int main () {
  int n, m; cin >> n >> m;
  vector<string> a(n);
  
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  
  sort(a.begin(), a.end());
  string ans = "";
  for (string s : a) {
    ans += s;
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;


const int MAX = 3 * 1e6; // 適宜


ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// 順列組み合わせ計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n - k] % MOD;
}

// 逆元 a^{-1} mod m
// aがmの倍数でないことが前提。O(log m)
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

void mainsolve(){

    ll r1,c1,r2,c2;
    cin >> r1 >> c1 >> r2 >> c2;

    COMinit();
    /*
    vector<ll> ff(MAX),cum(MAX+1);
    ff[0] = ff[1] = 1;
    rep(i,MAX){
        if(i!=0) ff[i] = (ff[i-1] * i) % MOD;
        cum[i+1] = (cum[i] + ff[i]) % MOD;
    }
*/
    auto g = [&](ll r, ll c){
        ll res = 0;
        if(r==0 || c==0) return res;
        if(r==1){
            rep(i,c) res = (res + COM(2+i, 1+i)) % MOD;
            return res;           
        }
        else{
            rep(i,c) res = (res + COM(2+r+i, 2+i)) % MOD;
            return (res - c + MOD) % MOD;
        }

    };


    ll res = (g(r2,c2) + g(r1-1,c1-1)) % MOD;
    res = (res - g(r1-1,c2) + MOD) % MOD;
    res = (res - g(r2,c1-1) + MOD) % MOD;
    cout << res << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 70528
#include <bits/stdc++.h>
#define ll long long
#define MAX 500005
using namespace std;

template<typename T>
void read(T &n){
    n = 0;
    T f = 1;
    char c = getchar();
    while(!isdigit(c) && c != '-') c = getchar();
    if(c == '-') f = -1, c = getchar();
    while(isdigit(c)) n = n*10+c-'0', c = getchar();
    n *= f;
}
template<typename T>
void write(T n){
    if(n < 0) putchar('-'), n = -n;
    if(n > 9) write(n/10);
    putchar(n%10+'0');
}

int n, m, cnt;
int head[MAX], vet[MAX], h[MAX], Next[MAX];

void add(int x, int y){
    cnt++;
    Next[cnt] = head[x];
    head[x] = cnt;
    vet[cnt] = y;
}

int main()
{
    ll X;
    cin >> X;
    for(int i = -2000; i <= 2000; i++){
        for(int j = -2000; j <= i; j++){
            ll x = (ll)i*i*i*i*i, y = (ll)j*j*j*j*j;
            if(x - y == X){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
using namespace std;

int main(){
    int H, W;
    while(1) {
        scanf("%d %d",&H, &W);
        if (H == 0 && W == 0) break;
        
        for (int i = 0; i < H; i++) {
            if (i == 0 || i == H-1) {
                for (int j = 0; j < W; j++){
                    printf("#");
                }
                printf("\n");
            } else {
                printf("#");
                for (int j = 0; j < W-2; j++){
                    printf(".");
                }
                printf("#\n");
            }
        }
        printf("\n");
    }
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   int n,k;
   string s;
   cin >> n >> k;
   vector<bool> v(n);
   rep(i,k){
      int tmp;
      cin >> tmp ;
      rep(j,tmp){
         int t;
         cin >> t;
         if (!v[t-1]) v[t-1]=true;
      }
   }
   int ans = 0;
   rep(i,n){
      if (!v[i]) ans++;
   }
   cout << ans << endl;
   
   
   return 0;
}


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

//gcdやり直す

void swap (int *x, int *y) {
  int temp;    

  temp = *x;
  *x = *y;
  *y = temp;
}




/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}




/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int n,q;
  scanf("%d%d",&n,&q);

  char s[n+1];
  scanf("%s",s);
  int i;
	//printf("%s\n",s);
  int A[n+100];

  for(i=0;i<=n+10;i++){
    A[i]=0;
  }

  int count=0;
  for(i=1;i<n;i++){
    if(s[i-1]=='A' && s[i]=='C'){
      count++;
    }
    A[i+1]=count;
  }


  while(q--){
    int l,r;
    scanf("%d%d",&l,&r);
    printf("%d\n",A[r]-A[l]);
  }

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a, b;
  a = N / 100;
  b = N % 100;
  if (b > 10 * a + a) {
    cout << 111 * (a + 1) << endl;
  }
  else {
    cout << 111 * a << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(long long N, long long Q, std::vector<long long> a, std::vector<long long> b, std::vector<long long> p, std::vector<long long> x){
    
}
vector< vector<int> > tree;
vector<int>node;
vector<bool>visited;
void dfs(int p, int x){
    // debug(p);debug(x);
    visited[p]=true;
    REP(i, tree[p].size()){
        if(!visited[tree[p][i]]){
            dfs(tree[p][i], x+node[tree[p][i]]);
            node[tree[p][i]]+=x;
        }
    }
    return;
}

int main(){
    int N,Q;
    cin>>N>>Q;
    REP(_, N+1){
        vector<int> t;
        tree.PB(t);
        node.PB(0);
        visited.PB(false);
    }
    REP(_, N-1){
        int a, b;
        cin>>a>>b;
        tree[a].PB(b);
        tree[b].PB(a);
    }
    REP(_, Q){
        int p,x;
        cin>>p>>x;
        node[p]+=x;
    }
    dfs(1, node[1]);
    for(int i=1; i<=N; i++){
        cout<<node[i];
        if(i<N)cout<<" ";
    }cout<<endl;
    return 0;
}


Measured memory_bytes: 23948
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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 ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    int n;
    cin >> n;
    cout << n*n*n;
    return 0;
}

Measured memory_bytes: 3536
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

typedef long long ull;
const ull M = 1000000007;

ull nCr[1005][1005];
void Pascals(){
	nCr[0][0] = 1;
	range(i,1,1001){
		rep(j,i + 1){
			if(j == 0) nCr[i][j] = nCr[i - 1][j];
			else if(j == i) nCr[i][j] = nCr[i - 1][j - 1];
			else nCr[i][j] = (nCr[i - 1][j] + nCr[i - 1][j - 1]);
			nCr[i][j] %= M;
		}
	}
}

//べき乗 x^n mod M
ull power(ull x, ull n){
	ull res = 1;
	if(n > 0){
		res = power(x, n / 2);
		if(n % 2 == 0) res = (res * res) % M;
		else res = (((res * res) % M) * x ) % M;
	}
	return res;
}

//階乗
ull fact[1005];
ull factorial(ull n, ull r){
	ull res = 1;
	range(i,r,n + 1){
		res*= i;
		res%= M;
		fact[i] = res;
	}
	return res;
}


//完全順列（a[i] != iとなるような順列）の数を返す
ull derangement(ull n /*長さ*/){
	ull dp[1000000] = {0};
	dp[2] = 1;
	range(i,3,n + 1){
		dp[i] = (i - 1) * (dp[i - 1] + dp[i - 2]);
		dp[i] %= M;
	}
	return dp[n];
}

int main(){
	Pascals();
	factorial(1000,1);
	ull fact_rev[1005];
	rep(i,1001) fact_rev[i] = power(fact[i], M - 2);

	long long n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;

	long long dp[1005] = {0};
	dp[n] = 1;
	//rep(i,1005) dp[i] = 1;
	range(i,a,b + 1){
		range(k,i * c,n + 1){
			long long person = k;
			long long comb = 1;

			range(j,1,d + 1){
				long long join = i * j;
				if(k - join < 0) break;

				(comb *= nCr[person][i]) %= M;
				person-=i;

				if(j >= c){
					assert(person >= 0);
					//cout <<k << ' ' <<  i << ' ' << j << endl;
					(dp[k - join] += dp[k] * comb % M * fact_rev[j] % M) %= M;
					//next[k - join] += dp[k] * comb  / fact[j];
				}
					//rep(i,n + 1){ cout << next[i] << ' '; } cout << endl;
			}
		}
		//rep(i,1005) (dp[i] += next[i]) %= M;
		//memset(next, 0, sizeof(next));
	}
	//rep(i,n + 1){ cout << dp[i] << ' '; } cout << endl;

	cout << dp[0] << endl;
}


Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
int a[30][30];
LL dp[4000001];
LL MOD=1e9+7;

LL dfs(int x,int n){
	if(dp[x]!=-1)return dp[x];
	if(n==N)return 1;
	LL ans=0;
	REP(i,N){
		if(a[n][i]==1&&((x>>i)&1)==0){
			ans+=dfs(x+(1<<i),n+1);
		}
	}
	ans%=MOD;
	dp[x]=ans;
	return ans;
}

int main(){
	cin>>N;
	REP(i,N){
		REP(j,N){
			cin>>a[i][j];
		}
	}
	REP(i,4000001){
		dp[i]=-1;
	}
	
	cout<<dfs(0,0)<<endl;
}

Measured memory_bytes: 31488
n, m = map(int, input().split())
a = []
b = []
for i in range(n):
    a.append(list(map(int, input().split())))
for i in range(m):
    b.append(int(input()))
for i in range(n):
    c = 0
    for j in range(m):
        c += a[i][j] * b[j]
    print(c)


Measured memory_bytes: 6008
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = NextInt();
            var list = new List<int>();
            for (int i = 0; i < N; i++) {
                list.Add(NextInt());
            }
            list.Sort((a, b) => b - a);

            Console.WriteLine(list.First() / 2 + list.Skip(1).Sum());
        }
    }

    class MyMath {
        public static long mod = 1000000007;

        public static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static List<long> Factor(long n) {
            var list = new List<long>();
            n = DivideToLimit(n, 2, list);
            n = DivideToLimit(n, 3, list);
            long sqrt = Sqrt(n);
            for (int i = 5; i <= n && i <= sqrt; i += 4) {
                n = DivideToLimit(n, i, list);
                i += 2;
                n = DivideToLimit(n, i, list);
            }
            if (n > 1) list.Add(n);
            return list;
        }

        public static long Sqrt(long n) {
            if (n < 0) return 0;
            long a = 0, tmp = 0, b = 0;
            for (int i = 62; i >= 0; i -= 2) {
                tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0;
                a = a << 1 | tmp;
                n -= (((b << 1) + 1) * tmp) << i;
                b = (b << 1) + tmp + tmp;
            }
            return a;
        }

        static long DivideToLimit(long divisor, long dividend, List<long> list) {
            while (divisor % dividend == 0) {
                list.Add(dividend);
                divisor /= dividend;
            }
            return divisor;
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

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

int main() {
  string s;
  int a = 0, b = 0, c = 0, i;
  cin >> s;
  
  for(i = 0; i < 3; i++){
    if(s.at(i) == 'a'){
      a++;
    }
    else if(s.at(i) == 'b'){
      b++;
    }
    else{
      c++;
    }
  }
  
  if(a == 1 && b == 1 && c == 1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  string s;cin>>s;
  s+='S';
  int res=0;
  int cur=0;
  rep(i,4){
    if(s[i]=='R')++cur;
    else{
      res=max(res,cur);
      cur=0;
    }
  }
  cout<<res<<"\n";
  return 0;
}


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

int main() {
  vector<int> A(5) ;
  rep(i,5) cin >> A.at(i) ;
  int B = 10 ;
  
  rep(i,5){
    if( A.at(i)%10 != 0 ){
      B = min(B,A.at(i)%10);
      A.at(i) = A.at(i) + 10 - A.at(i)%10 ;
    }
  }
  int ans = 0 ;
  rep(i,5) ans += A.at(i) ;
  cout << ans - 10 + B << endl ;
}

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

typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m,k,i,a,b,j,p;
	cin >> n >> m >> k;
	vector < vector <ll> > ans;
	vector < ll > v[n];
	for(i=0;i<n;i++)
	{
		for(j=0;j<m+1;j++)
		{
			cin >> b;
			v[i].push_back(b);
		}
	}
	for(i=1;i<pow(2,n);i++)
	{
		vector <ll> vi(m+1,0);
		t=i;
		a=0;
		while(t>0)
		{
			if(t%2)
			{
				for(j=0;j<m+1;j++)
				{
					vi[j]+=v[a][j];
				}
			}
			t/=2;
			a++;
		}
		ans.push_back(vi);
	}
	ll min=1000000000000;
	for(i=0;i<ans.size();i++)
	{
		for(j=1;j<m+1;j++)
		{
			if (ans[i][j]<k)
				break;
		}
		if(j==m+1 && ans[i][0]<min)
			min=ans[i][0];
	}
	if(min==1000000000000)
		min=-1;
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 4628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll dep(ll x)
{
    ll ret=0;
    while(x)
    {
        x/=10;
        ret++;
    }
    return ret;
}
void solve()
{
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        ll w=dep(i);
        if(w&1)
        {
            ans++;
        }
    }
    printf("%lld\n",ans);
}
int main()
{
    scanf("%lld",&n);
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
inline bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	cout << (n + 1) / 2 << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    g[a].append(b)
    g[b].append(a)

ed=[0]*n
ed[0]=1
ans=[0]*n

def f(x):
    if 0 not in ed:
        ans[x]+=1
        return
    for a in g[x]:
        if ed[a]==0:
            ed[a]=1
            f(a)
            ed[a]=0
f(0)
print(sum(ans))


Measured memory_bytes: 41436
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <thread>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)

using namespace std;

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

	int segments[2] = { 0, 0 };
	int s_count = 0;

	int max_val = 0;
	int val = 0;
	queue<int> windows;
	bool is_prev_zero = false;
	FOR_LT(i, 0, s.size()) {
		bool is_zero = (s[i] == '0');
		if (is_prev_zero != is_zero) {
			if (s_count & 1) {
				if (windows.size() == k) {
					max_val = max(max_val, val);

					val -= windows.front();
					windows.pop();
				}
				windows.push(segments[1] + segments[0]);
			}
			val += segments[s_count & 1];
			s_count++;
			segments[s_count & 1] = 0;
		}
		segments[s_count & 1]++;
		is_prev_zero = is_zero;
	}
	if (s_count & 1) {
		if (windows.size() == k) {
			max_val = max(max_val, val);
			val -= windows.front();
		}
	}
	val += segments[s_count & 1];
	max_val = max(max_val, val);

	cout << max_val << endl;

	return 0;
}

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

const int inf = 1e9;
const ll linf = 1e18;

template <typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template <typename T>
class SegTree
{
public:
    SegTree(const int n, const T &unity) : _unity(unity)
    {
        _n = 1 << __lg(2 * n - 1);
        _data.resize(2 * _n, unity);
    }

    SegTree(const vector<T> &v, const T &unity) : _unity(unity)
    {
        int n = v.size();
        _n = 1 << __lg(2 * n - 1);
        _data.resize(2 * _n, unity);

        // 最下段に要素をセット
        for (int i = 0; i < n; i++) this->set(i, v[i]);
        // セグメント木を構築
        this->build();
    }

    // k 番目の要素を最下段にセット
    void set(int k, const T &x) { _data[k + _n] = x; }

    // セグメント木を構築
    void build(void) {
        for (int i = _n - 1; i > 0; i--) _data[i] = f(_data[2 * i], _data[2 * i + 1]);
    }

    // k番目の値をxに更新する
    void update(int k, const T &x)
    {
        k += _n; // 葉の節点に変換
        _data[k] = x;
        while (k >>= 1) _data[k] = f(_data[2 * k], _data[2 * k + 1]);
    }

    // 区間[a, b)に対してクエリ処理した結果を返す
    T query(int a, int b)
    {
        T left = _unity, right = _unity;
        a += _n, b += _n; // 葉の節点に変換
        for (; a < b; a >>= 1, b >>= 1) {
            if (a & 1) left  = f(left, _data[a++]);
            if (b & 1) right = f(_data[--b], right);
        }
        return f(left, right);
    }

    const T &operator[](size_t i) const { return _data[i + _n]; }
    T &operator[](size_t i) { return _data[i + _n]; }

private:
    int _n;          // 要素数
    vector<T> _data; // データを格納する配列
    T _unity;        // 単位元

    // クエリ処理用の関数
    T f(const T &a, const T &b) { return gcd(a, b); }
};

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

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

    SegTree<int> seg(a, 0);

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int left = seg.query(0, i);
        int right = seg.query(i + 1, n);
        ans = max(ans, gcd(left, right));
    }

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

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,x,n) for(int i=x;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    vector<int> T={5,12,17,24,31};
    
    while(1){
        int N;cin>>N;
        if(N==0) break;
        vector<int> A(N+1);
        for(int i=0;i<N;i++){
            string S;cin>>S;
            A[i+1]=A[i]+S.size();
        }
        
        for(int s=0;s<N;s++){
            bool ok=true;
            for(int i=0;i<5;i++){
                if(!binary_search(all(A),A[s]+T[i])) ok=false;
            }
            if(ok){
                cout<<s+1<<endl;
                break;
            }
        }
    }
}



Measured memory_bytes: 3200
N = int(input())
S = input()

ruiseki_r = 0
ruiseki_l = 0


left_ruiseki = []
right_ruiseki = []


for s in S:
    if s == '#':
        ruiseki_l += 1
    left_ruiseki.append(ruiseki_l)


for s in S[::-1]:
    if s == '.':
        ruiseki_r += 1
    right_ruiseki.append(ruiseki_r)

right_ruiseki = right_ruiseki[::-1]
right_ruiseki.append(0)

cost = float('inf')

for i in range(N):
    tmpcost = left_ruiseki[i] + right_ruiseki[i+1]
    cost = min(cost,tmpcost)

ans = min(left_ruiseki[N-1], right_ruiseki[0], cost)

print(ans)

Measured memory_bytes: 14508
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
using namespace std;

int main(){
	int N;
	cin>>N;
	map<int,int>num;
	int tmp;
	vector<int>arr;
	for(int i=1;i<=N;++i){
		tmp=i;
		while(tmp!=1){
			for(int i=2;i<=tmp;++i){
				if(tmp%i==0){
					if(num[i]==0)arr.push_back(i);
					num[i]++;
					tmp/=i;
					//cout<<i<<" "<<num[i]<<endl;
					break;
				}
			}
		}
	}
	long ans=1;
	for(int i=0;i<arr.size();++i){
		//cout<<arr[i]<<" "<<num[arr[i]]<<endl;
		ans*=num[arr[i]]+1;
		ans%=(long)pow(10,9)+7;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string S;
  cin >> S;
  ll ans = 0;
  
  reverse(S.begin(), S.end());
  int len = S.size();
  string last = "";
  string curr = "";
  for (int i = 0; i < len; ++i) {
    curr += S[i];
    if (last != curr) {
      ans++;
      last = curr;
      curr = "";
    }
  }
  cout << ans;
  
  return 0;
}

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

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

const int N = 1e5;

int n,t;
int li[N+5];

int suf[N+5];
int pref[N+5];
priority_queue<int> pq;

map<int,int> pas;

int main(){
	scanf("%d%d",&n,&t); t/=2;
	for(int i=1;i<=n;i++){
		scanf("%d",&li[i]);
	}
	suf[n] = li[n];
	pref[1] = li[1];
	for(int i=n-1;i>=1;i--) suf[i] = max(suf[i+1],li[i]);
	for(int i=2;i<=n;i++) pref[i] = min(pref[i-1],li[i]);
	int tmp = 0;
	for(int i=1;i<n;i++){
		tmp = max(tmp,suf[i+1]-li[i]);
	}
//	cout << tmp << endl;
	for(int i=1;i<n;i++){
		if(suf[i+1]-li[i] == tmp){
//			cout << "COBA " << i << endl;
			pas[li[i]]++;
		}
	}
	for(int i=n;i>1;i--){
		if(li[i] - pref[i-1] == tmp){
			pas[li[i]]++;
		}
	}
	int ans = 0;
	for(int i=1;i<n;i++){
		if(suf[i+1]-li[i] != tmp) continue;
		int cur = pas[li[i]];
		int cur2 = pas[suf[i+1]];
//		cout << cur << " " << cur2 << endl;
		ans += min(cur,cur2);
		pas[li[i]]=0;
		pas[suf[i+1]]=0;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6144
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int H = sc.nextInt();

		int[] a = new int[N];
		int[] b = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}

		Arrays.sort(a);
		Arrays.sort(b);

		int maxA = a[a.length - 1];

		int ans = 0;
		int d = 0;

		for (int i = b.length - 1; i >= 0; i--) {
			if (d >= H) {
				break;
			}
			if (b[i] < maxA) {
				break;
			}
			ans++;
			d += b[i];
		}
		sc.close();

		while (d < H) {
			ans++;
			d += maxA;
		}
		out.println(ans);

	}

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

}


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

int n,k;
int a[1000001];
long long sum[1000001];
signed main() 
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		sum[i]=sum[i-1]+a[i]+1;
	}
	sort(a+1,a+n+1);
	long long ans=0;
	for(int i=1;i<=n-k+1;i++)
	{
		ans=max(ans,sum[i+k-1]-sum[i-1]);
	}
	printf("%lf",(double)ans/2);
	return 0;
}


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

using namespace std;




int main()
{

    string s;
    ll a,b;

    cin>>s;

    sort(s.begin(),s.end());
    if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2])cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#-*-coding:utf-8-*-

def main():
    n, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    a_list.sort()
    total = 0
    ans = 0
    for i in range(n):
        total += a_list[i]
        if total <= x:
            ans += 1
    if total < x:
        print(ans - 1)
    else:
        print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

const int N = 25;
struct Point{ int x, y; };

int w, h;
int cost[N][N];
char m[N][N];
vector<Point> t(N);


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

int bfs(int h, int w, Point p, Point g){
	int dis[N][N];
	queue<Point> q;
	rep(i,N) rep(j,N) dis[i][j] = INF;

	dis[p.y][p.x] = 0;
	q.push(p);

	Point u;
	while(not q.empty()){
		u = q.front(); q.pop();
		rep(i,4){
			Point next;
			next.x = u.x + dx[i];
			next.y = u.y + dy[i];
			if(next.x < 0 || next.x >= w || next.y < 0 || next.y >= h) continue;
			if(dis[next.y][next.x] == INF && m[next.y][next.x] != 'x'){
				dis[next.y][next.x] = dis[u.y][u.x] + 1;
				q.push(next);
			}
		}
	}
	return dis[g.y][g.x];
}

int main(){
	while(cin >> w >> h, w){
		t.clear();
		Point s;
		rep(i,h) rep(j,w){
			cin >> m[i][j];
			if(m[i][j] == 'o') s = Point{j,i};
			else if(m[i][j] == '*') t.emplace_back(Point{j,i});
		}
		t.emplace_back(s);

		rep(i,t.size()){
			rep(j,t.size()){
				cost[i][j] = bfs(h, w, t[i], t[j]);
			}
		}

		vector<int> v(t.size() - 1);
		iota(all(v),0);

		int ans = INF;
		do{
			int cnt = 0;
			rep(i,v.size() - 1){
				cnt += cost[v[i]][v[i + 1]];
			}
			cnt += cost[t.size() - 1][v[0]];
			ans = min(ans, cnt);
		}while(next_permutation(all(v)));

		cout << (ans == INF ? -1 : ans) << endl;
	}
}

Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,a; cin >> n >> a;
    ll ans=n;
    for(int i=2;i<50;i++){
        ll left=1,right=10000001;
        while(right-left>1){
            ll mid=(left+right)/2;
            ll tmp=1;
            for(int j=0;j<i;j++){
                tmp*=mid;
                if(tmp>n)break;
            }
            if(tmp>n){
                right=mid;
            }
            else{
                left=mid;
            }
        }
        for(int j=0;j<i+1;j++){
            ll tmp=1;
            for(int k=0;k<j;k++){
                tmp*=left;
            }
            for(int k=0;k<i-j;k++){
                tmp*=right;
            }
            if(tmp>=n){
                ans=min(ans,left*i+i-j+a*(i-1));
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define ll int
#define ull unsigned long long
#define pll pair<ll,ll>
#define MS(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define INFL LLONG_MAX
#define pb push_back
#define FIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll N = 1e6 + 5;
const ll M = 5e2 + 5;
const ll mod = 1e9 + 7;
const ll m1 = 1e9 + 7;
const ll m2 = 1e9 + 9;
const ll p1 = 402653189;
const ll p2 = 1610612741;
const int LN = 32;

ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

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

ll pw[LN],fact[N],invfact[N];

void pre()
{
    fact[0]=1;
    for(int i=0;i<LN;i++)pw[i]=power(2,i);
    for(int i=1;i<N;i++)fact[i]=(i*fact[i-1])%mod;
    for(int i=0;i<N;i++)invfact[i]=powermodm(fact[i],mod-2,mod);
}

int main()
{
    FIO;
    //pre();

    ll i,j;

    ll n;
    cin>>n;

    vector <ll> v(n);

    for(i=0;i<v.size();i++)
        cin>>v[i];

    vector <ll> ans;

    while(!v.empty())
    {
        bool flag = false;
        ll idx = v.size()-1;
        while(v[idx]!=idx+1 && idx>=0)
            idx--;
        if(idx==-1)
        {
            printf("-1\n");
            return 0;
        }
        ans.pb(v[idx]);
        v.erase(v.begin()+idx);
    }
    reverse(all(ans));
    for(i=0;i<ans.size();i++)
        printf("%lld\n",ans[i]);

    return 0;
}

Measured memory_bytes: 256
object Q20200817 {
  case class Input(
    numberOfHuman: Int,
    numberOfKindOfFood: Int,
    answers: Seq[Answer]
             )

  case class Answer(
    numberOfLikeFood: Int,
    numberOfLikeFoodIndexes: Seq[Int],
              )


  class AllHumanLikeKindFoodCount(val value: Int) extends AnyVal {
    override def toString: String = value.toString
  }

  object AllHumanLikeKindFoodCount {
    def apply(numberOfKindOfFood: Int, answers: Seq[Answer]): AllHumanLikeKindFoodCount = {
      new AllHumanLikeKindFoodCount((1 to numberOfKindOfFood)
        .count { i =>
          answers.forall(_.numberOfLikeFoodIndexes.contains(i))
        })
    }
  }
}

object Main extends App {
  import Q20200817._

  import io.StdIn._
  val header = readLine().split(' ').map(_.toInt)
  val stringToAnswer = (line: String) => {
    val numbers = line.split(' ')
    Answer(numbers.head.toInt, numbers.tail.map(_.toInt))
  }
  val numberOfHuman = header.head

  val inputs = (0 until numberOfHuman).map(_ => readLine()).map(stringToAnswer)
  println(AllHumanLikeKindFoodCount(header(1), inputs))
}

Measured memory_bytes: 55096
#include <iostream>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; ++i)
using namespace std;
int main() {
	int n; cin >> n;
	vector<int> value(n);
	vector<int> cost(n);
	rep(i, n) cin >> value[i];
	rep(i, n) cin >> cost[i];
	
	int ans = 0;
	rep(i, n) {
		if (cost[i] < value[i]) {
			ans += value[i] - cost[i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever while (true)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
using namespace std;

template<typename InputIterator> constexpr std::string join(InputIterator first, InputIterator last, const std::string &sep) {
  if (first == last) return "";
  std::stringstream ss;
  ss << *(first++);
  for_each(first, last, [&](auto &x) { ss << sep << x; });
  return ss.str();
}

main {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  list<int> l;
  while (n--) {
    string cmd;
    cin >> cmd;
    int x;
    if (cmd == "insert" || cmd == "delete") cin >> x;
    if (cmd == "insert") l.push_front(x);
    if (cmd == "delete") {
      auto iter = find(all(l), x);
      if (iter != l.end()) l.erase(iter);
    }
    if (cmd == "deleteFirst") l.pop_front();
    if (cmd == "deleteLast") l.pop_back();
  }
  cout << join(all(l), " ") << endl;
}

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

using ll = long long int;
const int maxn = 10+5;
int N, M;
vector<vector<int> > S(maxn);
int P[maxn];

ll solve()
{
	ll result = 0;
	int total = 1 << N;
	for(int bit = 0; bit < total; bit++)
	{
		bool ok = true; 
		for(int i = 0; i < M; i++)
		{
			int cnt = 0; 
			for(auto v : S[i])
				if(bit & (1<<v)) cnt++;
			if(cnt % 2 != P[i]) 
				{
					ok = false;
					break;
				}
		}
		if(ok) result++;
	}
	return result;
}

int main()
{
	cin >> N >> M;
	for(int i = 0; i < M; i++)
	{
		int k; cin >> k; 
		for(int j = 0; j < k; j++)
		{
			int s; cin >> s; s--;
			S[i].push_back(s);
		}	
	}

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

	printf("%lld\n", solve());
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i = 0; i < 6; i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[100];
  int n;cin >> n;
  for(int j=0;j<n;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
  bool ff = true;
  for(int k=0;k<n-1;k++){
    for(int l=k+1;l<n;l++){
      bool f=false;
      for(int i=0;i<4;i++){
	d[l].roll('R');
	for(int j=0;j<4;j++){
	  d[l].roll('N');
	  if(same(d[k],d[l])) f=true;
	}
      }
      d[l].roll('E');
      for(int j=0;j<4;j++){
	d[l].roll('N');
	if(same(d[k],d[l])) f=true;
      }
      
      d[l].roll('W');
      d[l].roll('W');
      for(int j=0;j<4;j++){
	d[l].roll('N');
	if(same(d[k],d[l])) f=true;
      }
      if(f) ff=false;
    }
  }
  if(ff)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const double EPS=1e-6;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) a.rbegin(),a.rend()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) FLL(a,0)
#define declare(a,it) __typeof(a) it=(a)
#define FOR(it,a) for(declare(a.begin(),it);it!=a.end();++it)
#define FORR(it,a) for(declare(a.rbegin(),it);it!=a.rend();++it)
template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
int s2i(string& a){stringstream ss(a);int r;ss>>r;return r;}
int geti(){int n;scanf("%d", &n);return n;}

int n,d;
int main(){
  while(cin >> n >> d && (n || d)){
    vector<vector<int> > miss(n);
    map<int,int> app;
    vector<int> msum(n);
    for(int i = 0; i < n; ++i){
      int m;
      cin >> m;
      vector<int> mi(m);
      for(int j = 0; j < m; ++j)
        cin >> mi[j];
      reverse(mi.begin() , mi.end());
      miss[i] = mi;
      msum[i] = accumulate(mi.begin(), mi.end(), 0);
      ++app[msum[i]];
    }

    vector<int> midx(n);
    while(true){
      bool end = true;
      for(int i = 0; i < n; ++i){
        if(msum[i] == 0) continue;
        int csu = msum[i];
        int nsu = msum[i] - miss[i][midx[i]];
        if(--app[csu]==0) app.erase(csu);
        ++app[nsu];
        if(app.begin()->F+d>=app.rbegin()->F){
          msum[i] = nsu;
          ++midx[i];
          end=false;
          break;
        }
        
        if(--app[nsu]==0) app.erase(nsu);
        ++app[csu];
      }
      
      if(end) break;
    }

    string ans = "Yes";
    for(int i = 0; i < n; ++i)
      if(midx[i] < miss[i].size())
        ans = "No";
    cout << ans << endl;
  }
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */


int main(const int argc, char * argv [])
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  size_t n;
  cin >> n;
  vector<int64_t> a(n);
  cin >> a;

  const int64_t acc = accumulate(begin(a), end(a), (int64_t) 0);

  int64_t out = numeric_limits<int64_t>::max();
  int64_t x = 0;
  for(size_t i = 0; i + 1 < n; ++i)
  {
    x += a[i];
    out = min(out, abs(2 * x  - acc));
  }
  cout << out;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;


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

    string a;
    for (int i = 0; i < 5; i++) {
        a.push_back(str[i]);
    }
    
    string b;
    for (int j = 6; j < 13; ++j) {
        b.push_back(str[j]);
    }

    string c;
    for (int k = 14; k < 19; ++k) {
        c.push_back(str[k]);
    }



    cout << a << " " << b << " " << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N;
  scanf("%d", &N);
  int A[N][N - 1];
  int next[N];
  int fighter[N];
  for(int i = 0; i < N; i++){
    next[i] = 0;
    fighter[i] = 0;
    for(int j = 0; j < N - 1; j++){
      scanf("%d", &A[i][j]);
      A[i][j]--;
    }
  }
  
  int ok = 1;
  int day = -1;
  while(1){
    day++;
    ok = 0;
    for(int i = 0; i < N; i++){
      if(next[i] == N - 1) continue;
      
      ok = 1;
      int hostile = A[i][next[i]];
      if(A[hostile][next[hostile]] == i) fighter[i] = 1;
    }
    
    if(!ok) break;
    
    ok = 0;
    for(int i = 0; i < N; i++){
      if(fighter[i]){
        next[i]++;
        fighter[i] = 0;
        ok = 1;
      }
    }
    
    if(!ok){
      day = -1;
      break;
    }
  }
  
  printf("%d", day);
  
  return 0;
}

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

using namespace std;
typedef long long ll;

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

    int maxNum = min(a, b), cnt = 0, ans = 0;
    for(int i=maxNum; i>0; i--){
        if(a%i==0 && b%i==0){
            cnt++;
        }
        if(cnt == k){
            ans = i;
            break;
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>

#define MAX 101
int sum(0);

void print(int A[], int n) {
    for (int i = 0; i < n; i++) {
        if (i) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n%d\n", sum);
}

void selectionSort(int A[], int n) {
    int i = 0;
    while (i != n-1) {
        int ch = 0;
        int min_i = i;
        for (int j = i+1; j < n; j++) {
            if (A[min_i] > A[j]) {
                min_i = j;
                ch = 1;
            }
        }
        if (ch) {
            std::swap(A[i], A[min_i]);
            sum++;
        }
        i++;
    }
    print(A, n);
}

void bubbleSort( int A[], int n ) {
    int i = 1;
    while (1) {
        for (int j = n-1; j >= i; j--) {
            if (A[j] < A[j-1]) {
                std::swap(A[j], A[j-1]);
                sum ++;
            }
        }
        if (i == n) break;
        i++;
    }
    print(A, n);
}

int main() {
    int n;
    int A[MAX];
    
    scanf( "%d", &n );
    for ( int i = 0; i < n; i++ ) {
        scanf("%d", &A[i]);
    }
    selectionSort(A, n);
    
    return 0;
}

Measured memory_bytes: 3208