akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

ll dp[1000100][3];

int main(){
  rep(i,0,1000100)rep(j,0,3)dp[i][j] = 1000000000000000000LL;
  ll d[10] = {0,1,2,3,4,5,5,4,3,2};
  string s;
  cin>>s;
  ll flag = 0;
  dp[0][0] = d[s[0]-'0'];
  dp[0][1] = 1+(9-(s[0]-'0'));
  rep(i,1,s.sz){
    ll a = s[i]-'0';
    dp[i][0] = min(dp[i][0],dp[i-1][0]+d[a]);
    dp[i][1] = min(dp[i][1],dp[i-1][0]+1+(9-a));
    dp[i][2] = min(dp[i][2],dp[i-1][1]+(9-a));
    dp[i][2] = min(dp[i][2],dp[i-1][2]+(9-a));
    dp[i][0] = min(dp[i][0],dp[i-1][1]+(10-a));
    dp[i][0] = min(dp[i][0],dp[i-1][2]+(10-a));
  }
  cout << dp[s.sz-1][0] << endl;
  return 0;
}

Measured memory_bytes: 24964
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    if(abs(A-B) % 2 == 0)cout << abs(A-B)/2;
    else{
        cout << min(N - max(A, B), min(A, B) - 1) + (abs(A - B)-1) /2 + 1;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll dx = c - a, dy = d - b;
  cout << c - dy << " " << d + dx << " " << a - dy << " " << b + dx << endl;
  return 0;
}


Measured memory_bytes: 256
#define q(x,y)(f[x]*h[y]%m*h[(x)-(y)]%m)
long long H,W,A,B,i=2,f[1<<18],g[1<<18],h[1<<18],r,z=2e5,m=1e9+7;main(){for(f[0]=f[1]=g[1]=1;i<z;i++)f[i]=f[i-1]*i%m,g[i]=g[m%i]*(m-m/i)%m;for(h[0]=i=1;i<z;i++)h[i]=h[i-1]*g[i]%m;for(scanf("%d%d%d%d",&H,&W,&A,&B),i=0;i<W-B;i++)r=(r+q(A+i-1,i)*q(W-i+H-A-2,H-A-1))%m;i=!printf("%d\n",r);}

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

using namespace std;

int n;

int kind[16];
vector<pair<int,int>> guess[16];
int ans = -1;

void kind_recur(int k, int val){
    if(k==n){
        bool flag_val = true;
        for(int i=0;i<n;i++){
            if(!kind[i]) continue;
            for(auto z: guess[i]){
                if(kind[z.first]!=z.second){
                    flag_val = false;
                    break;
                }
            }
            if(!flag_val) break;
        }
        if(flag_val){
            int sum = 0;
            for(int i=0;i<n;i++){
                sum += kind[i];
            }
            ans = max(ans, sum);
        }
    }else{
        kind[k] = val;
        kind_recur(k+1, 0);
        kind_recur(k+1, 1);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        for(int j=0;j<a;j++){
            int x, y;
            cin>>x>>y;
            x--;
            guess[i].emplace_back(x, y);
        }
    }
    kind_recur(0, 0);
    kind_recur(0, 1);
    cout<<ans;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
int n, *a;
	cin >> n;
	a = new int[n];
	for (int i = 0; i < n; i++)
			cin >> a[i];
	cout << a[n-1];
	for (int i = n-2; i >= 0; i--)
	cout << " " << a[i];
	cout << endl;
		return 0;
}

Measured memory_bytes: 1188
N = int(input())
S = [input() for _ in range(N)]
L = [0] * 5
ans,tmp = 0,1

for char in S:
    if char[0] == "M":
        L[0] += 1
    if char[0] == "A":
        L[1] += 1
    if char[0] == "R":
        L[2] += 1
    if char[0] == "C":
        L[3] += 1
    if char[0] == "H":
        L[4] += 1

for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += L[i] * L[j] * L[k]

print(ans)


Measured memory_bytes: 9772
#include<stdio.h>

#include<queue>

using namespace std ;

#define N_MAX 100000

int N ,K ;
int time[ N_MAX ] ;

priority_queue< int > que ;

int main( void )
{
	scanf( "%d %d" ,&N ,&K ) ;

	int i ,j ;
	for( i = 0 ; i < N ; ++i )
	{ 
		scanf( "%d" ,time + i ) ;

		if( i > 0 )
		{
			que.push( -(time[ i - 1 ] = time[ i ] - time[ i - 1 ] - 1) ) ;
		}
	}

	long long sum = N ;	N -= K ;
	for( i = 0 ; i < N ; ++i )
	{
		sum += -que.top() ;	que.pop() ;
	}

	printf( "%lld\n" ,sum ) ;

	return 0 ;
}


