akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(1e6)+10;
int n,m,sum,s,a[maxn],b[maxn];
char S[maxn];
int N,id[maxn],d[maxn],tot;
bool cmpa(int x,int y) { return a[x]<a[y]; }
bool cmpb(int x,int y) { return b[x]>b[y]; }
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) {
		scanf("%s",S+1);
		m=strlen(S+1);
		s=0;
		for (int j=1;j<=m;j++) {
			if (S[j]=='(') s++; else s--;
			a[i]=max(a[i],-s);
		}
		sum+=s;
		s=0;
		for (int j=m;j>=1;j--) {
			if (S[j]=='(') s++; else s--;
			b[i]=max(b[i],s);
		}
		//printf("%d %d\n",a[i],b[i]);
	}
	if (sum!=0) { printf("No\n"); return 0; }
	
	sum=0;
	for (int i=1;i<=n;i++) if (b[i]>=a[i]) d[++tot]=i;
	sort(d+1,d+tot+1,cmpa);
	for (int i=1;i<=tot;i++) id[++N]=d[i];
	tot=0;
	for (int i=1;i<=n;i++) if (b[i]<a[i]) d[++tot]=i;
	sort(d+1,d+tot+1,cmpb);
	for (int i=1;i<=tot;i++) id[++N]=d[i];
	for (int i=1;i<=N;i++) {
		if (sum-a[id[i]]<0) { printf("No\n"); return 0; }
		sum+=b[id[i]]-a[id[i]];
	}
	printf("Yes\n");
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 17132
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.000000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main()
{
    fast();
    ll x,y;
    cin>>x>>y;
    ll t=(y-2*x)/2;
    ll c=x-t;
    if(t>=0 && c>=0 && 2*c+4*t==y)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


Measured memory_bytes: 3652
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

#define WHITE '.'
#define BLACK '#'

int main(void)
{
	int H, W;
	cin >> H >> W;

	vector<string> s(H);
	for(int i=0; i<H; i++)
		cin >> s[i];

	const int dx[] = {0, 1, 0, -1};
	const int dy[] = {1, 0, -1, 0};
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			if(s[i][j] == WHITE)
				continue;

			bool ok = false;
			for(int k=0; k<4; k++){
				int x = j + dx[k];
				int y = i + dy[k];

				if(x<0 || x>=W || y<0 || y>=H)
					continue;

				if(s[y][x] == BLACK)
					ok = true;
			}
			if(ok == false){
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;

	return 0;
}


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

int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a*4+b*2+c == 1) printf("Open\n");
	else if(a*4+b*2+c == 6) printf("Open\n");
	else printf("Close\n");
	return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int x[n];
  for(int i=0;i<n;i++) scanf("%lld",x+i);
  set<int> s;
  int u=1;
  for(int i=0;i<n;i++){
    if(s.count(0)){
      cout<<"No"<<endl;
      continue;
    }
    int k=x[i];
    while(s.count(u)) u++;
    if(k<u-1||(k==u-1&&(int)s.size()!=u-1)){
      puts("No");
      continue;
    }
    puts("Yes");
    while(s.count(k)) s.erase(k--);
    s.insert(k);
  }
  return 0;
}

Measured memory_bytes: 18756
<?php
  fscanf(STDIN, "%i", $x);
  if ($x > pow(10, 15) + pow(10, 13) * 25) throw null;
  $d = (int)ceil($x / 11);
  $m = $x % 11;
  echo ($d * 2 - (($m >= 1 && $m <= 6) ? 1 : 0)).PHP_EOL;
?>


Measured memory_bytes: 2936
#include <stdio.h>
#define MAX 50005

int min(int x, int y)
{
  return x < y ? x : y;
}

int main(void)
{
  int n, m;
  int c[20];
  int t[20][MAX];
  
  scanf("%d%d", &n, &m);
  
  for (int i = 0; i < m; i++) {
    scanf("%d", &c[i]);
    t[i][0] = 0;
  }
  
  for (int i = 1; i <= n; i++)
    t[0][i] = i;
  
  for (int i = 1; i < m; i++)
    for (int j = 0; j <= n; j++)
      t[i][j] = j < c[i] ? t[i-1][j] : min(t[i-1][j], t[i][j-c[i]]+1);
  
  printf("%d\n", t[m-1][n]);
  
  return 0;
}


Measured memory_bytes: 5648
#include <bits/stdc++.h>
using namespace std;
#define forx(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;

