akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  string Sa, Sb, Sc;
  cin >> Sa >> Sb >> Sc;

  char now = 'a';
  int a = 0;
  int b = 0;
  int c = 0;
  while (true) {

    if (now == 'a') {
      if (a == Sa.size()) {
        cout << "A" << endl;
        break;
      }

      now = Sa[a];
      a++;
    } else if (now == 'b') {
      if (b == Sb.size()) {
        cout << "B" << endl;
        break;
      }

      now = Sb[b];
      b++;
    } else {
      if (c == Sc.size()) {
        cout << "C" << endl;
        break;
      }

      now = Sc[c];
      c++;
    }
  }

  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T Read(T)() { return readln.chomp.to!(T); }
T[] Reads(T)() { return readln.split.to!(T[]); }
alias read = Read!(int);
alias reads = Reads!(int);

int[][] c;

void main() {
    int n = read();
    foreach (i;0..n) c ~= reads();
    long s;
    foreach (i; 0..n) foreach (j; 0..n)
        if (i < j) s += min(c[i][j], c[j][i]);
    writeln(s);
}


Measured memory_bytes: 2920
x,n=map(int, input().split())
if n==0:
    print(x)
    exit()
p=list(map(int, input().split()))

dl=[abs(x-i) for i in p]


for i in range(101):
    c=dl.count(i)

    if i==0:
        if c==1:
            continue
        else:
            print(x)
            exit()

    if c==0:
        print(x-i)
        exit()
    elif c>=2:
        continue
    else:
        b=dl.index(i)
        print(x-(p[b]-x))
        exit()


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<int>> a(w,vector<int>(h));
  rep(i,h){
      string s;
      cin >> s;
      rep(j,w){
          if (s[j]=='.') a[j][i]=0;
          else a[j][i]=1;
      }
  }
  vector<vector<int>> b(w,vector<int>(h,inf));
  queue<pp> q;
  q.push(mk(0,0));
  if (a[0][0]==1) b[0][0]=1;
  else b[0][0]=0;
  while(!q.empty()){
      int f=q.front().first,g=q.front().second;
      q.pop();
      if (a[f][g]%2==0){
      if (f+1<w){
          if (a[f+1][g]==0 && b[f+1][g]>b[f][g]){
              b[f+1][g]=b[f][g];
              q.push(mk(f+1,g));
          }
          if (a[f+1][g]==1 && b[f+1][g]>b[f][g]+1){
              b[f+1][g]=b[f][g]+1;
              q.push(mk(f+1,g));
          }
      }
      if (g+1<h){
          if (a[f][g+1]==0 && b[f][g+1]>b[f][g]){
              b[f][g+1]=b[f][g];
              q.push(mk(f,g+1));
          }
          if (a[f][g+1]==1 && b[f][g+1]>b[f][g]+1){
              b[f][g+1]=b[f][g]+1;
              q.push(mk(f,g+1));
          }
      }
      }
      else{
          if (f+1<w){
          if (a[f+1][g]==1 && b[f+1][g]>b[f][g]){
              b[f+1][g]=b[f][g];
              q.push(mk(f+1,g));
          }
          if (a[f+1][g]==0 && b[f+1][g]>b[f][g]+1){
              b[f+1][g]=b[f][g]+1;
              q.push(mk(f+1,g));
          }
      }
      if (g+1<h){
          if (a[f][g+1]==1 && b[f][g+1]>b[f][g]){
              b[f][g+1]=b[f][g];
              q.push(mk(f,g+1));
          }
          if (a[f][g+1]==0 && b[f][g+1]>b[f][g]+1){
              b[f][g+1]=b[f][g]+1;
              q.push(mk(f,g+1));
          }
      }
      }
  }
  cout << (b[w-1][h-1]+1)/2 << endl;
}


Measured memory_bytes: 384
R,G,B,N = map(int,input().split())
ans = 0
for r in range(N+1):
  if r*R>N:
    break
  for g in range(N+1):
    S = N-r*R-g*G
    if S<0:
      break
    elif S%B==0:
      ans+=1
print(ans)

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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;
using vb=vector<bool>;using vs=vector<string>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template<typename T>T read(){T t;cin>>t;return t;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){o<<'('<<p.fst<<", "<<p.snd<<')';return o;}