Measured memory_bytes: 3408
n,w = map(int,input().split())
dp = [[0]*(w+1) for _ in range(n+1)]
ary = [list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    for j in range(w+1):
        if j >= ary[i][0]:
            dp[i+1][j] = max(dp[i][j],dp[i][j-ary[i][0]]+ary[i][1])
        else:dp[i+1][j] = dp[i][j]
print(dp[n][w])

Measured memory_bytes: 120044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define F first
#define S second

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define maxp 22
#define EPS (ld)(1e-18)
#define mod (int)(1e9+7)
#define INF (ll)((ll)2*1e18)
#define N (int)(1e5+1)
void yesno(bool a){if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
ll power(ll x, ll n, ll m){if(n==0)return 1;ll u=power(x,n/2,m);u=(u*u)%m;if(n%2)u=(u*x)%m;return u;}



int main (){


ll n;
cin>>n;

ll cnt=1;
ll num=26;


while(num<n){
    cnt++;
    n-=num;
    num*=(ll)26;
}

num/=(ll)26;

string ans="";
int i;

for(i=0;i<cnt;i++){
    ll temp=n/num;
    if(n%num)
        temp++;
    temp--;
    ans+=(char)(temp+'a');

    if(i+1<cnt){
        n%=num;
        if(n==0)
            n+=num;
        num/=(ll)26;
    }
}

cout<<ans;



}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b, c;
  cin >> a >> b >> c;
  for (int t = 0; t < 100; ++t) {
    int n = 60 * t + c;
    n %= a + b;
    if (0 <= n and n <= a) {
      cout << 60 * t + c << '\n';
      return 0;
    }
  }
  cout << "-1\n";
}



Measured memory_bytes: 3212
a, b, k = map(int, input().split())

x = b-a
if x < 2*k:
    for i in range(a,b+1):
        print(i)
else:
    for i in range(a, a+k):
        print(i)
    for i in range(b-k+1, b+1):
        print(i)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define fi first
#define se second

int d1[100010], d2[100010];
vector<int> G[100010];
int main(){
	int n, a, b;
	scanf("%d", &n);
	
	for(int i = 0;i < n-1;i++){
		scanf("%d%d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	int ans = n-2;
	queue<P> q;
	q.push(P(1, 1));
	d1[1] = 1;
	while(!q.empty()){
		P p = q.front();q.pop();
		int from = p.fi, cnt = p.se;
		for(int i = 0;i < G[from].size();i++){
			int to = G[from][i];
			if(d1[to] == 0){
				q.push(P(to, cnt+1));
				d1[to] = cnt+1;
			}
		}
	}
	
	q.push(P(n, 1));
	d2[n] = 1;
	while(!q.empty()){
		P p = q.front();q.pop();
		int from = p.fi, cnt = p.se;
		for(int i = 0;i < G[from].size();i++){
			int to = G[from][i];
			if(d2[to] == 0){
				q.push(P(to, cnt+1));
				d2[to] = cnt+1;
				if(d2[to] < d1[to])ans--;
			}
		}
	}
	
	if(n-2-ans < ans)printf("Fennec\n");
	else printf("Snuke\n");
	return 0;
}

Measured memory_bytes: 6720
// ????????¨?????????

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define MAX 30
#define NIL -1

struct Node { int parent, leftChild, rightSibling; };

Node tree[MAX];

void preorder(int root){
    printf(" %d", root);
    if (tree[root].leftChild != NIL)
    {
        preorder(tree[root].leftChild);
    }
    if (tree[root].rightSibling != NIL)
    {
        preorder(tree[root].rightSibling);
    }
}

void inorder(int root){
    if (root == NIL)
    {
        return;
    }
    inorder(tree[root].leftChild);
    printf(" %d", root);
    inorder(tree[root].rightSibling);
}

void postorder(int root){
    if (root == NIL)
    {
        return;
    }
    postorder(tree[root].leftChild);
    postorder(tree[root].rightSibling);
    printf(" %d", root);
}

int main(int argc, char const *argv[])
{
    int numNode;
    int id, left, right;
    cin >> numNode;

    // initialization
    for (int i = 0; i < numNode; ++i)
    {
        tree[i].parent = NIL;
    }

    // store the values
    for (int i = 0; i < numNode; ++i)
    {
        scanf("%d %d %d", &id, &left, &right);
        tree[id].leftChild = left;
        tree[id].rightSibling = right;
        if (left != NIL)
        {
            tree[left].parent = id;
        }
        if (right != NIL)
        {
            tree[right].parent = id;
        }
    }
    // find the root
    int root;
    for (int i = 0; i < numNode; ++i)
    {
        if (tree[i].parent == NIL)
        {
            root = i;
        }
    }
    // print
    printf("Preorder\n");
    preorder(root);
    printf("\n");
    printf("Inorder\n");
    inorder(root);
    printf("\n");
    printf("Postorder\n");
    postorder(root);
    printf("\n");

    return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef pair<pl, ll> ppl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll s;
  cin >> s;

  vvl BC(2001, vl(2001));
  BC[0][0] = 1;
  rep(i, 2001) rep(j, i+1) {
      if(j>0) BC[i][j] += BC[i-1][j-1];
      if(j<i) BC[i][j] += BC[i-1][j];
      BC[i][j] %= MOD;
  }

  ll ans = 0;
  rep2(num, 1, s/3) {
      ans += BC[s-2*num-1][num-1];
      ans %= MOD;
  }
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 34580
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(r.readLine());

		String[] s = new String[n];
		for (int i = 0; i < n; ++i) {
			s[i] = r.readLine();
		}

		long c = Arrays.stream(s).distinct().count();
		System.out.println(c);

		r.close();
	}
}

Measured memory_bytes: 67492
#include <iostream>
using namespace std;
int main(){
  char str[4] ;
  int i1 ;
  cin >> str ;
  if ( str[0] == str [1] ){
    i1++;
  }
  if ( str[0] == str [2] ){
    i1++;
  }
  if ( str[0] == str [3] ){
    i1++;
  }
  if ( str[1] == str [2] ){
    i1++;
  }
  if ( str[1] == str [3] ){
    i1++;
  }
  if ( str[2] == str [3] ){
    i1++;
  }
  if ( i1 == 2 ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}
  


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

typedef long double ld;

bool vis[301][301][301];
ld memo[301][301][301];
int n,ctr[4];

ld SUSHI(int x1, int x2, int x3)
{
	if((x1 < 0) || (x2 < 0) || (x3 < 0))
	return 0;
	else if((x1 == 0) && (x2 == 0) && (x3 == 0))
	return 0;
	if(vis[x1][x2][x3])
	return memo[x1][x2][x3];
	ld ans = 0;
	ans = ((((ld)x1) * SUSHI(x1-1, x2, x3)) + (((ld)x2) * SUSHI(x1+1, x2-1, x3)) + (((ld)x3) * SUSHI(x1, x2+1, x3-1)) + ((ld)n))/((ld)(x1 + x2 + x3));
	vis[x1][x2][x3] = 1;
	memo[x1][x2][x3] = ans;
	return ans;	
}

int main(void)
{
	memset(vis, 0, sizeof(vis));
	scanf("%d", &n);
	for(int i=0;i<n;i++)
	{
		int x;
		scanf("%d", &x);
		ctr[x]++;
	}	
	ld ans = SUSHI(ctr[1], ctr[2], ctr[3]);
	printf("%.15Lf\n", ans);
	return 0;
}

Measured memory_bytes: 452992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

class UnionFind{
public:
    UnionFind(int n){
        size = n;
        parent = vector<int>(size,-1);
    }
    int getSize(){return size;}
    int getParentElement(int index){return parent[index];}
    int getGroupSize(int index){return abs(getParentElement(find(index)));}
    bool isSame(int x, int y){return find(x)==find(y);}
    void printParent(){
        for(auto v: parent) {cout << v << " ";}
        cout << endl;
    }
    int find(int x){
        int a = x;
        vector<int> children;
        while(parent[a]>=0){
            children.push_back(a);
            a = parent[a];
        }
        for(auto child: children){parent[child] = a;}
        return a;
    }
    int Union(int x, int y){
        int root_x = find(x);
        int root_y = find(y);
        if(root_x != root_y){
            if(parent[root_x]>=parent[root_y]){
                parent[root_x] += parent[root_y];
                parent[root_y] = root_x;
            }else{
                parent[root_y] += parent[root_x];
                parent[root_x] = root_y;
            }
        }
        return parent[root_x];
    }
private:
    int size;
    vector<int> parent;
};

int main(){
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    int x, y, z;
    for(int i = 0; i < m; i++){
        cin >> x >> y >> z;
        x--; y--;
        uf.Union(x,y);
    }
    set<int> ans;
    for(int i = 0; i < n; i++){
        ans.insert(uf.find(i));
    }
    cout << ans.size() << endl;
    return 0;

}


Measured memory_bytes: 5376
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <ctime>
#define LL long long
#define inf 0x3f3f3f3f
#define PII pair<int,int>
#define lson rt<<1
#define rson rt<<1|1
#define test freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
using namespace std;
int n,m;
struct nod
{
    int v,sz,st;
}a[1005];
int dp[1005][1<<13|3];
void input()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;++i)
    {
        scanf("%d%d",&a[i].v,&a[i].sz);
        int num=0,t;
        for(int j=0;j<a[i].sz;++j)
        {
            scanf("%d",&t);
            --t;
            num|=(1<<t);
        }
        a[i].st=num;
    }
}
int main()
{
    input();
    memset(dp,inf,sizeof(dp));
    dp[0][a[0].st]=a[0].v;
    dp[0][0]=0;
    int S=1<<n;
    for(int i=1;i<m;++i)
    {
        for(int j=0;j<S;++j) dp[i][j]=dp[i-1][j];
        for(int j=0;j<S;++j)
        {
            dp[i][j|a[i].st]=min(dp[i-1][j]+a[i].v,dp[i][j|a[i].st]);
            //dp[i][j|a[i].st]=min(dp[i-1][j|a[i].st],dp[i][j|a[i].st]);
        }
    }
    if(dp[m-1][S-1]>=inf) cout<<-1;
    else printf("%d",dp[m-1][S-1]);
    return 0;
}


Measured memory_bytes: 32512
n, m = map(int, input().split())
l = []
for i in range(m):
    a, b = map(int, input().split())
    l.append((b, a))
l.sort()
answer = 0
last = 0
for b, a in l:
    if a >= last:
        answer += 1
        last = b
print(answer)


Measured memory_bytes: 18592
#include<stdio.h>

int V[101][101]={0};
int d[101]; // 発見時刻
int f[101]; // 完了時刻
int time=0;

void dfs(int,int);

int main()
{
  int i,j;
  int n,u,k,v;
 
  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%d%d",&u,&k);
      for(j=0;j<k;j++)
	{
	  scanf("%d",&v);
	  V[u][v]=1;
	}
    }

  for(i=0;i<n;i++)
    {
    if(d[i+1]==0) dfs(i+1,n);
    }

  for(i=0;i<n;i++)
    {
      printf("%d %d %d\n",i+1,d[i+1],f[i+1]);
    }

  return 0;
}