int main()
{
    string s, t;
    cin >> s >> t;
    int p = s.size();
    int q = t.size();
    vector<string>x;

    rep(i,p-q+1){
        string u = s;
        bool y = true;
        rep(j,q){
            
            if(u[i+j]=='?'){
                u[i + j] = t[j];
                continue;
            }
            if(u[i+j]!=t[j])
                y=false;
        }
        if(y){
            rep(i, p) if (u[i] == '?') u[i] = 'a';
            x.push_back(u);
        }
    }

    sort(x.begin(),x.end());
    if(x.size()==0)
        cout << "UNRESTORABLE" << endl;
    else
        cout << x[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

const int MAX_LEN = 1000;
char A[MAX_LEN + 1];
char B[MAX_LEN + 1];

void _main() {
  cin >> A >> B;

  int asize = strlen(A);
  int bsize = strlen(B);
  if (asize > bsize) {
    cout << "GREATER" << "\n";
    return;
  }
  if (asize < bsize) {
    cout << "LESS" << "\n";
    return;
  }

  rep(i, 0, MAX_LEN) {
    if (A[i] > B[i]) {
      cout << "GREATER" << "\n";
      return;
    }
    if (A[i] < B[i]) {
      cout << "LESS" << "\n";
      return;
    }
  }
  cout << "EQUAL" << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
   int a[100],b[100],c,d,n;
   scanf("%d",&n);
   for (c=0;c<n;c++)
   {
      scanf("%d",&a[c]);
   }
   for (c=n-1,d=0;c>=0;c--,d++)
   {
      b[d]=a[c];
   }
   for (c=0;c<n; c++)
   {
      a[c]=b[c];
   }
   for (c=0;c<n;c++)
   {
       if(c<(n-1))
      printf("%d ",a[c]);
       else
       printf("%d\n",a[c]);
   }
   return 0;
}



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

int main()
{
	int64_t A, B, C, K;
	cin >> A >> B >> C >> K;

	int maxN = 0;
	if (K < A)
	{
		maxN = K;
	}
	else if(K - A < B)
	{
		maxN = A;
	}
	else
	{
		maxN = A - (K - A - B);
	}

	cout << maxN << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main()
{
    int D;
    cin >> D;
    
    if(D==25){
        cout << "Christmas" << endl;
    }else{
        if(D==24){
            cout << "Christmas Eve" << endl;
        }else{
            if(D==23){
                cout << "Christmas Eve Eve" << endl;
            }else{
                cout << "Christmas Eve Eve Eve" << endl;
                
            }
        }
    }
    
    return 0;
}


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

int dfs (vector<vector<int> > &v, int now, vector<bool> &used, int count) {
    if (used[now]) return count;
    count++;

    used[now] = true;
    int ret = count;
    for (auto i : v[now]) {
        ret = max(ret, dfs(v, i, used, count));
    }
    used[now] = false;

    return ret;
}

int main() {
    int N;
    while (cin >> N, N) {
        vector<vector<int> > v(101);
        for (int i = 0; i < N; i++) {
            int x, y;
            cin >> x >> y;
            v[x].push_back(y);
            v[y].push_back(x);
        }

        int ans = 0;
        vector<bool> used(101, false);
        for (int i = 1; i <= 100; i++) {
            ans = max(ans, dfs(v, i, used, 0));
        }
        cout << ans << endl;
    }

    return 0;
}

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

//素数判定

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

main(){
  ll a,b;
  cin>>a>>b;
  vector<ll> A,B;
  for(int i = 1; i*i<=a; i++){
    if(a%i==0){
      A.push_back(i);
      A.push_back(a/i);
    }
  }
  for(int i = 1; i*i<=b; i++){
    if(b%i==0){
      B.push_back(i);
      B.push_back(b/i);
    }
  }
  map<ll,ll> mp;
  for(auto x : A){
    for(auto y : B){
      if(x==y) mp[x]=1;
    }
  }
  int ans=0;
  for(auto x : mp){
    if(x.first == 1 || IsPrime(x.first)) ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4228
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#define inf 99999999
using namespace std;
typedef long long ll;
const int MAXN=2000+7;
const int MAX=100+10;
int main(){
   #ifdef SIYU
   freopen("in.txt","r",stdin);
   #endif // SIYU
   char s1[20],s2[20],s3[20];
   cin>>s1>>s2>>s3;
   if(s1[0]>='A'&&s1[0]<='Z')
      printf("%c",s1[0]);
   else
      printf("%c",s1[0]-32);
   if(s2[0]>='A'&&s2[0]<='Z')
      printf("%c",s2[0]);
   else
      printf("%c",s2[0]-32);
   if(s3[0]>='A'&&s3[0]<='Z')
      printf("%c",s3[0]);
   else
      printf("%c",s3[0]-32);
   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++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    map<int, int> mp;
    rep(i,n) mp[a[i]]++;

    int sum = 0;
    for(auto m: mp){
        if (m.second % 2 != 0) sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 8184
# coding: utf-8
import copy

N = int(input())

d = dict()

res = 0
for i in range(N):
    s = input()
    s = ''.join(sorted(s))

    if s in d.keys():
        res += d[s]
        d[s] += 1
    else:
        d[s] = 1

print(res)


Measured memory_bytes: 18308
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int dp[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n, m;
    cin>>n>>m;
    int ans = 0;
    f(i, m){
        int l, r;
        cin>>l>>r;
        dp[l]++;
        dp[r + 1]--;
    }
    for(int i = 1; i < n + 2; i++) dp[i] += dp[i - 1];
    rep(i, 1, n + 2){
        if(dp[i] == m) ans++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;

int main(){
    int H, W;
    cin >> H >> W;
    string s[H];
    int output_row = 0;
    int output_col = 0;
    int output_rows[H];
    int output_cols[W];
    for(int i = 0; i < H; i++){
        cin >> s[i];
        output_rows[i] = 0;
    }
    for(int i = 0; i < W; i++){
        output_cols[i] = 0;
    }
    // check row;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(s[i][j] == '#'){
                output_rows[i] = 1;
                output_cols[j] = 1;
            }
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(output_rows[i] == 1 && output_cols[j] == 1){
                cout << s[i][j];
            }
        }
        if(output_rows[i] == 1){
            cout << endl;
        }
    }
    return 0;
}

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

int main(){
  int N, M, X;
  cin >> N >> M >> X;
  M++;
  vector<vector<int>> vec(N, vector<int>(M));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < M; j++)
      cin >> vec[i][j];
  }
  
  vector<int> money(0);
  
  for(int tmp = 0; tmp < (1 << 12); tmp++){
    bitset<12> s(tmp);
    vector<int> sum(M);
    for(int i = 0; i < N; i++){
      if(s.test(i)){
        for(int j = 0; j < M; j++)
          sum[j] += vec[i][j];
      }
    }
    bool check = true;
    for(int i = 1; i < M; i++){
      if(sum[i] < X){
        check = false;
        break;
      }
    }
    if(check)
      money.push_back(sum[0]);
    
    if(s.count() == N)
      break;
  }
  
  int min = -1;
  if(money.size() != 0){
    min = money[0];
    for(int i = 0; i < money.size(); i++){
      if(money[i] != 0 && money[i] < min)
        min = money[i];
    }
  }
  
  cout << min << endl;
  
  return 0;
  
}

Measured memory_bytes: 3644
A, B, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

o = min(a_list) + min(b_list)
for _ in range(M):
    x, y, c = map(int, input().split())
    t_a = a_list[x-1]
    t_b = b_list[y-1]
    r = t_a + t_b - c
    if o is None or o > r:
        o = r


print(o)

Measured memory_bytes: 18736
S = input()
N=int(len(S))
if S==S[::-1]:
    if S[0:int((N-1)/2)]==S[0:int((N-1)/2)][::-1]:
        if S[int((N+3)/2)-1:N+1]==S[int((N+3)/2)-1:N+1][::-1]:
            print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int x=sc.nextInt();
		int y=sc.nextInt();
		int z=sc.nextInt();
		System.out.print(z+" "+x+" "+y);
		sc.close();
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>

using namespace std;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    deque<int> A;
    while (n--) {
        int x;
        cin >> x;
        if (n & 1) A.push_back(x);
        else A.push_front(x);
    }
    while (!A.empty()) {
        printf("%d ", A.front());
        A.pop_front();
    }
    return 0;
}

Measured memory_bytes: 3072
//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 310
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int n,m,mod;
inline int Z(int x){return x>=mod?x-mod:x;}
int dp[N][N][N];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),m=read(),mod=read();
	dp[0][1][0]=1;
	for(register int i=0;i<=n;i++)
	{
		for(register int j=1;j<=m;j++)
		{
			for(register int k=i;k>=0;k--)
			{
				if(k){dp[i][j][k-1]=Z(dp[i][j][k-1]+dp[i][j][k]);}
				else dp[i][j+1][i]=Z(dp[i][j+1][i]+dp[i][j][k]);
				dp[i+1][j][k]=Z(1LL*dp[i][j][k]*(k+1)%mod+dp[i+1][j][k]);
			}
		}
	}
	printf("%d\n",dp[n][m][0]);
	return 0;
}


Measured memory_bytes: 114804
#include<cstdio>

char c[100][100];

void dfs(int x,int y){
    char ch=c[x][y];
    c[x][y]=0;
    int dx[4]={0,0,1,-1};
    int dy[4]={-1,1,0,0};
    for(int i=0;i<4;i++){
        if(x+dx[i]<100&&x+dx[i]>=0&&y+dy[i]<100&&y+dy[i]>=0&&ch==c[x+dx[i]][y+dy[i]]){
            dfs(x+dx[i],y+dy[i]);
        }
    }
    return;
}

int solve(int h,int w){
    for(int i=0;i<h;i++){
        getchar();
        for(int j=0;j<w;j++){
            c[i][j]=getchar();
        }
    }
    int res=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(c[i][j]!=0){
                res++;
                dfs(i,j);
            }
        }
    }
    return res;
}