ll solve() {
  int i, o, t, j, l, s, z;
  cin >> i >> o >> t >> j >> l >> s >> z;

  ll ret = 0;

  ret += o;

  if (j%2 + l%2 + i%2 >= 2 && j && l && i) {
    ret += 3;
    j--;
    l--;
    i--;
  }
  ret += (j / 2) * 2;
  ret += (l / 2) * 2;
  ret += (i / 2) * 2;

  return ret;
}
void Main() { cout << solve() << endl; }
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if (abs(a - c) <= d) {
        cout << "Yes" << endl;
    } else if (abs(a - b) <= d && abs(b - c) <= d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import sys;sys.setrecursionlimit(int(1e7))

N = int(input())
ABC = [tuple(map(int,input().split())) for _ in range(N-1)]
Q,K = map(int,input().split())
XY = [tuple(map(int,input().split())) for _ in range(Q)]

tree = [[] for _ in range(N+1)]

for abc in ABC:
    tree[abc[0]].append([abc[1],abc[2]])
    tree[abc[1]].append([abc[0],abc[2]])

def DFS(v,p,d):
    for e in tree[v]:
        e.append(d)
        if e[0] != p:
            DFS(e[0], v, d + e[1])

DFS(K,0,0)

for i in range(Q):
    print(tree[XY[i][0]][0][2] + tree[XY[i][1]][0][2])


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

namespace ABCO087B
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, a, b, c;

            x = int.Parse(Console.ReadLine());
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());

            c = (x - a) % b;

            Console.WriteLine(c);

            Console.ReadKey();































        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define INF 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	int a,b,c;
	cin>>a>>b>>c;
	// int sum=0;
	int flag=0;
	for(int i=1;i<=300;i++)
	{
		// flag=0;
		// sum=0;
		// for(int j=1;j<=i;j++)
		// 	sum+=a*j;
		if((a*i)%b==c)
		{
			flag++;
			cout<<"YES"<<endl;
			break;
		}
	}
	if(!flag)
		cout<<"NO"<<endl;
	return 0;
}

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

#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, 1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define dbg(x) cout << "Line " << __LINE__ <<": " << x << nl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl "\n"
#define sp " "

#define _ ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define file() freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout), cout << "File" << nl

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

const int N = 305;

int tc = 1;

int n;

unordered_map<string, int> cnt;
string s;