void dfs(int i, int n)
{
  int j;
  d[i] = ++time;
  for(j=0;j<n;j++){
    if(V[i][j+1] != 1) continue;
    else V[i][j+1] = 0;
    
    if(d[j+1] == 0) dfs(j+1, n); // 再起
  }
  f[i] = ++time;
}



Measured memory_bytes: 2088
#coding=UTF-8

N=int(input())
mozir=input()

hyo=mozir.split(' ')
p=[int(mono)-1 for mono in hyo]

kaburi=[]
for idx in range(0,N,1):
    if p[idx]==idx:
        kaburi.append(True)
    else:
        kaburi.append(False)


kaburi.append(False)
idy=0
ans=0
while idy < N:
    if kaburi[idy]:
        idy+=2
        ans+=1
    else:
        idy+=1

print(ans)


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

int main() {
  int A, B;

  cin >> A >> B;

  int count = 0;
  for (int i = A; i <= B; i++) {
    int tmp = i;
    int i4, i3, i2, i1, i0;

    i4 = tmp / 10000; tmp = tmp - (i4 * 10000);
    i3 = tmp /  1000; tmp = tmp - (i3 * 1000);
    i2 = tmp /   100; tmp = tmp - (i2 * 100);
    i1 = tmp /    10; tmp = tmp - (i1 * 10);
    i0 = tmp;

    if ((i4 == i0) && (i3 == i1)) count++;
  }

  cout << count << endl;
}


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