int main(){
    while(1){
        int h,w;
        scanf("%d %d",&h,&w);
        if(h==0&&w==0) return 0;
        else printf("%d\n",solve(h,w));
    }
}

Measured memory_bytes: 1820
import sys
import math
input = sys.stdin.readline

A,B,h,m=map(int,input().split())
res = 0

if (h == 12): 
        h = 0
if (m == 60): 
    m = 0
a1 = 0.5 * (h * 60 + m) 
a2 = 6 * m 
res = abs(a1 - a2) 
res = min(360 - res, res) 

t = A*A + B*B - 2*A*B*math.cos(((math.pi)/180)*(res))
t = t**0.5


print("{0:.15f}".format(t))

Measured memory_bytes: 62524
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,d;
  cin >> n >> d;
  int i,j;
  int s[n][d];
  for(i=0;i<n;i++){
    for(j=0;j<d;j++){
      cin >> s[i][j];
    }
  }
  int count=0,x;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      int sum=0;
      for(int k=0;k<d;k++){
        sum+=(s[i][k]-s[j][k])*(s[i][k]-s[j][k]);
      }
      for(x=0;x<=sum;x++){
        if(x*x==sum){
          count++;
          break;
        }
      }
    }
  }
  cout << count;
}

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

int main() {
    int x, y;
    cin >> x >> y;

    int var[13] = {0,1,3,1,2,1,2,1,1,2,1,2,1};

    if(var[x] == var[y])cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define MAX_N 50

using namespace std;

typedef long long ll_t;
typedef pair<ll_t, ll_t> point_t;

point_t sub( point_t p1, point_t p2 )
{
    return point_t( p1.first - p2.first, p1.second - p2.second );
}

int main( int argc, char **argv )
{
    int N;
    cin >> N;

    vector<point_t> points( N );
    for ( int i = 0; i < N; i++ ) cin >> points[i].first >> points[i].second;

    map<point_t, int> mp;
    for ( auto p1 : points )
    {
        for ( auto p2 : points )
        {
            if ( p1 == p2 ) continue;
            mp[sub( p1, p2 )]++;
        }
    }
    int ans = 0;
    for ( auto kv : mp ) ans = max( ans, kv.second );

    cout << N - ans << endl;

    return 0;
}


Measured memory_bytes: 384
function toNum (str) {
	return parseInt(str, 10);
}

// inputに入力データ全体が入る
function Main(input) {
	var AtoB = toNum(input.split(' ')[0]);
	var BtoC = toNum(input.split(' ')[1]) / 2;
	console.log(AtoB + BtoC);
}

// ※この行以降は編集しない (標準入力から一度に読み込みMainを呼び出します)
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 21064
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        if(a+b == c+d){
            System.out.println("Balanced");
        }else if(a+b > c+d){
            System.out.println("Left");
        }else{
            System.out.println("Right");
        }
    }
}