int main(){_

    //file();

    //cin >> tc;

    while(tc--){

        cin >> n;

        while(n--){
            cin >> s;
            cnt[s]++;
        }

        cout << "AC x "<<cnt["AC"]<<nl;
        cout << "WA x "<<cnt["WA"]<<nl;
        cout << "TLE x "<<cnt["TLE"]<<nl;
        cout << "RE x "<<cnt["RE"]<<nl;
    }  
    

    return 0;
        
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
const ll ber = 1e18;
const int M = 1000005;

int main(){
  char m;
  cin >> m;
  
  if(isupper(m)){
    cout << "A" << endl;
  }else{
    cout << "a" << endl;
  }
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int H,W,K,A[10][1000],count,pre,z,sum,ans,res=100000;
	char s;
	bool S[10][1000],flag,no;
	cin>>H>>W>>K;
	for(int i=0;i<H;i++)for(int j=0;j<W;j++){
		cin>>s;
		S[i][j]= s=='1';
		A[i][j]= S[i][j];
	}
	for(int i=0;i<H;i++)for(int j=1;j<W;j++){
		A[i][j]+=A[i][j-1];
	}
	for(int i=1;i<H;i++)for(int j=0;j<W;j++){
		A[i][j]+=A[i-1][j];
	}
	
	for(int i=0;i<(1<<(H-1));i++){
		vector<int> vec;
		pre=i;
		count=0;
		for(int j=0;j<H-1;j++){
			if(pre%2){
				vec.push_back(j);
				count++;
			}
			pre/=2;
			if(pre==0)break;
		}
		vec.push_back(H-1);
		ans=count;
		z=-1;
		no=false;
		for(int j=0;j<W;j++){
			flag=true;
			for(int k=0;k<=count;k++){
				sum=A[vec[k]][j];
				if(k>=1){
					sum-=A[vec[k-1]][j];
					if(z>=0)sum+=-A[vec[k]][z]+A[vec[k-1]][z];
				}else{
					if(z>=0)sum-=A[vec[k]][z];
				}
				flag &= sum<=K;
			}
			if(!flag){
				ans++;
				z=j-1;
				if(j==0)no=true;
			}
		}
		if(!no)res=min(res,ans);
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	//cout << fixed << setprecision(10);
	int n,m; cin>>n>>m;
	vvi a(n,vi(m));
	vi b(m);
	rep(i,0,n)rep(j,0,m)cin>>a[i][j];
	rep(i,0,m)cin>>b[i];
	rep(i,0,n){
		int ans=0;
		rep(j,0,m)ans+=b[j]*a[i][j];
		cout<<ans<<endl;
	}

	return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <tuple>

using namespace std;

typedef tuple<int, string, int> T;

bool comp(const T &a, const T &b){
  return get<1>(a) < get<1>(b) || !(get<1>(b) < get<1>(a)) && get<2>(b) < get<2>(a);
}

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

  vector<T> v(N);

  string S;
  int P;
  for (int i = 0; i < N; ++i) {
    cin >> S >> P;
    v[i] = make_tuple(i, S, P);
  }

  sort(v.begin(), v.end(), comp);
  for (auto e: v) cout << get<0>(e) + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		for (int i = 0; i < n; i++) {
			String s1 = sc.next();
			String s2 = sc.next();
			if (s1.length() > 80 || s2.length() > 80) {
				System.out.println("overflow");
				continue;
			}
			BigInteger b = new BigInteger(s1).add(new BigInteger(s2));
			System.out.println(b.toString().length() > 80 ? "overflow" : b);
		}

	}

}

Measured memory_bytes: 17252
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int n; vector<int> odd,even;
void input()
{
    cin >> n;
    for(int i=0; i<n/2; ++i){
        int a,b; cin >> a >> b;
        odd.emplace_back(a);
        even.emplace_back(b);
    }
}

bool pair_compare(pair<int,int> a, pair<int,int> b)
{
    return a.first > b.first;
}

void solve()
{
    map<int,int> Modd,Meven;
    Modd[0]; Meven[0];
    for(auto x: odd) Modd[x]++;
    for(auto x: even) Meven[x]++;

    vector<pair<int,int>> oddMap, evenMap;
    for(auto m: Modd){
        oddMap.emplace_back(make_pair(m.second,m.first));
    }
    sort(oddMap.begin(),oddMap.end(),pair_compare);
    for(auto m: Meven){
        evenMap.emplace_back(make_pair(m.second,m.first));
    }
    sort(evenMap.begin(),evenMap.end(),pair_compare);

    if(oddMap[0].second == evenMap[0].second){
        cout << min(n - oddMap[0].first - evenMap[1].first, n - oddMap[1].first - evenMap[0].first) << endl;
    }
    else cout << n - oddMap[0].first - evenMap[0].first << endl;
}

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

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

int main(){

    int n;
    cin >> n;

    vector<vector<int> > a(2,vector<int>(n,0));
    ll s=0;
    rep(i,2){
        rep(j,n){
            cin >> a[i][j];
        }
    }

    ll ma=0;

    for(int i=0;i<n;i++){
        ll t=0;
        for(int j=0;j<=i;j++){
            t+=a[0][j];
        }
        for(int j=i;j<n;j++){
            t+=a[1][j];
        }
        ma=max(t,ma);
    }
    cout << ma << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define endl "\n" 
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;

struct Card {
    char suit, value;
};

void bubble_sort(struct Card a[], int n) {
    for(int i=0; i < n; ++i) {
        for(int j = n-1; j > i; --j) {
            if(a[j].value < a[j-1].value) {
                swap(a[j], a[j-1]);
            }
        }
    }
}

void selection_sort(struct Card a[], int n) {
    for(int i=0; i < n; ++i) {
        int minj = i;
        for(int j = i; j < n; ++j) {
            if(a[minj].value > a[j].value) {
                minj = j;
            }
        }
        swap(a[minj], a[i]);
    }
}

void print(struct Card a[], int n) {
    for(int i=0; i < n; ++i) {
        if(i > 0) cout << " ";
        cout << a[i].suit << a[i].value;
    }
    cout << endl;
}

bool isStable(struct Card c1[], struct Card c2[], int n) {
    for(int i=0; i < n; ++i) {
        if(c1[i].suit != c2[i].suit) return false;
    }
    return true;
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    Card C1[100], C2[100];
    int n; cin >> n;
    //char ch;
    for(int i=0; i < n; ++i) {
        cin >> C1[i].suit >> C1[i].value;
    }

    for(int i=0; i < n; ++i) {
        C2[i] = C1[i];
    }
    
    bubble_sort(C1, n);
    selection_sort(C2, n);

    print(C1,n);
    cout << "Stable" << endl;
    print(C2,n);
    if(isStable(C1, C2, n)){
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    

    return 0;
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  ll ans=0;
  for(int i=1;i<sqrt(n);i++){
    if(n%i==0&&n!=(i+1)*i){
      ans+=(n-i)/i;
    }
    //cout << ans << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	Main(){
		new AOJ2096();
	}
	
	class AOJ2096{
		final long INF=1<<60;
		int N;
		long W;
		AOJ2096(){
			while(true){
				N=sc.nextInt();
				W=sc.nextLong();
				if((N|W)==0)	break;
				solve();
			}
		}
		void solve(){
			HashMap<String, Integer> weeks = new HashMap<String, Integer>();
			weeks.put("Monday", 1);		weeks.put("Tuesday", 2);
			weeks.put("Wednesday", 3);	weeks.put("Thursday", 4);
			weeks.put("Friday", 5);		weeks.put("Saturday", 6);
			weeks.put("Sunday", 7);
			
			final int MAX = N+11;
			long[][] cap=new long[MAX][MAX];
			for(int i=1; i<=7; ++i)	cap[0][i]=W;
			long sum=0;
			for(int i=0; i<N; ++i){
				long t=sc.nextLong();
				int c=sc.nextInt();
				sum+=t;
				for(int j=0; j<c; ++j){
					String week = sc.next();
					cap[weeks.get(week)][10+i] = W;
				}
				cap[10+i][10+N]=t;
			}
			Dinic d = new Dinic(cap, MAX);
			long ret = d.maxFlow(0, 10+N);
//			System.out.println( ret +" "+sum );
			System.out.println(ret==sum? "Yes": "No");
		}
		class Dinic{
			ArrayList<ArrayList<Edge2>> g;
			int[] 	level,
					iter;
			final long INF = 1<<60;
			int V;
			class Edge2{
				int to, rev;
				long cap;
				Edge2(int to,long cap,int rev){
					this.to=to;	this.cap=cap;	this.rev=rev;
				}
			}
			Dinic(long[][] cap,int V){
				this.V = V;
				level = new int[V];
				iter = new int[V];
				g = new ArrayList<ArrayList<Edge2>>(V);
				for(int i=0; i<V; ++i)	g.add(new ArrayList<Edge2>());
				for(int from=0; from<V; ++from)for(int to=0; to<V; ++to){
					if(cap[from][to] > 0){
						g.get(from).add(new Edge2(to, cap[from][to], g.get(to).size()));
						g.get(to).add(new Edge2(from, 0, g.get(from).size()-1));
					}
				}
			}
			long maxFlow(int s,int t){
				long flow = 0;
				while(true){
					bfs(s);
					if(level[t] < 0)	return flow;
					for(int i=0; i<V; ++i)	iter[i]=0;
					long f=0;
					while( (f=dfs(s, t, INF)) > 0)	flow += f;
				}
			}
			void bfs(int s){
				for(int i=0; i<V; ++i)	level[i] = -1;
				LinkedList<Integer> que = new LinkedList<Integer>();
				level[s] = 0;
				que.add(s);
				while(!que.isEmpty()){
					int v = que.poll();
					for(Edge2 e:g.get(v)){
						if(e.cap > 0 && level[e.to] < 0){
							level[e.to]= level[v]+1;
							que.add(e.to);
						}
					}
				}
			}
			long dfs(int v,int t,long f){
				if(v==t)	return f;
				for( ; iter[v]<g.get(v).size(); ++iter[v]){
					Edge2 e = g.get(v).get(iter[v]);
					if(e.cap > 0 && level[v] < level[e.to]){
						long d = dfs(e.to, t, min(f ,e.cap));
						if(d > 0){
							e.cap -= d;
							g.get(e.to).get(e.rev).cap += d;
							return d;
						}
					}
				}
				return 0;
			}
		}
	}
}

Measured memory_bytes: 63232
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define vin(v,n) rep(i,n)cin>>v[i];
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define sz size()
#define fi first
#define se second0
#define pb push_back
#define prqueue priority_queue<ll,vector<ll>,greater<ll>>
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
int main() {
	ll n, v[110], sum=0,ans=INF;
	cin >> n;
	rep(i, n)cin >> v[i], sum += v[i];
		ll num = 0;
		sum /= n;
		rep(i, n)num += pow(v[i] - sum, 2);
		ans = min(num, ans);
		num = 0;
		++sum;
		rep(i, n)num += pow(v[i] - sum, 2);
		ans = min(num, ans);
		cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int N,K;
    int[] P;
    private void solve() {
        N = nextInt();
        K = nextInt();

        P = nextIntArray(N);
        Arrays.sort(P);

        int sum = 0;
        for(int i = 0;i < K;i++) {
            sum += P[i];
        }
        out.println(sum);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

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

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

    public long[] nextLongArray(int n) {
        long[] x = new long[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextLong();
        }
        return x;
    }

    public double[] nextDoubleArray(int n) {
        double[] x = new double[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextDouble();
        }
        return x;
    }
}

Measured memory_bytes: 32860
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>

using namespace std;

int main(void){
	string s;

	cin >> s;

	int left = 0, right = s.size(), mid;

	int aaa = 0;
		while (left <= right){
			mid = (left + right)/2;

			int ok = 1;
			char temp = s[s.size() - mid];
			for (int i = s.size() - mid; i < mid; i++){
				if (temp != s[i])
					ok = 0;
			}
			if (ok == 1){
				left = mid + 1;
			}
			else {
				right = mid - 1;
			}
		}

	cout << right << endl;
}

Measured memory_bytes: 512
class Dice
  #   1
  # 4 2 3 5
  #   6
  attr_reader :pips
  def initialize(*pips)
    @pips = pips
  end

  def rotate!(direction)
    pips = case direction
    when :n then [2, 6, 3, 4, 1, 5].map { |i| i - 1 }
    when :e then [4, 2, 1, 6, 5, 3].map { |i| i - 1 }
    when :w then [3, 2, 6, 1, 5, 4].map { |i| i - 1 }
    when :s then [5, 1, 3, 4, 6, 2].map { |i| i - 1 }
    when :z then [1, 3, 5, 2, 4, 6].map { |i| i - 1 }
    end
    @pips = @pips.values_at(*pips)
    self
  end

  def rotate_to_top!(pip)
    case @pips.index(pip) + 1
    when 1 then self
    when 2 then self.rotate!(:n)
    when 3 then self.rotate!(:w)
    when 4 then self.rotate!(:e)
    when 5 then self.rotate!(:s)
    when 6 then self.rotate!(:n).rotate!(:n)
    end
  end
end

pips = gets.split.map(&:to_i)
q = gets.to_i
q.times do
  dice = Dice.new(*pips)
  p1, p2 = gets.split.map(&:to_i)

  dice.rotate_to_top!(p1)
  until dice.pips[1] == p2 do
    dice.rotate!(:z)
  end

  p dice.pips[2]
end

Measured memory_bytes: 6120
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  int n, k;
  readf("%d %d\n", &n, &k);
  writeln(n-k+1);
}


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

using namespace std;

bool check(int a, int b, const vector<int>& div, int low){
	if(a < b) return false;
	vector<int> dp(a+1, 0);
	dp[a] = 1;
	for(auto& d : div){
		for(int i=d;i<=a;i++){
			if(dp[i]) dp[i%d] = 1;
		}
	}
	for(int d=low;d>0;d--){
		for(int i=d;i<=a;i++){
			if(dp[i]) dp[i%d] = 1;
		}
	}
	return dp[b];
}

bool checkAll(const vector<int>& a, const vector<int>& b, const vector<int>& div, int low){
	const int N = a.size();
	for(int i=0;i<N;i++){
		if(!check(a[i], b[i], div, low)) return false;
	}
	return true;
}

int main(){
	int N;
	while(cin >> N){
		vector<int> a(N), b(N);
		for(auto& t : a) cin >> t;
		for(auto& t : b) cin >> t;
		vector<int> res;
		int end = 50;
		while(true){
			if(checkAll(a, b, res, 0)) break;
			bool update = false;
			for(int i=1;i<=end;i++){
				if(checkAll(a, b, res, i)){
					res.push_back(i);
					end = i - 1;
					update = true;
				}
			}
			if(!update) break;
		}
		if(!checkAll(a, b, res, 0)){
			cout << -1 << endl;
		} else {
			long long c = 0;
			for(auto& t : res) c += 1LL << t;
			cout << c << endl;
		}
	}
}


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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;
    
    static void solve(InputReader in, PrintWriter out){
        ArrayDeque<Character> a = new ArrayDeque<>();
        ArrayDeque<Character> b = new ArrayDeque<>();
        ArrayDeque<Character> c = new ArrayDeque<>();
        char[] sa = in.ns().toCharArray();
        char[] sb = in.ns().toCharArray();
        char[] sc = in.ns().toCharArray();
        for(char i: sa) a.addLast(i);
        for(char i: sb) b.addLast(i);
        for(char i: sc) c.addLast(i);
        char player = 'a';
        while(true){
            if(player=='a'){
                if(!a.isEmpty()){
                    player = a.pollFirst();
                }else break;
            }else if(player=='b'){
                if(!b.isEmpty()){
                    player = b.pollFirst();
                }else break;
            }else{
                if(!c.isEmpty()){
                    player = c.pollFirst();
                }else break;
            }
        }
        out.println((char)(player+'A'-'a'));
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 22996
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 1;										/* デバッグプリント 提出時は0 */
int main()
{
	int		ans = 0;

	int		X,A;
	
	scanf("%d %d %d", &X, &A);

	if (X<A) printf("0\n");
	else printf("10\n");


	return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
          unsigned long int a,b,c,d,e,x;
          cin>>a;
          b=a/500;
          e=a%500;
          c=e/5;
          x=c*5+b*1000;
          cout<<x<<endl;
          return 0;
}


Measured memory_bytes: 3592
h, w, k = map(int, input().split())
c = []


def count(h_mask, w_mask):
    sum_ = 0
    
    for i in range(h):
        if h_mask & 2 ** i != 0:
            continue
        for j in range(w):
            if w_mask & 2 ** j != 0:
                continue
            else:
                if c[i][j] == "#":
                    sum_ += 1

    if sum_ == k:
        return 1
    else:
        return 0


for i in range(h):
    c.append(input())

res = 0

for i in range(2 ** h):
    for j in range(2 ** w):
        res += count(i, j)

print(res)


Measured memory_bytes: 74252
N = int(input())
mojis = ["a","b","c","d","e","f","g","h","i","j"]
def append_m(moji):
    arr = []
    for i in mojis[:len(set(moji))+1]:
        arr.append(moji+i)
    return arr

arr = ["a"]
for i in range(N-1):
    tmp = []
    for j in arr:
        tmp += append_m(j)
    arr = tmp
for i in arr:
    print(i)

Measured memory_bytes: 12916
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>
#include <queue>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

int main() {
  //std::cout << std::fixed << std::setprecision(10);
  ull n;
  cin >> n;

  vector<string> s;
  vector<ull> p;
  vector<tuple<string, ull, ull>> sp;
  each(i, n) {
    string t;
    ull tmp;
    cin >> t >> tmp;
    s.push(t);
    p.push(tmp);
    sp.emplace_back(make_tuple(t, tmp, i+1));
  }

  std::sort(sp.begin(), sp.end(), [](const tuple<string, ull, ull>& l, const tuple<string, ull, ull>& r) {
                                    if (get<0>(l) == get<0>(r)) {
                                      return get<1>(l) > get<1>(r);
                                    } else {
                                      return get<0>(l) < get<0>(r);
                                    }
                                  });


  each(i, n) {
    cout <<  get<2>(sp[i]) << endl;
  }

  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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;}

signed main(){
    string S;cin>>S;
    string T=S;
    sort(all(T));T.erase(unique(all(T)),T.end());
    if(S.size()==T.size())cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<ll>())
#define rvpsort(v) sort(v.begin(), v.end(), greater<pair<ll, ll>>())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
#define vfind(v, target) find(v.begin(), v.end(), target)
#define notFound(v, target) (vfind(v, target) == v.end())

using namespace std;

int main()
{
  ll N; cin >> N;
  vector<ll> A(N);
  for(ll i = 0; i < N; i++) cin >> A[i];
  if (N % 3) {
	for(ll i = 0; i < N; i++) {
    	if (A[i] != 0){
        	cout << "No" << endl; 
          	return 0;
        }          
    }
  	cout << "Yes" << endl;
    return 0;  }
  vector<pair<ll, ll>> triple;
  for(ll i = 0; i < N; i++) {
  	bool exist = false;
    for (ll j = 0; j < triple.size(); j++) {
    	if (A[i] == triple[j].first) {
        	triple[j].second++;
          	exist = true;
        }
    }
    if (exist == false) {
    	triple.emplace_back(A[i], 1);
    }
    if (triple.size() > 3) {
    	cout << "No" << endl; return 0;
    }
  }
  vsort(triple);
  if (triple.size() == 1) {
  	if (triple[0].first == 0) {
    	cout << "Yes" << endl;
    } else {
    	cout << "No" << endl;
    }
  } else if (triple.size() == 2) {
  	if (triple[0].first == 0 && triple[0].second * 2 == triple[1].second) {
    	cout << "Yes" << endl;
    } else {
    	cout << "No" << endl;
    }
  } else {
  	if (triple[0].second == triple[1].second && triple[2].second == triple[1].second
       && (triple[0].first ^ triple[1].first ^ triple[2].first) == 0) {
    	cout << "Yes" << endl;
    } else {
    	cout << "No" << endl;
    }
  }
}

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

int N, K;
string S;

int main() {
	cin >> N >> K >> S;
    if (S[K-1] == 'A') S[K-1] = 'a';
    else if (S[K-1] == 'B') S[K-1] ='b';
    else S[K-1] = 'c';
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

int main() {
    int N; cin >> N;
    vector<int> A(N), B(N), C(N - 1);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N - 1) cin >> C[i];
    int ans = 0;
    rep(i, N) {
        ans += B[A[i] - 1];
    }
    rep(i, N - 1) {
        if(A[i] + 1 == A[i + 1]) {
            ans += C[A[i] - 1];
        }
    }
    cout << ans << "\n";
}

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

const int maxn=200005;
int d, t;
int n, m;
map<int, int> cnt;
int main(){
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%d", &d);
        cnt[d]++;
    }
    scanf("%d", &m);
    bool ans=1;
    for(int i=0;i<m;i++){
        scanf("%d", &t);
        if(cnt[t]){
            cnt[t]--;
        }
        else ans=0;
    }
    printf("%s\n", ans?"YES":"NO");
    return 0;
}



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

def main():
    N = int(input())
    rx,ry = [],[]
    _root = []
    for i in range(N):
        a,b = map(int,input().split())
        rx.append((a,i))
        ry.append((b,i))
    
    I = [i for i in range(N)]
    rank = [1 for _ in range(N)]
    def root(x):
        if x == I[x]:
            return x
        I[x] = root(I[x])
        return I[x]
    
    def unite(x,y):
        px,py = root(x),root(y)
        rx,ry = rank[px],rank[py]
        if rx > ry:
            I[py] = px
        else:
            I[px] = py
            if rx == ry:
                rank[py] += 1

    ans = 0
    rx.sort()
    ry.sort()
    for i in range(N-1):
        dx = rx[i+1][0]-rx[i][0]
        dy = ry[i+1][0]-ry[i][0]
        _root.append((dx,rx[i][1],rx[i+1][1]))
        _root.append((dy,ry[i][1],ry[i+1][1]))
        
    _root.sort()
    a = len(_root)
    for i in range(a):
        cost,now,fol = _root[i]
        if (root(now) == root(fol)):
            continue
        ans += cost
        unite(now,fol)
        
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 54952
#include <iostream>

using namespace std;

int N, A, B;

int main()
{
	cin>>N;
	
	if(N==1) cout<<"Hello World\n";
	
	else if(N==2)
	{
		cin>>A>>B;
		cout<<A+B<<'\n';
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define rep(i,x) for(int i = 0;i<x;i++)
#define REP(i,x) for(ll i = 1;i<=x;i++)
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; 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 change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; 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 nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}
ll mypow(ll n,ll m){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n);
        m >>= 1;
        n *= n;
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    map<ll,ll> ma;
    ll n;
    rep(i,N){
        cin >> n;
        ma[n]++;
    }
    ll one = 0,two = 0;
    for(auto x : ma){
        if(x.second % 2 == 0)two++;
        else one++;
    }
    cout << one + two / 2 * 2 << "\n";
}

Measured memory_bytes: 9816
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
//Loopで使う文字列の長さは固定！
//intで大丈夫？オーバーフローしない？
//Loop回数は本当に10⁹以内になってる？Loopは回る？？
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int t=sc.nextInt();
        int[] a=new int[n+1];
        int leftmin=1000000001;
        int dmax=0;
        int[] ansarr=new int[n+1];
        int count=0;
        for (int i = 1; i <= n; i++) {
            a[i]=sc.nextInt();
            leftmin=min(leftmin,a[i]);
            dmax=max(dmax,a[i]-leftmin);
            if(a[i]-leftmin==dmax){
                ansarr[i]=dmax;
            }
        }
        for (int i = 1; i <= n; i++) {
            if(dmax==ansarr[i])count++;
        }
        out.println(count);
    }
}

Measured memory_bytes: 61912
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
trafic = [a, b, c, d, e]
ans = 5

if min(trafic) >= n:
    print(ans)
    exit()
else:
    if n % min(trafic) == 0:
        group = n//min(trafic) - 1
    else:
        group = n//min(trafic)

print(ans+group)

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

using namespace std;

typedef long long ll;

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

    int k;
    string s;

    cin >> k >>s;

    int lenS = s.size();

    if (lenS <= k){
        cout << s<<"\n";
    } else if(lenS > k){
        string substr = s.substr(0, k);
        substr.append("...");

        cout << substr << "\n";
    }



    return 0;
} 

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define mod 1000000007
typedef long long ll;
using namespace std;