int main(){
	string S;
	cin >> S;
	vector<string> vec{ "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN" };
	
	for (int i = 0; i < 7; i++) {
		if (vec.at(i) == S) {
			cout << i + 1 << endl;
		}
	}
}

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

WHITE = '.'
BLACK = '#'

b_num = 0
w_num = S.count(WHITE)
ans = b_num + w_num
for v in S:
    if v == BLACK:
        b_num += 1
    else:
        w_num -= 1
    ans = min(ans, b_num + w_num)

print(ans)


Measured memory_bytes: 3500
# coding: utf-8
# Your code here!

# ITP1_6_D

matrix=list()
col=list()
y,x=map(int,input().split())

for _ in range(y):
    matrix.append(list(map(int,input().split())))

for _ in range(x):
    col.append(int(input()))

for j in range(y):
    result=0
    for i in range(x):
        result+=matrix[j][i]*col[i]
    print(result)


Measured memory_bytes: 6008
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define MOD 1000000007
typedef long long ll;
using namespace std;
int main()
{
	ll N; cin >> N;
  	vector<double> v(N);
  	for (ll i = 0; i < N; i++){
    	cin >> v[i];
    }
  	vsort(v);
  	for (ll i = 0; i < N - 1; i++){
    	v[i + 1] = (v[i] + v[i + 1]) / 2;
    }
  	cout << v[N - 1] << endl;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int> > mtr(n, vector<int>(m));
    vector<int> vec(m);
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> mtr[i][j];
        }
    }
    for(int i=0; i<m; i++){
        cin >> vec[i];
    }

    for(int i=0; i<n; i++){
        int ret=0;
        for(int j=0; j<m; j++){
            ret += mtr[i][j]*vec[j];
        }
        cout << ret << endl;
    }
    return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long

signed main() {
    int q,h,s,d;
    cin >> q >> h >> s>> d;
    int n;
    cin >> n;
    int qq = 8*q;
    int hh = 4*h;
    int ss = 2*s;
    int mi = min(qq,min(hh,min(ss,d)));
    int ans = n/2*mi;
    if(n%2==1) {
        qq = 4*q;
        hh = 2*h;
        mi = min(qq,min(hh,s));
        ans += mi;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3576
N, K = list(map(int, input().split()))
S = [1 if x=='R' else -1 for x in input()]
cnt = 0
rule = S[0]
f = False
for i in range(1, N):
    if S[i] != rule:
        f = True
        S[i] *= -1
    else:
        if f:
            f = False
            cnt += 1
    if cnt >= K:
        break

S.insert(0, 1)
S.append(-1)
ans = 0
for i in range(N):
    x = S[i+1]
    y = S[i+1+x]
    if x == y:
        ans += 1

print(ans)

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i,n) for(ll i=0; i<(n); i++)
#define forn for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'
#define FILL(x,v) memset(x,v,sizeof(x))
#define pb push_back
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}
template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

void solve(){
	int n, a, b;
	cin >> n;
	cin >> a >> b;
	if(b-a >= n) {
		cout << "OK" << en;
		return ;
	}
	for(int i=a; i<=b&&i<=a+n; i++){
		if(i%n==0){
			cout << "OK" << en;
			return;
		}
	}
	cout << "NG" << en;
}

int main(){
	fast;
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	solve();
    return 0;
}

Measured memory_bytes: 3656
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))
X = []
Y = []
i = 0
for i in range(N):
    if V[i] >= C[i]:
        X.append(V[i])
        Y.append(C[i])
        i += 1
    else:
        i += 1
print(sum(X) - sum(Y))



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

using namespace std;

const int N = 310;

char s[N];
int f[N][N][N];