Measured memory_bytes: 23380
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iostream>
#include <queue>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64; // 9e18
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

const double PI = 3.141592653589793238463;
const int MAXN = 1000500;
const int MAXVALUE = 1000000500;
const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;


i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> a;
//vector <i64> b;
vector <i64> dp;


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

    //cin >> T;
    T = 1;

    for (i64 tt = 0; tt < T; ++tt) {

        string s;
        string g;

        cin >> s >> g;

        i64 res = 0;

        for (i64 i = 0; i < s.size(); ++i) {
            if (s[i] != g[i]) {
                res += 1;
            }
        }

        cout << res << endl;




    }

    return 0;
}

Measured memory_bytes: 3464
#include <bits/stdc++.h>
    using namespace std;
    int main()
    {
      int N;
      cin >> N ;
      int time[N];
      int i ;
      for(i=0; i<N ; i++)
      {
        cin >> time[i] ;
      }

      int M;
      cin >> M;

      int new_time[M][2];

      for(i=0; i<M ; i++)
      {
    	cin >> new_time[i][0] >> new_time[i][1] ;
      }

      int total_time = 0 ;
       for(i=0 ; i<N ; i++)
       {
         total_time = total_time + time[i] ;
       }


        for(i=0; i<M ; i++)
        {
            cout << total_time - time[new_time[i][0]-1]  + new_time[i][1] <<endl;
        }

    }


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