ll S[100100]; // S[i] := [1,i]に含まれるお菓子の総数をmで割ったあまり
int main(){
    ll n,m; cin >> n >> m;
    ll A[100100];
    S[0] = 0;
    for(int i=1;i<=n;i++){
        cin >> A[i];
        S[i] = (S[i-1] + A[i]) % m; 
    }
    map<ll,ll> mp;
    ll ans = 0;
    //S[S[0]]++;
    for(int i=1;i<=n;i++){
        ans += mp[S[i]%m];
        mp[S[i]%m]++;
    }
    /*for(int i=1;i<=n;i++){
        if(A[i] % m == 0) ans++;
    }*/
    ans += mp[0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    string s;
    cin >> s;
    bool b = false;
    for (auto &c:s) {
        b = !b;
        if ((b && c == 'h') || (!b && c == 'i')) continue;
        else {
            cout << "No" << '\n';
            return 0;
        }
    }
    cout << (!b ? "Yes" : "No") << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};

/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_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;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/


int main(){
    int N,M; cin >> N >> M;
    vector<pair<ll,ll> > p(N);
    for (int i = 0; i < N; i++){
        ll a,b; cin >> a >> b;
        p[i] = {a,b};
    }
    sort(p.begin(),p.end());
    priority_queue<ll> pq;
    int now = 0;
    ll ans = 0;
    for (int i = 1; i <= M; i++){
        while (p[now].first <= i && now < N){
            pq.push(p[now].second);
            now++;
        }
        if (pq.size()){
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll a,b;

int main(){
    cin >> a >> b;
    cout << a - 1 + (a <= b) << endl;
}

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

int main() {
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  int N;
  cin>>N;

  string S;
  cin>>S;

  int R=0,B=0;
  for(int i=0;i<N;i++){
    if(S.at(i)=='R') R++;
    if(S.at(i)=='B') B++;
  }
  
  cout<<(R>B? "Yes":"No")<<endl;
}


Measured memory_bytes: 256
#  ABC 088 B - Card Game for Two
N = int(input())
an = list(map(int, input().split()))

Alice = []
Bob = []
while len(an) > 0:
    Alice.append(max(an))
    del an[an.index(max(an))]
    if len(an) > 0:
        Bob.append(max(an))
        del an[an.index(max(an))]
    else:
        break

k = 0
j = 0
for i in range(len(Alice)):
    k += Alice[i]
for i in range(len(Bob)):
    j += Bob[i]

print(str(k-j))

Measured memory_bytes: 9112
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	ll h, w;
	cin >> h >> w;
	ll ans = INFLL;

	if(h % 3 == 0 || w % 3 == 0) ans = 0;

	ll a, b, c;

	for(ll i = 1;i < h;i++){
		a = i * w;
		b = (h-i) * (w/2);
		c = (h-i) * ((w/2) + (w%2));

		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
	}

	for(ll i = 1;i < h;i++){
		a = i * w;
		b = (h-i) / 2 * w;
		c = (h-i) / 2;
		if((h-i) % 2 == 1) c++;
		c *= w;

		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
	}


	for(ll i = 1;i < w;i++){
		a = i * h;
		b = (w-i) * (h/2);
		c = (w-i) * ((h/2) + (h%2));

		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
	}


	for(ll i = 1;i < w;i++){
		a = i * h;
		b = (w-i) / 2 * h;
		c = (w-i) / 2;
		if((w-i) % 2 == 1) c++;
		c *= h;

		ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set>
int main(){
  int n,k;
  cin>>n>>k;
  
  vector<int> d(n);
  rep(i,k){
   int m;
   cin>>m;
    rep(j,m){
      int a;
      cin>>a;
      d.at(a-1)=1;
    }
  }
  int ans =0;
  rep(i,n)if(d.at(i)==0)ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 3600