int main() {
  int m;
  scanf("%s %d", s + 1, &m);
  int n = (int)strlen(s + 1);
  memset(f, 0, sizeof f);
  for (int i = 1; i <= n; ++i) {
    for (int j = n; j >= i; --j) {
      for (int k = 0; k <= m; ++k) {
        f[i][j][k] = max(f[i][j][k], f[i - 1][j + 1][k] + 2 * (s[i] == s[j]) - (j == i));
        f[i][j][k] = max(f[i][j][k], f[i - 1][j][k]);
        f[i][j][k] = max(f[i][j][k], f[i][j + 1][k]);
      }
      for (int k = 1; k <= m; ++k) {
        f[i][j][k] = max(f[i][j][k], f[i - 1][j + 1][k - 1] + 2 - (j == i));
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; ++j) {
      for (int k = 0; k <= m; ++k) {
        ans = max(ans, f[i][j][k]);
      }
    }
  }
  printf("%d\n", ans);
}


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

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

def find(x, k):
    while x != None and k != x.key:
        if k < x.key:
            x = x.left
        else:
            x = x.right
    return x
    
def delete(root, z):
    if z.left == None or z.right == None:
        y = z
    else:
        y = getSuccessor(z)
    
    if y.left != None:
        x = y.left
    else:
        x = y.right
        
    if x != None:
        x.parent = y.parent
    
    if y.parent == None:
        root = x
    elif y == y.parent.left:
        y.parent.left = x
    else:
        y.parent.right = x
    
    if y != z:
        z.key = y.key

def getSuccessor(x):
    if x.right != None:
        return getMinimum(x.right)
    y = x.parent
    while y != None and x == y.right:
        x = y
        y = y.parent
    return y

def getMinimum(x):
    while x.left != None:
        x = x.left
    return x
    
def printInOrder(z):
    if z == None:
        return
    if z.left != None:
        printInOrder(z.left)
    inorder.append(str(z.key))
    #print(z.key, end = " ")
    if z.right != None:
        printInOrder(z.right)
        
def printPreOrder(z):
    if z == None:
        return
    #print(z.key, end = " ")
    preorder.append(str(z.key))
    if z.left != None:
        printPreOrder(z.left)
    if z.right != None:
        printPreOrder(z.right)

root = None


n = int(input())
for i in range(n):
    command = input()
    if command[0] == "i":
        com,num = command.split()
        z = Node(int(num))
        insert(root, z)
        if root == None:
            root = z
    elif command[0] == "f":
        com,num = command.split()
        z = Node(int(num))
        x = find(root, int(z.key))
        if x != None:
            print("yes")
        else:
            print("no")
    
    elif command[0] =="d":
        com,num = command.split()
        z = Node(int(num))
        delete(root, find(root, int(z.key)))
    

    else:
        inorder = []
        printInOrder(root)
        print(" ", end = "")
        print(' '.join(inorder))
        preorder = []
        printPreOrder(root)
        print(" ", end = "")
        print(' '.join(preorder))







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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (a); i < (n); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  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: 256
#include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
     
     
    void copy(char *to,char *from,int n){
    	int i;
    	for(i=0;i<6;i++){
    		if(i<n)	to[i] = from[i];
    		else to[i] = '\0';
    	}
    }
     
     
    int check(char *a,char *b){
    	int i;
    	for(i=0;i<5;i++){
    		if(a[i] < b[i])			return -1;	//a -> b
    		else if (a[i] > b[i])	return 1;	//b -> a
    	}
    	return 0;	//a == b
    }
     
    int int_sort( const void * a , const void * b ) {
      return strcmp(( char * )a , ( char * )b );
    }
     
    int main(void){
    	char s[5001];
    	int K;
    	int i,j;
    	scanf("%s",s);
    	scanf("%d",&K);
    	
    	char kouho[25000][6];
    	int index = 0;
    	
    	
    	for(i=0;s[i] != '\0';i++){
    		for(j=1; s[i+j-1] != '\0' ;j++){
    			if(j>5) break;
    			copy(kouho[index],&s[i],j);
    			index++;
    		}
    	}
    		
    	
    	qsort(kouho,index,sizeof(kouho[0]),int_sort);
     
    	int ex[25000];
    	for(i=0;i<25000;i++){
    		ex[i] = 1;
    	}
    	for(i=0;i<index;i++){
    		if(check(kouho[i],kouho[i+1]) == 0){
    			ex[i+1] = -1;
    		}
    	}
    	
    		
    	int count = 0,flag = 0;
    	i = 0;
    	while(flag <= K){
    		if(ex[i] > 0){
    			count = i;
    			flag++;
    		}
    		i++;
    	}
    	
    	
    	printf("%s",kouho[count-1]);
    	
    	
    	return 0;}

Measured memory_bytes: 508
use std::io::*;
use std::str::FromStr;
 
fn abc(n: i32, y: i32) -> Vec<i32> {
    let mut result = vec![];
 
    for i in (0..n+1) {
        for j in (0..n-i+1) {
            let k = n-i-j;
            if (10*i + 5*j + k == y/1_000) {
                result.extend_from_slice(&[i, j, k]);
                return result;
            }
        }
    }
    result.extend_from_slice(&[-1, -1, -1]);
    return result
}
 
fn main() {
    
    //assert_eq!(abc(9, 45_000), vec![4, 0, 5]);
    //assert_eq!(abc(20, 196_000), vec![-1, -1, -1]);
    //assert_eq!(abc(1_000, 1_234_000), vec![2, 54, 944]);
    //assert_eq!(abc(2_000, 20_000_000), vec![2_000, 0, 0]);
 
    
    let n: i32 = read();
    let y: i32 = read();
 
    let result = abc(n, y);
 
    println!("{}", result.iter().fold(String::new(), |acc, &num| acc + &num.to_string() + " "));
}
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
from collections import deque

n,m = map(int,input().split())

up = [[] for i in range(n)]
down= [[]for i in range(n)]
for i in range(n+m-1):
    a,b = map(int,input().split())
    a -=1
    b -=1
    up[b].append(a)
    down[a].append(b)

res = [-1]*n
root = -1

for i in range(n):
    if len(up[i])==0:
        res[i] = 0
        root = i
        break

#0なら不使用
used = [0]*n
used[root]=1

#yの親に不使用が一つも存在しなければTrue
def g(y):
    for pe in up[y]:
        if used[pe]==0:
            return False
    return True
    
#zの下のusedとresを埋める
def f(z):
    for e in down[z]:
        if used[e]==0 and g(e):
            res[e]=z+1
            tank2.append(e)
            usedtank.append(e)

#c : 確定した点の数            
c = 1
tank = deque([root])
tank2 = deque([root])
usedtank = []

while c != n:
    tank = tank2
    tank2 = deque([])
    usedtank = []
    while len(tank)!=0:
        f(tank.popleft())
    for e_used in usedtank:
        used[e_used]=1
    c += len(tank2)
    
for i in range(n):
    print(res[i])


Measured memory_bytes: 38944
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys

t = [int(s) for s in stdin.readline().rstrip().split()]
n = t[0]
m = t[1]
x = t[2]

data = []
for el in range(n):
    tmp = [int(s) for s in stdin.readline().rstrip().split()]
    skills = []
    count = 0
    for el2 in tmp:
        if count > 0:
            skills.append(el2)
        count += 1
    data.append({'price': tmp[0], 'skills': skills})

num = 0
priceSum = sys.maxsize
while True:
    status = [int(s) for s in'0'*m]
    price = 0
    para = [int(s) for s in str(format(num, 'b'))]
    pp = [int(s) for s in(n - len(para)) * '0']
    pp.extend(para)

    tim = 0
    for el in pp:
        if (el == 1):
            price += data[tim]['price']
            status = list(map(lambda x, y: x+y, status, data[tim]['skills']))
        tim += 1
    else:
        for el in status:
            if (el < x):
                break
        else:
            if (priceSum > price):
                priceSum = price
    if all(pp):
        break
    num += 1
if priceSum == sys.maxsize:
    print(-1)
else:
    print(priceSum)


Measured memory_bytes: 74704
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	vector<int> a(100,0);
	int n;
	while(cin>>n){
		a[n-1]++;
	}
	int num=0;
	for(int i=0;i<100;i++){
		num = max(num,a[i]);
	}
	for(int i=0;i<100;i++){
		if(a[i] == num) cout<< i+1<< endl;
	}
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

Measured memory_bytes: 1196
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
ans = -float("inf")
for i in range(1,2**10):
    res = 0
    for j in range(n):
        tnp = 0
        for k in range(10):
            if ((i>>k)&1):
                if (f[j][k]==1):
                    tnp += 1
        res += p[j][tnp]
    ans = max(ans,res)
print(ans)

Measured memory_bytes: 68612
#include<vector>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<cctype>
#include<cassert>
#include<cmath>
#include<climits>

#define INF (1<<29)
#define all(c) (c).begin(),(c).end()
#define D(x) cout << #x " is " << (x) << endl
#define is_palindrome(c) equal((c).begin(),(c).end(),(c).rbegin())
#define rep(i,n) for(int i = 0; i < n; i++)
#define foreach(it,c) for(__typeof__((c).begin()) it=(c).begin();it!=(c).end();it++)
#define x first
#define y second

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef pair<int,int>pii;
typedef pair<int,pii>piii;

string toStr(int num){
  if(num==0)return "0";
  string res = "";
  while(num){
    res+=(num%10)+'0';
    num/=10;
  }
  reverse(res.begin(),res.end());
  return res;
}

int toInt(string s){return atoi(s.c_str());}

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

ll dp[1001][1001];

int main(void){
  
  int n;
  cin >> n;

  vector<pii>v(n);
  rep(i,n)cin >> v[i].x >> v[i].y;


  fill(dp[0],dp[1001],INT_MAX);

  rep(i,1001)dp[i][i]=0;
  
  for(int w=0;w<n;w++){
    for(int i=0;i+w<n;i++){
      for(int s=i;s<i+w;s++){
	ll cost=abs(v[i].x-v[s+1].x)+abs(v[s].y-v[i+w].y);
	dp[i][i+w]=min(dp[i][i+w],dp[i][s]+dp[s+1][i+w]+cost);
      }
    }
  }

  cout << dp[0][n-1] << endl;
  
  return 0;
}

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

int main() {
  int N, temp, d, sum, denominator;

  cin >> N;
  
  temp = 0;
  sum = 0;
  
  for(int i = 8; i >= 0; i--) {
    
    denominator = 1;
    for(int j = 0; j < i; j++) {
      denominator *= 10;
    }
    
    d = (N - temp) / denominator;
    temp += d * denominator;
    sum += d;
  }
  
  if((N % sum) == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

using namespace std;

int main()
{
	int n;
	long long x;
	vector<long long> a;
	
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> x;
		a.push_back(x);
	}

	sort(a.begin(), a.end());

	int cnt = 1;
	for (int i = 0; i < n-1; i++) {
		if (a[i] < a[i + 1]) {
			cnt++;
		}		
	}

	cout << cnt << endl;
}

Measured memory_bytes: 256
let n, l = Scanf.scanf " %d %d" @@ fun a b -> a, b
let sum = n * (2 * l + n - 1) / 2
let _ =
  Array.init n (fun i -> l + i) |> Array.fold_left (fun m v -> if abs v < abs m then v else m) max_int
  |> (-) sum |> Printf.printf "%d\n"

Measured memory_bytes: 384
N, M = map( int, input().split())
X = list( map( int, input().split()))
X.sort()
XS = [0]*(M-1)

if N >= M:
    print(0)
else:
    for i in range(M-1):
        XS[i] = X[i+1] - X[i]
    XS.sort( key = None, reverse = True)
    ans = X[-1] - X[0]
    ans -= sum( XS[:N-1])
    print(ans)

Measured memory_bytes: 13960
#include <bits/stdc++.h>
#define repl(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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() {
    string s;
    cin >> s;
    ll n = s.length();
    ll temp = 0;
    vector<ll> a(n+1,0);
    rep(i,n){
        if(s[i] == '<')++temp;
        else temp = 0;
        a[i+1] = temp;
    }
    temp = 0;
    per(i,n-1){
        if(s[i] == '>')temp++;
        else temp = 0;
        a[i] = max(a[i],temp);
    }
    cout << accumulate(a.begin(),a.end(),0LL) << endl;
    return 0;
}

Measured memory_bytes: 4740
#include<bits/stdc++.h>
#include<algorithm>
using namespace std; 
#define float double
const int  LMT =1000000000+5;
#define int long long 
#define lp(i,n) for( i=0;i<n;i++)
const int N=105,M=100005;
int n,m,a[N],i,j,k;
int dp[M];bool vis[N][M];
void solve(){

for(int i=0;i<=k;i++ ){
  if(dp[i])continue;
  for(int j=0;j<n;j++)
    if(a[j]+i<=k)dp[a[j]+i]=1;
}
}
int32_t main(){
  #ifndef ONLINE_JUDGE 
  freopen("input.txt", "r", stdin); 
  freopen("output.txt", "w", stdout); 
 #endif
 cin>>n>>k;
 memset(dp,0,sizeof(dp));
 lp(i,n){cin>>a[i];dp[a[i]]=1;}
 solve();
 cout<<(dp[k]?"First":"Second")<<endl;
} 

Measured memory_bytes: 4408
import Control.Monad

main = do
    fst <- getLine
    let [n, m, c] = map read (words fst)
    snd <- getLine
    let bs = map read (words snd) :: [Int]
    thd <- replicateM n getLine
    let as = map (map read) (map words thd) :: [[Int]]
    let y = ans as bs c
    print y

hantei :: [Int] -> [Int] -> Int -> Int
hantei a bs c = (sum $ zipWith (*) a bs) + c

ans :: [[Int]] -> [Int] -> Int -> Int
ans (a:[]) bs c
    | hantei a bs c > 0 = 1
    | otherwise = 0
ans (a:as) bs c
    | hantei a bs c > 0 = (ans as bs c) + 1
    | otherwise = ans as bs c


Measured memory_bytes: 1020
import itertools
import math
N = int(input())
xy = [map(int, input().split()) for _ in range(N)]
x, y = [list(i) for i in zip(*xy)]
l=[]
for i in range(0,N):
    l.append(i)
p=list(itertools.permutations(l,N))
z=0
for j in range(0,len(p)):
    for k in range(0,N-1):
        z=z+math.sqrt(pow(x[p[j][k]]-x[p[j][k+1]],2)+pow(y[p[j][k]]-y[p[j][k+1]],2))
ans=z/len(p)
print(ans)


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

int N, M, dp[100009], in[100009];
vector<int> G[100009];

int main() {
    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--; // 0-indexed にする
        G[x].push_back(y);
        in[y]++;
    }

    queue<int> que;
    for(int i = 0; i < N; i++)
        if(in[i] == 0) que.push(i);

    while(!que.empty()) {
        int u = que.front();
        que.pop();
        for(int v : G[u])
            if(--in[v] == 0) {
                que.push(v);
                dp[v] = dp[u] + 1;
            }
    }

    int res = 0;
    for(int i = 0; i < N; i++)
        res = max(res, dp[i]);

    cout << res << endl;

    return 0;
}

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