int main() {
  int n;
  cin >> n;
  
  if (n%10 == n/10%10 && n/10%10 == n/100%10) cout << "Yes" << endl;
  else if (n/10%10 == n/100%10 && n/100%10 == n/1000) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
        int n;
        scanf("%d",&n);
        vector<int> a(n);
        for(auto&e:a){
                scanf("%d",&e);
        }
//      sort(a.begin(),a.end(),greater<int>());
        for(int i=n-1;i>-1;i--){
                if(i!=0){
                    printf("%d ",a[i]);
                }else{
                    printf("%d\n",a[i]);
                }
        }
        return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, l;
	cin >> n >> l;
	string s[n];
	for (int i = 0; i < n; i++)
		cin >> s[i];
	sort(s, s+n);
	for (int i = 0; i < n; i++)
		cout << s[i];
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) for (int i=1;i<=n;i++)
int a[1000000];
int main()
{
    int r=500000-1,l=500000;
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
    	int x;
    	cin>>x;
    	if (i%2) a[++r]=x;
    	else a[--l]=x;
    }
    
    if (n%2)
    {
    	for (int i=r;i>l;i--) cout<<a[i]<<" ";
    	cout<<a[l];
    }
    else
    {
    	for (int i=l;i<r;i++) cout<<a[i]<<" ";
    	cout<<a[r];
    }
}

Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define cost first
#define from second.first
#define to second.second
#define MOD (1000000007ll)
#define l_ength size

ll p[123456],q[123456];

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll inv(ll x){
	ll a = MOD-2,ans=1ll;
	while(a > 0){
		if((a&1)>0){
			mul_mod(ans,x);
		}
		a /= 2;
		mul_mod(x,x);
	}
	return ans;
}

ll comb(int x, int y){
	ll ans=1ll;
	if(x <= 0 || y < 0 || (x-y) < 0){
		return 0ll;
	}
	mul_mod(ans,p[x]);
	mul_mod(ans,q[y]);
	mul_mod(ans,q[x-y]);
	return ans;
}


int main(void){
	int n,k,i,l,ans=0;
	vector<int> v;
	cin >> n >> k;
	for(i=0; i<n; ++i){
		cin >> l;
		v.push_back(l);
	}
	sort(v.begin(),v.end(),greater<int>());
	for(i=0; i<k; ++i){
		ans += v[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

int n,a,b;


const ll INF=100000000001;
int main() {

	cin>>n;
	int f[101]={};
	int p[101][11]={};
	int f1;
	for(int i=1;i<n+1;i++){
		for(int j=0;j<10;j++){
			cin>>f1;
			if(f1==1)f[i]+=(1<<j);
		}
	}
	for(int i=1;i<n+1;i++){
		for(int j=0;j<11;j++){
			cin>>p[i][j];
		}
	}

	int total=-1000000000;
	for(int i=1;i<(1<<10);++i){
		int r=0;
		for(int j=1;j<n+1;j++){
			int k=i&f[j];
			int t=0;
			for(int h=0;h<10;h++){
				if((k>>h)&1==1)t+=1;
			}
			r+=p[j][t];
		}
		total=max(total,r);
	}
	cout<<total<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a, b, c, para;

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

	if (a > b)
	{
		para = a;
		a = b;
		b = para;
	}

	if (b > c)
	{
		para = b;
		b = c;
		c = para;
	}

	if (a > b)
	{
		para = a;
		a = b;
		b = para;
	}

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

	return 0;
}

Measured memory_bytes: 1164
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<cstring>
#include<string>
#include<stack>
#include<math.h>
#include<stdlib.h>
using namespace std;
#define int long long
//#define double long double
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef pair<int, pii > pip;
typedef pair<pii, pii > piipii;
typedef pair<double, double> pdd;
typedef pair<int, char> pic;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define all(vec) vec.begin(), vec.end()
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60)
#define mod 1000000007
#define se second
#define fi first

int N;
vector<int> G[100100];
int dist[100100];
int ans[100100];

void dfs1(int v, int par){
    for(auto& e : G[v]){
        if(e == par){
            continue;
        }
        dfs1(e, v);
        dist[v] = max(dist[v], dist[e] + 1);
    }
}

void dfs2(int v, int d_par, int par){
    vector<pair<int, int> > V;
    V.push_back(mk(0, -1));
    for(auto& e : G[v]){
        if(e == par){
            V.push_back(mk(d_par + 1, par));
            continue;
        }
        V.push_back(mk(dist[e] + 1, e));
    }
    sort(V.rbegin(), V.rend());
    ans[v] = V[0].first;
    for(auto& e : G[v]){
        if(e == par)continue;
        if(e == V[0].second){
            dfs2(e, V[1].first, v);
        }
        else {
            dfs2(e, V[0].first, v);
        }
    }
}

signed main(){
    cin >> N;
    for(int i = 0; i < N - 1; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs1(0, -1);
    dfs2(0, 0, -1);
    for(int i = 0; i < N; i++){
        cout << (N - 1) * 2 - ans[i] << endl;
    }
    
    return 0;
}

/*

*/


Measured memory_bytes: 31896
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	while(cin>>n,n){
		vint aa(50,0);
		vector<string> s(n);
		vector<vint> vv(n);

		rep(i,n){
			cin>>s[i];
			int m;
			cin>>m;
			rep(j,m){
				int t;
				cin>>t;
				aa[t]++;
				vv[i].PB(t);
			}
		}
		vector<pair<int,string> > ans;
		rep(i,n){
			int S=0;
			rep(j,vv[i].size()){
				S+=n+1-aa[vv[i][j]];
			}
			ans.PB(mkp(S,s[i]));
		}
		sort(ALL(ans));
		rep(i,1){
			cout<<ans[i].F<<" "<<ans[i].S<<endl;
		}
	}
}

Measured memory_bytes: 1252
import java.util.HashSet;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int i;
        int[] give = new int [n];
        for(i=0;i<n;i++){
            give[i] = sc.nextInt();
        }
        int m = sc.nextInt();
        int j;
        int[] num = new int [m];
        for(j=0;j<m;j++){
            num[j] = sc.nextInt();
        }
        int k,l,o;
        HashSet<Integer> hs = new HashSet<>();
        for(k=0;k<Math.pow(2,n);k++){
            int sum = 0;
            for(l=0;l<n;l++){
                if((1&k>>l)==1){
                    sum += give[l];
                }
            }
            hs.add(sum);
        }
        for(o=0;o<m;o++){
            if(hs.contains(num[o])){
                System.out.println("yes");
            }else{
                System.out.println("no");
            }
        }
    }
}



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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

ll tri(ll A)
{
    if(A==0) return 0;
    else if(A==1) return 0;
    else return A * (A-1) / 2;
}

ll njou10(ll A)
{
    if(A==0) return 1;
    else if(A==1) return 10;
    else if(A%2==0) return (njou10(A/2)%2019) * (njou10(A/2)%2019)%2019;
    else return (njou10((A+1)/2)%2019) * (njou10((A-1)/2)%2019)%2019;
}

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

    ll ssize = s.size();

    vector<ll> last(ssize);
    last.at(0) = s.at(ssize-1) - '0';
    ll beki10 = 10;
    for(int i=1;i<ssize;i++)
    {
        last.at(i) = (last.at(i-1) + (s.at(ssize-i-1) - '0')*beki10)%2019;
        beki10*=10;
        beki10%=2019;
    }

    map<int,int> M;
    M[0]++;
    for(int i=0;i<ssize;i++)
    {
        M[last.at(i)]++;
    }

    ll answer = 0;
    for(auto x : M)
    {
        answer += tri(x.second);
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 5152
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;
#define ll signed long long

double EPS = 1e-10;

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

  ll r = c - a - b;
  if (r < 0) {
    cout << "No" << endl;
    return 0;
  }
  r = r * r;
  ll l = 4 * a * b;
  if (l < r) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int n,sum,t;
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	{
		int v;
		scanf("%d",&v);
		t=max(v,t);
		sum+=v;
	}
	if(sum-t>t)puts("Yes");
	else puts("No");
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("02")
#define ll long long
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
struct ios{
    inline char gc(){
        static const int IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }
    template <typename _Tp> _inline ios & operator >> (_Tp &x){
        static char ch,sgn; ch=gc(),sgn=0;
        for(;!isdigit(ch);ch=gc()){if(ch==-1)return *this;sgn|=ch=='-';}
        for(x=0;isdigit(ch);ch=gc())x=x*10+(ch^'0');
        sgn&&(x=-x); return *this;
    }
}inc;
int a,b;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>a>>b;
	string s;
	cin>>s;
	if(s[a]!='-') return puts("No"),0;
	int cnt=0;
	for(int i=0;i<=a+b;i++) if(isdigit(s[i])) cnt++;
	puts(cnt==a+b?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if((a*100+b*10+c)%4==0)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
} 

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

int main(){
	int m=0,f=0,r=0;
	while(m+f+r!=-3){
		cin >> m >> f >> r;
		if((m==-1||f==-1)&&m+f+r>=-2){
			cout << "F" <<endl;
		}
		else if(m+f>=80){
			cout << "A" <<endl;
		}
		else if(m+f>=65){
			cout << "B" <<endl;
		}
		else if(m+f>=50){
			cout << "C" <<endl;
		}
		else if(m+f>=30){
			if(r>=50){cout << "C" <<endl;}
			else {cout << "D" <<endl;}
		}
		else if(m+f+r>=-2){cout << "F" <<endl;}
	}
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using db = double;
#define pb push_back

const int mxn = 100006;

int R[mxn], W[mxn];
int n, m;

int main() {
	cin >> n >> m;
	R[1] = 1;
	for (int i = 2; i <= n; ++i)
		W[i] = 1;
	for (int i = 0; i < m; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (!R[x]) {
			--W[x], ++W[y];
		} else {
			--R[x], ++R[y];
		}
		if (R[y])
			R[y] += W[y], W[y] = 0;
	}
	
	int s = 0;
	for (int i = 1; i <= n; ++i) if (R[i])
		++s;
	cout << s << endl;
	
	return 0;
}


Measured memory_bytes: 1024
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<int> L;

  double l3 = L / 3.0;

  return l3*l3*l3;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<string.h>

int main(){
    int N,max=0,ans=0,p;
    scanf("%d",&N);
    int i;
    for(i=0;i<N;i++){
        scanf("%d",&p);
        ans += p;
        max = max>p? max:p;
    }
    printf("%d",ans-max/2);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define append push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define pb push_back
#define print(a) cout<<a<<endl
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define all(x) x.begin(), x.end()
#define loop(i,n) for(int i=0;i<n;i++)
const int MOD = 1e9 + 7;
const ll longinf = 1000000000000000;
void solve();
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	//cin>> t;
	while(t--){
		solve();
	}

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}
int n,k;
int a[101],dp[101][100001],p[101][100001];
void solve()
{
	cin>>n>>k;
  	memset(dp,0,sizeof dp);
  	memset(p,0,sizeof p);
  	loop(i,n)
      cin>>a[i+1];
  for(int i=1;i<=n;i++)
  {
    for(int j=0;j<=100000;j++)
    {
      if(i==1)
      {
  	      if(j<=a[1])
     	    dp[i][j]=1;
      }
      else
      {
        if(j>a[i])
	      dp[i][j]=(MOD+p[i-1][j]-p[i-1][j-a[i]-1])%MOD;
        else
          dp[i][j]=p[i-1][j];
      }
    }
    p[i][0]=dp[i][0];
    for(int j=1;j<=100000;j++)
    {
      p[i][j]=(dp[i][j]+p[i][j-1])%MOD;
    }
  }
  cout<<dp[n][k]<<endl;/*
  	loop(i,n+1)
   {
      loop(j,k+1)
      	cout<<dp[i][j]<<" ";
      cout<<endl;
     }
  cout<<";\n";
  loop(i,n+1)
   {
      loop(j,k+1)
      	cout<<p[i][j]<<" ";
      cout<<endl;
     }*/
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<pair<string, int>> v;
	vector<pair<string, int>> w;
	for( int i = 0; i < n; ++i ){
		string s;
		int p;
		cin >> s >> p;
		v.emplace_back(s, p);
		w.emplace_back(s, -p);
	}
	sort( w.begin(), w.end() );
	for( int i = 0; i < n; ++i ){
		for( int j = 0; j < n; ++j ){
			if( w[i].first == v[j].first && w[i].second == -1*(v[j].second) ){
				cout << j+1 << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int n, k;
  	cin >> n >> k;
  	vector<int> l(n);
  	for (int i = 0; i < n; i++){
    	cin >> l[i];
    }
  	sort(l.begin(), l.end(), greater<int>());
  	int snake = 0;
  	for (int i = 0; i < k; i++){
    	snake += l[i];
    }
  	cout << snake;
}

Measured memory_bytes: 256
#include<stdio.h>
int j,n,u,d[100],k[100],v[100][100],c[100][100];

void SSSP(int a,int x){
    int i;
    d[a]=x;
    for(i=0;i<k[a];i++){
        if(d[v[a][i]]>x+c[a][i]) SSSP(v[a][i],x+c[a][i]);
    }
}

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

    for(i=1;i<n;i++) d[i]=187349713;
    SSSP(0,0);
    for(i=0;i<n;i++) printf("%d %d\n",i,d[i]);

    return 0;
}


Measured memory_bytes: 2148
cost :: [Int] -> Int -> Int
cost [] _ = 0
cost (x:xs) a = (x - a) ^ 2 + cost xs a

main :: IO ()
main = do
    _ <- readLn :: IO Int
    as <- map read . words <$> getLine :: IO [Int]
    print $ minimum $ map (cost as) [minimum as .. maximum as]


Measured memory_bytes: 1020
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N = lread();
    long a = 1, b = 1;
    foreach (_; 0 .. N)
    {
        long T, A;
        scan(T, A);

        long ng = 0;
        long ok = (1000000000000000000 + max(T, A) - 1) / max(T, A);
        dprint((1000000000000000000 - 1 + max(T, A)), ok, T, A);
        while (abs(ng - ok) > 1)
        {
            long m = (ok + ng) / 2;
            long x = T * m;
            long y = A * m;
            if (x < a || y < b)
            {
                ng = m;
            }
            else
            {
                ok = m;
            }
        }
        a = T * ok;
        b = A * ok;
        dprint(ok, a, b);
    }
    writeln(a + b);
}


Measured memory_bytes: 3616
#include<stdio.h>
#include<string.h>
int main(void){
	char s[1000];
	scanf("%s",s);
	int len=strlen(s);
	if(s[len-1]=='s'){
		printf("%ses",s);
	}
	else{
		printf("%ss",s);
	}
	return 0;
}


Measured memory_bytes: 1736
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] tow1 = new int[3][10];
        int[][] tow2 = new int[3][10];
        int[][] tow3 = new int[3][10];
        int[][] tow4 = new int[3][10];
        int b = 0, f = 0, r = 0, v = 0;
        int num = sc.nextInt();

        for (int i = 0; i < num; i++) {
            b = sc.nextInt();
            f = sc.nextInt()-1;
            r = sc.nextInt()-1;
            v = sc.nextInt();
            if (b == 1) {
                tow1[f][r] += v;
            } else if (b == 2) {
                tow2[f][r] += v;
            } else if (b == 3) {
                tow3[f][r] += v;
            } else if (b == 4) {
                tow4[f][r] += v;
            }
            
    }
        for (int i = 0; i <= 2; i++) {
            for (int j = 0; j < 10; j++) {
                System.out.printf(" %d", tow1[i][j]);
            }
            System.out.println();
        }
        System.out.println("####################");
        for (int i = 0; i <= 2; i++) {
            for (int j = 0; j < 10; j++) {
                System.out.printf(" %d", tow2[i][j]);
            }
            System.out.println();
        }
        System.out.println("####################");
        for (int i = 0; i <= 2; i++) {
            for (int j = 0; j < 10; j++) {
                System.out.printf(" %d", tow3[i][j]);
            }
            System.out.println();
        }
        System.out.println("####################");
        for (int i = 0; i <= 2; i++) {
            for (int j = 0; j < 10; j++) {
                System.out.printf(" %d", tow4[i][j]);
            }
            System.out.println();
        }

        sc.close();
    }
}