int main() {
	char s;
	cin >> s;
	int a = s - '0';
	a++;
	char c = '0' + a;
	cout << c << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main (){

    int a, h, m, s;

    cin >> a;

    h = a / 3600;
    m = a % 3600 / 60;
    s = a % 3600 % 60;

    cout << h << ":" << m << ":" << s << endl;

    return 0;
}

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

int main(){
  string s;
  cin>>s;
  int a[26];
  for(int i=0; i<26; ++i){
    a[i]=-10;
  }
  //a 49
  for(int i=0; i<s.size(); ++i){
    int b,c;
    b=s[i]-'0';
    b-=49;
    c=a[b];
    if(i!=-10 && i-c<=2){
      cout<<c+1<<" "<<i+1<<endl;
      return 0;
    } else {
      a[b]=i;
    }
  }
  cout<<-1<<" "<<-1<<endl;
  return 0;
}


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

using i64 = int64_t;

int main(){
    int n, k;
    cin >> n >> k;
    int m = (n-1) * (n-2) / 2;
    if(k > m){
        cout << -1 << endl;
        return 0;
    }
    int e = 0;
    vector<vector<int>> graph(n+1, vector<int>());
    for(int i=2;i<=n;++i){
        graph[1].push_back(i);
        e++;
    }
    while(m > k){
        for(int i=2;i<=n;++i){
            for(int j=i+1;j<=n;++j){
                graph[i].push_back(j);
                m--;
                e++;
                if(m <= k)break;
            }
            if(m <= k)break;
        }
    }
    cout << e << endl;
    for(int i=1;i<=n;++i){
        for(auto to: graph[i]){
            cout << i << " " << to << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.util.*;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import static java.util.stream.Collectors.*;
import static java.util.Map.Entry.*;

public class Main {

	public static void main(String[] args) throws IOException {
		FastReader in = new FastReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int sum = 0;
		int max = 0;
		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			sum += x;
			max = Math.max(max, x);
		}
		out.write((sum -max > max) ? "Yes" : "No");
		out.close();

	}

	static class FastReader {
		StringTokenizer st;
		BufferedReader br;

		public FastReader(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public FastReader(FileReader fileReader) {
			br = new BufferedReader(fileReader);
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = nextInt();
			}
			return ret;
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}

}

Measured memory_bytes: 22484
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
	int n, a, b;
	int ans = 0;

	cin >> n >> a >> b;

	REP(i, n + 1){
		string s = to_string(i);
		int len = (int)s.size();
		int sum = 0;

		while (len){
			sum += (s[--len] - '0');
		}

		if (a <= sum && sum <= b){
			ans += i;
		}

	}

	cout << ans << endl;

}


Measured memory_bytes: 256
//98tarunkumar
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rlop(i,n) for(int i=n;i>0;i--)
#define lli long long int
#define sf ios::sync_with_stdio(false); cin.tie(NULL);
#define ainp(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define aout(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";
#define f(i, a, b) for(int i=a; i<b; i++)
#define lop(a,b) for(int i=a;i<b;i++)
#define ln cout<<"\n"
#define MOD 1e9+7

int main()
{ 
   	sf;
   

    lli n;
    cin>>n;
    lli a[n];
    ainp(a,n)
    lli s=0;
    lli ma=a[0];
    for(int i=1;i<n;i++){
    	if(a[i]>=ma)
    		ma=a[i];
    	s+=ma-a[i];
    }
    cout<<s;

}

Measured memory_bytes: 5224
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<ctime>
#include<vector>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long LL;
const double pi=3.141592653;
const double eps=1e-10;
const int INF=0x3f3f3f3f;
const int MOD=10007;
const int MAXN=220;
struct people
{
    double pp[MAXN],time[MAXN];
} peo[MAXN];

int n,m,L,p[MAXN],t[MAXN],v[MAXN];
LL Com[MAXN][MAXN];

int main()
{
    Com[0][0]=1;
    for(int i=1;i<=50;i++)
    {
        Com[i][0]=Com[i-1][0];
        for(int j=1;j<=i;j++)
            Com[i][j]=Com[i-1][j]+Com[i-1][j-1];
    }
    while(scanf("%d%d%d",&n,&m,&L)!=EOF)
    {
        for(int i=0; i<n; i++)
            scanf("%d%d%d",&p[i],&t[i],&v[i]);
        for(int i=0; i<n; i++)
            for(int j=0; j<=m; j++)
            {
                double x=Com[m][j];
                int k;
                for(k=1;k<=j;k++)
                    x*=p[i]/100.0;
                for(;k<=m;k++)
                    x*=(100-p[i])/100.0;
                peo[i].pp[j]=x;
                peo[i].time[j]=(L+0.0)/v[i]+j*t[i];
            }
        for(int i=0; i<n; i++)
        {
            double ans=0;
            for(int j=0; j<=m; j++)
            {
                double tmp=1;
                for(int k=0; k<n; k++)
                {
                    if(k==i)
                        continue;
                    double x=0;
                    for(int l=0; l<=m; l++)
                        if(peo[k].time[l]>peo[i].time[j])
                            x+=peo[k].pp[l];
                    tmp*=x;
                }
                ans+=tmp*peo[i].pp[j];
            }
            printf("%.8lf\n",ans);
        }
    }
    return 0;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int A, B;
    int H, M;
    cin >> A >> B >> H >> M;
    complex<double> a(A), b(B);
    double h = H + M / 60.0;
    a *= polar(1.0, 2 * M_PI * h / 12);
    b *= polar(1.0, 2 * M_PI * h);
    cout << abs(a - b) << endl;
}

Measured memory_bytes: 4096