Measured memory_bytes: 30252
/*
Competitive programming template
Author: Aswin Sampath

*/


#include<bits/stdc++.h>

using namespace std;


typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef priority_queue<ll,vl,greater<ll>()> pq_ll_min;
typedef priority_queue<ll> pq_ll_max; 
typedef stack<ll> s;
typedef queue<ll> q;


#define pi 3.141592653589793
#define PI  acos(-1.0)
#define space " "
#define endl '\n'
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

#define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define testcase ll t;cin>>t;while(t--)
#define dbxstl(x){for(auto ele:x)cout<<ele<<space; cout<<endl;}
#define dbxval(x){cout<<x<<endl;}

const ll INF = 1e18+7;
const ll MOD=1e9+7;
ll n,k;

void solve(vl &h){

    ll dp[n+1];
    memset(dp,INT_MAX,sizeof dp);
    dp[0]=0;
    dp[1]=0;

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

        dp[i]=INT_MAX;
        
        for(ll j=1;j<=k;j++){
            if(i-j>0){
                dp[i] = min(dp[i],dp[i-j] + abs(h[i-j]-h[i]));
            }

        }

    }

    // for(ll i=0;i<=n;i++){
    //     cout<<dp[i]<<space;
    // }
    // cout<<endl;

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

int main(int argc, char const *argv[])
{
    
    cin>>n>>k;

    vl h(n+1);
    for(ll i=1;i<=n;i++)cin>>h[i];

    solve(h);

    return 0;
}



Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int N = sc.nextInt();
		int sum = 0;
		for(int i = 0;i < N;i++){
			sum += sc.nextInt();
		}
		sc.close();
		if(sum >= H){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    set<int> s;
    rep(i, n) s.insert(a[i]);
    if (s.size() == n) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

typedef vector <vector<ll>> Mat;
int N; ll K;
Mat A;

Mat MatMal(Mat X, Mat Y){
  Mat ans; ans.resize(N);
  for (int i = 0; i < N; i++){
    ans[i].resize(N);
    for (int j = 0; j < N; j++){
      for (int k = 0; k < N; k++){
        ans[i][j] += X[i][k] * Y[k][j];
        ans[i][j] %= MOD;
      }
    }
  }
  return ans;
}

Mat MatPow(Mat M, ll P){
  Mat ans; ans.resize(N);
  for (int i = 0; i < N; i++) ans[i].resize(N);
  if (P == 0){
    for (int i = 0; i < N; i++) ans[i][i] = 1;
    return ans;
  }

  if (P % 2 == 0){
    return MatPow(MatMal(M, M), P / 2);
  }
  return MatMal(MatPow(MatMal(M, M), P / 2), M);
}


int main(){
  cin >> N >> K;
  A.resize(N);
  for (int i = 0; i < N; i++){
    A[i].resize(N);
    for (int j = 0; j < N; j++){
      cin >> A[i][j];
    }
  }
  Mat ans = MatPow(A, K);
  ll sum = 0;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      sum += ans[i][j]; sum %= MOD;
    }
  }
  cout << sum << endl;

  return 0;
}


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

int main()
{

    int total=0,c,n,m,x,i,d;
    cin>>n>>d>>x;
    while(n--){
        cin>>c;
        int mm=d/c;
        if(d%c)total+=mm+1;
        else total+=mm;
    }
    cout<<total+x<<endl;
    return 0;
}


Measured memory_bytes: 256