akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <atcoder/convolution>


using namespace std;
using namespace atcoder;

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> a(n),b(m);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < m; i++) cin >> b[i];
	vector<int> res = convolution<998244353>(a,b);
	for(int x : res){
		cout << x << " ";
	}
	return 0;
}


Measured memory_bytes: 19060
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 0x3f3f3f3f
int h[100005];
int main()
{
    int n,k,hmax,hmin;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++)
        scanf("%d",&h[i]);
    sort(h,h+n);
    int mi=maxn;
    for(int i=n-1;i>=0;i--)
    {
        hmax=h[i];
        if(i-k+1<0)
            break;
        hmin=h[i-k+1];
        int num=hmax-hmin;
        mi=min(mi,num);
    }
    printf("%d\n",mi);
    return 0;
    }




Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
#define pi 3.14159265358979323846
 
int main(){
  ios_base::sync_with_stdio(false);
  int n, m;
  cin>>n>>m;
  // vi a(n, 0);
  int sum=0;
  for(int i = 0; i < m; i++){
  	int x;
  	cin>>x;
  	sum += x;
  }

  if(n - sum < 0) cout<<-1<<endl;
  else cout<<(n-sum)<<endl;
 
}

Measured memory_bytes: 3192
a, b, m = map(int, input().split())
u = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = min(u) + min(v)
for i in range(m):
    x, y, c = map(int, input().split())
    ans = min(u[x - 1] + v[y - 1] - c, ans)
print(ans)

Measured memory_bytes: 70892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;cin>>n;
	ll ans = 0;
	rep(i, n){
		int a;cin>>a;
		ans += a-1;
	}
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;
const ll MOD = 1000000007;

int main() {
    ll N;
    cin >> N;
    vector<ll>a(N);
    ll total = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        a[i] = a[i]-(i+1);
        total += a[i];
    }
    
    sort(a.begin(), a.end());
    int num = a[N/2];
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += abs(a[i]-num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);
 
#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)
 
int n, a;
int cnt[3];
 
int main(int argc, char **argv) {
	cin >> n;
	REP(i, n) {
		cin >> a;
		if (a % 4 == 0) ++cnt[2];
		else if (a % 2 == 0) ++cnt[1];
		else ++cnt[0];
	}
	cout << (cnt[2] >= cnt[0] || (cnt[0] ==  cnt[2] + 1 && cnt[1] == 0) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<lint, lint> P;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int N;
	cin >> N;
	vector<int>H(N+1);
	rep(i, N) {
		cin >> H[i];
	}
	H[N] = 0;
	int cnt = 0;
	int ans = 0;
	while (1) {
		for (int i = 0; i < N; i++) {
			if (H[i] != 0) {
				H[i]--;
				if (H[i + 1] == 0) {
					cnt++;
				}
			}
		}
		if (cnt == 0) {
			break;
		}
		else {
			ans += cnt;
			cnt = 0;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python
import fractions

def count_antidivision(n, x, y):
    """
    returns count of numbers from 1 to n which are not dividable by x nor y.
    """
    return n - n // x - n // y + n // (x * y // fractions.gcd(x, y))    

def main(A, B, C, D):
    return count_antidivision(B, C, D) - count_antidivision(A-1, C, D)

if __name__ == '__main__':
    A, B, C, D = list(map(int, input().split()))
    print(main(A, B, C, D))




Measured memory_bytes: 64620
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <vector>
#define F first
#define S second
#define pb push_back
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vLL vector<LL>
using namespace std;
typedef long long LL;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vint a(n + 1), pre(n + 1, 1), suf(n + 1, 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    pre[1] = a[1];
    suf[n] = a[n];
    for (int i = 2; i <= n; i++)
    {
        pre[i] = hcf(a[i], pre[i - 1]);
    }
    for (int i = n - 1; i >= 1; i--)
    {
        suf[i] = hcf(a[i], suf[i + 1]);
    }
    int ans = 1;
    for (int i = 1; i <= n; i++)
    {
        if (i == 1)
        {
            ans = max(ans, suf[i + 1]);
        }
        else if (i == n)
        {
            ans = max(ans, pre[i - 1]);
        }
        else
        {
            ans = max(ans, hcf(pre[i - 1], suf[i + 1]));
        }
    }
    cout << ans << "\n";
    return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  int l=0,r=0;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
    r += v[i];
  }
  int res=1000*1000*1000;
  for(int i=0;i<n-1;i++){
    l += v[i];
    r -= v[i];
    res=min(res, abs(l-r));
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  vector<char> ans;
  rep(i, s.size()) {
    if (s[i] == 'B') {
      if (!ans.empty()) {
        ans.pop_back();
      }
    }
    else ans.push_back(s[i]);
  }
  rep(i, ans.size()) cout << ans[i];
  cout << endl;


  
  return 0;
}

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


int main(void){

	double r;
	cin >> r;
	cout << fixed << setprecision(7) << r*r*M_PI << " " << 2*r*M_PI << endl;
	return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define MM 1e9

int P,Q,R;

void input() {
    cin >> P >> Q >> R;
}

void solve(){
    int result=P+Q+R;
    result-=max(max(P,Q),R);
    cout << result << endl; 
}

int main() {
    input();
    solve();
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

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

bool prime[1000000];

int main()

{
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for(int i = 2; i * i < 1000000; i++){
    if(prime[i]){
      for(int j = 2; j * i < 1000000; j++){
	prime[i*j] = false;
      }
    }
  }
  int n;
  while(cin >> n && n){
    int cnt = 0;
    for(int i = n + 1; i <= 2 * n; i++){
      if(prime[i]) cnt++;
    }
    cout <<cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int agency();
int main(){agency();}
int agency(){
	int x,y;
	cin>>x>>y;
	if(x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12){
		if(y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12){
			cout<<"Yes"<<endl;
		}
		else{cout<<"No"<<endl;}
	}
	if(x==4 || x==6 || x==9 || x==11){
		if(y==4 || y==6 || y==9 || y==11){
			cout<<"Yes"<<endl;
		}
		else{cout<<"No"<<endl;}
	}
	if(x==2) cout<<"No"<<endl;
return 0;
}


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

#include <algorithm>

using namespace std;

int main()
{
	int x,a,b,c;
	scanf("%d %d %d %d",&a,&b,&c,&x);
	int count = 0;
	for(int i = 0;i <= a;i++)
	{	
		for(int j = 0;j <= b;j++)
		{	
			for(int k = 0;k <= c;k++)
			{
//				printf("1.%d %d\n",i,a);
//				printf("2.%d %d\n",j,b);
//				printf("3.%d %d\n",k,c);
				if( i*500 + j*100 + k*50 == x)
				{
			//		printf("%d %d %d",i,j,k);
					count++;
				}
			}
		}
	}
	printf("%d\n",count);
	return 0;
}

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

int a[3];

void input() {
    for (int i = 0; i < 3; ++i) cin >> a[i];
}

int main() {
    input();
    sort(a, a+3, less<int>());

    cout << a[0] << " " << a[1] << " " << a[2] << endl;
    return 0;
}


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

using namespace std;

int main() {
  int n; cin >> n;
  vector <int> a(n), ord(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    ord[i] = i;
  }
  auto comp = [&] (int x, int y) {
    return a[x] < a[y];
  };
  sort(ord.begin(), ord.end(), comp);
  for(auto x : ord) cout << x + 1 << ' ';
}

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

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

const int mod = 1000000007;

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

  int n, t;
  cin >> n >> t;

  vector<long> a(n);
  fillLong(a, n);

  vector<long> b(n);
  b[n-1] = 0;

  for(int i = n-2; i >= 0; i--) {
    b[i] = max(a[i+1], b[i+1]);
  }

  int mx = 0;
  int cnt = 0;
  rep(i, n-1) {
    if (mx < b[i]-a[i]) {
      mx = b[i]-a[i];
      cnt = 1;
    } else if (mx == b[i]-a[i]) {
      cnt++;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 2040
#include<stdio.h>
#include<iostream>

#define MAX_N 105

using namespace std;

int SelectionSort(int arr[], int N)
{
    int swapNum=0;
    for(int i=0; i<N-1; i++)
    {
        int minIdx=i;
        for(int j=i; j<N; j++)
        {
            if(arr[j]<arr[minIdx])
            {
                minIdx=j;
            }
        }
        if(minIdx!=i)
        {
            swap(arr[i], arr[minIdx]);
            swapNum++;
        }
    }
    return swapNum;
}

int main()
{
    int arr[MAX_N];
    int N;
    scanf("%d", &N);
    for(int i=0; i<N; i++)
        scanf("%d", arr+i);
    int res=SelectionSort(arr, N);
    printf("%d", arr[0]);
    for(int i=1; i<N; i++)
        printf(" %d", arr[i]);
    printf("\n");
    printf("%d\n", res);
    return 0;
}



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

int ma[200][200];

int main(void){
	while(1){
		for(int i=0; i<200; i++){
			for(int j=0; j<200; j++){
				ma[i][j] = 0;
			}
		}
		int n;
		cin >> n;
		if(n == 0) break;

		int w, h;
		cin >> w >> h;
		for(int i=0; i<n; i++){
			int tx, ty;
			cin >> tx >> ty;
			ma[ty][tx] = 1;
		}

		int s, t;
		cin >> s >> t;

		/*
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				printf("%d ", ma[i][j]);
			}
			puts("");
		}
		*/

		int ans = 0;
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				if(i+t <= h+1 && j+s <= w+1){
					int sum = 0;
					for(int k=i; k<i+t; k++){
						for(int l=j; l<j+s; l++){
							if(ma[k][l] == 1){
								//printf("%d %d %d %d\n", i, j, k, l);

								sum++;
							}
							//sum += ma[k][l];
						}
					}
					//cout << sum << endl;
					//printf("%d %d %d\n", i, j, sum);
					ans = max(ans, sum);
				}
			}
		}

		cout << ans << endl;


	}


	return 0;
}

Measured memory_bytes: 1320
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
using namespace std;

struct Node{
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x != NIL){
		y = x;
		if(z->key < x->key){
			x = x->left;
		} else {
			x = x->right;
		}
	}
	z->parent = y;
	if( y == NIL){
		root = z;
	} else {
		if(z->key < y->key){
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u){
	if( u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preoder(Node *u){
	if( u == NIL) return;
	printf(" %d", u->key);
	preoder(u->left);
	preoder(u->right);
}

int main(){
	int n;
	string s;
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>s;
		if(s == "print"){
			inorder(root);
			cout<<endl;
			preoder(root);
			cout<<endl;
		} else{
			int x;
			cin>>x;
			insert(x);
		}
	}
	
	return 0;
}


Measured memory_bytes: 26572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

// x番目のゴーレムをk番目のマスに移動させられるか確認する
bool checkLeft(int x, int k, string &s, vector<char> &t, vector<char> &d)
{
	for(int i = 0; i < t.size(); ++i)
	{
		if(t[i] == s[x])
		{
			if(d[i] == 'L')
			{
				--x;
			}
			else
			{
				++x;
			}
		}

		if(s[x] == '_')
		{
			return x == k;
		}
	}

	return false;
}

int main()
{
	int n, q;
	string s;

	cin >> n >> q;
	cin >> s;

	s = "_" + s + "_";

	vector<char > t(q);
	vector<vector<char> > d(2, vector<char>(q));
	for(int i = 0; i < q; ++i)
	{
		cin >> t[i] >> d[0][i];
		d[1][i] = (d[0][i] == 'L' ? 'R' : 'L');
	}

	//cout << "Hello" << endl;

	int bounds[2];
	int golem = n;

	for(int i = 0; i < 2; ++i)
	{
		//cout << "UKI!" << endl;
		int lb = 0, m, ub = n + 1;
		//for(int j = 0; j < 20; ++j)
		while(ub - lb > 1)
		{
			m = (ub + lb) / 2;
			//cout << lb << " " << m << " " << ub << endl;
			if(checkLeft(m, 0, s, t, d[i]))
			{
				lb = m;
			}
			else
			{
				ub = m;
			}
		}

		reverse(s.begin(), s.end());

		bounds[i] = lb;
		golem -= lb;
	}

	
	//cout << "Left " << bounds[0] << endl;
	//cout << "Right " << bounds[1] << endl;
	cout << golem << endl;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define rep(i, n, k) for(int i=k; i<n; ++i)
#define drep(i, n, k) for(int i=k; i>=n; --i)
using namespace std;

int main(){
  int n, a, b;
  cin >>  n >> a >> b;
  
  cout << min(n*a, b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void optimize_cpp_stdio() {
    std::ios::sync_with_stdio(false);
    std::cout.tie(NULL);
    std::cin.tie(NULL);
}
int N;
int x[105];
int leng(int xr){
	long long ans = 0;
	for(int i = 0; i < N; i++){
		ans += (x[i] - xr) * (x[i] - xr);
	}
	return ans;
}
int main(){
	optimize_cpp_stdio();
	while(cin >> N){
		int sum = 0;
		for(int i = 0; i < N; i++) {
			cin >> x[i];
		    sum += x[i];
		}
		if(sum % N == 0) cout << leng(sum / N) << endl;
		else{
			int m = sum / N;
			cout << min(leng(m), leng(m + 1)) << endl;
		}
	}
	return 0;
} 

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <bits/stdc++.h>
typedef long long ll;
typedef double flot;
using namespace std;
#define rep(i,a,b) for(long long int i=a;i<b;i++)
int main()
{
    ll n;
    cin>>n;
    set<string> k;
    while(n--)
    {string s;
    cin>>s;
        k.insert(s);
    }
    cout<<k.size();
}


Measured memory_bytes: 19260
#include <iostream>
#include <algorithm>

#define LEN 100005

using namespace std;

typedef struct _pair {
    string name;
    int t;
} Pair;

int main() {
    Pair queue[LEN];

    int n, q;
    cin >> n >> q; 
    for (int i = 0; i < n; i++) {
        cin >> queue[i].name >> queue[i].t;
    }

    int head = 0, tail = n;

    Pair task;
    int total_elapsed = 0;
    int place;
    while (head != tail) {
        place = head % LEN;
        task = queue[place];
        head++;
        int elapsed = min(task.t, q); 
        total_elapsed += elapsed;
        task.t = task.t - q;
        if (task.t <= 0) {
            cout << task.name << " " << total_elapsed << endl;
        } else {
            place = tail % LEN;
            queue[place] = task;
            tail++;
        }
    }

    return 0;
}


Measured memory_bytes: 6984
import math

def nCm(n, m):
    return math.factorial(n) / (math.factorial(m) * (math.factorial(n - m)))


N, P = list(map(int, input().split(" ")))
A = list(map(int, input().split(" ")))

odd = 0
even = 0
for a in A:
    if a % 2 == 0:
        even += 1
    else:
        odd += 1

ans = 0


if P == 0:
    k = 0
    for i in range(0, odd+1):
        if i%2==1 :
            continue
        elif i > odd:
            break
        k += nCm(odd, i)
    ans = (2**even)*k
        
else:
    k = 0
    for i in range(1, odd+1):
        if i%2==0 :
            continue
        elif i > odd:
            break
        k += nCm(odd, i)
    ans = (2**even)*k
print(int(ans))

Measured memory_bytes: 3064
import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.util.Arrays;

import java.util.Collections;

import java.util.Comparator;

import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        int N = Reader.nextInt();
        int A = Reader.nextInt();
        int tem = (N/500)*500 + A;
        if(tem>=N){System.out.println("Yes");}
        else{System.out.println("No");}
    }
}

class Reader {

    static BufferedReader reader;

    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */

    static void init(InputStream input) {

        reader = new BufferedReader(

                new InputStreamReader(input) );



        tokenizer = new StringTokenizer("");

    }



    static String nextToken() {

        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {

                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {

                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    /** get next word */

    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }



    static double nextDouble() throws IOException {

        return Double.parseDouble( next() );

    }



    static long nextLong() {

        return Long.parseLong(nextToken());

    }


}


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

int main() {
    int N; cin >> N;
    int ans = 0;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    while(1) {
        bool can_divide = true;
        for (int i = 0; i < N; i++) {
            if (A[i] % 2 != 0) {
                can_divide = false;
            }
        }
        if (can_divide) {
            for (int i = 0; i < N; i++) {
                A[i] /= 2;
            }
            ans++;
        } else {
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;





ll x,y,z,k;
ll a[1009], b[1009],c[1009];
vector<ll> vec;

int main(){

        cin >> x >> y >> z >> k;
        for(ll i = 0; i < x; i++) cin >> a[i];
        for(ll i = 0; i < y; i++) cin >> b[i];
        for(ll i = 0; i < z; i++) cin >> c[i];

        sort(a, a+x, greater<ll>());
        sort(b, b+y, greater<ll>());
        sort(c, c+z, greater<ll>());
        
        for(int i = 0; i < x; i++){
                for(int j = 0; j < y; j++){
                        for(int l = 0; l < z; l++){
                                if((i+1) * (j+1) * (l+1) <= k) vec.push_back(a[i] + b[j] + c[l]);
                                else break;
                        }
                }
        }

        sort(vec.begin(), vec.end(), greater<ll>());
        for(int i = 0; i < k; i++){
                cout << vec[i] << endl;
        }

        return 0;
}



Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow_(ll a, ll b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  map<int, int> mp;

  ll ans = 0;
  rep(j, n) {
    /*
    cout << endl << j - a[j] << endl;
    cout << "e" << endl;
    for (auto e : mp) cout << e.F << " " << e.S << endl;
    */
    // cout << mp[j - a[j]] << endl;
    if (mp.count(j - a[j])) ans += mp[j - a[j]];
    mp[a[j] + j]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 13400
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;

int f(int x){
    int ans = 0;
    if (x % 2 == 0) ans = x / 2;
    else ans = 3 * x + 1;

    return ans;
}

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

    vector<int> A;
    A.push_back(s);

    int counter = 1;
    int m = -1;
    while (1){
        if (m != -1) break;
        int tmp = f(A[counter - 1]);
        for (int i = 0; i < A.size(); i++){
            if (A[i] == tmp) m = counter + 1;
        }
        counter++;
        A.push_back(tmp);
    }

    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const llint INF = 100000000;

struct edge { int to, cost; };

int b_s(vector<vector<int>>& a, int key,int z) {
	int left = -1;
	int right = a[z].size();
	while (right - left > 1) {
		int mid = left + (right - left) / 2;
		if (a[z][mid] > key)right = mid;
		else left = mid;
	}
	return left;
}


int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	int x = 0;
	int y = 0;
	rep(i, 0, s.size()) {
		if (s[i] == 'W') {
			x++;
			y++;
		}
		else {
			ans += x;
			x = 0;
		}
	}
	int sum = y;
	rep(i, s.size() - y, s.size()) {
		if (s[i] == 'W')sum--;
	}
	ans = min(ans, sum);
	cout << ans << endl;
		return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(void)
{
    int n,m;
    int sum = 0;
    cin >> n >> m;
    vector<vector<int>> A(n, vector<int>(m));
    vector<int> b(m);
    REP(i,n) {
        REP(j,m) cin >> A.at(i).at(j);
    }
    REP(i,m) cin >> b.at(i);
    REP(i,n) {
        REP(j,m) {
            sum += A.at(i).at(j) * b.at(j);
        }
        cout << sum << endl;
        sum = 0;
    }
}



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

int mul(int num){
	int b = 1;
	rep(i,num-1){
		b *= 2;
	}
	return b;
}
	
int main(){
	string s;
	cin >> s;
	long long ans = 0;
	long long num = 0;
	int size = s.size();
	for(int x = 0; x < mul(size); ++x){
		string temp;
		temp = s.at(size-1);
		for(int i = 0; i < (size-1); ++i){
			if(x & (1 << i)){
				num = stoll(temp);
				ans += num;
				temp = s.at(size-2-i);
			}else{
				temp.insert(temp.begin() ,s.at(size-2-i));
			}
		}
		ans += stoll(temp);
	}
	
		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 < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, X, T; cin >> N >> X >> T;        
    cout << ((N+X-1)/X) * T << endl;
}

Measured memory_bytes: 3636
#include <iomanip>
#include <string>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
	string a, b;
	cin >> a >> b;
	if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define rep(i,j,k) for(int i=j; i<k; ++i)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io 
	int h,a;
	cin>>h>>a;
	cout<<ceil(h*D/a);
	
	return 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << "," << a.second << ")";return os;}

array<array<int,2>,1000010> dp;

int main() {
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    int n = s.size();
    dp[0][1] = 1e9;
    for (int i = 0;i < n;++i) {
        dp[i+1][0] = min(dp[i][0],dp[i][1]+1)+s[i]-'0';
        dp[i+1][1] = min(dp[i][0],dp[i][1]-1)+10-(s[i]-'0');
    }
    cout << min(dp[n][0],dp[n][1]+1) << endl;
}

Measured memory_bytes: 9220
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int sum=0;
	for(int i=1;i<=n-1;i++){
		for(int j=1;i*j<n;j++){
			sum++;
		}
	}
	cout<<sum<<endl; 
	return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <queue>

using namespace std;

int N;
int A[200000], B[200000];

typedef pair<int, int> P;

priority_queue<P> que;

int main(){
    cin >> N;
    long ans = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++){
        cin >> B[i];
    }
    for(int i = 0; i < N; i++){
        if(A[i] != B[i]){
            que.push(P(B[i], i));
        }
    }
    while(!que.empty()){
        P top = que.top();
        que.pop();
        int idx = top.second;
        int m = top.first;
        int il = (idx-1+N)%N;
        int ir = (idx+1)%N;
        int n = ((max(B[il], B[ir])/(B[il]+B[ir])))*(B[il]+B[ir]) + m%(B[il]+B[ir]);
        ans += (m-n)/(B[il]+B[ir]);
        if(n > max(B[il], B[ir])){
            ans++;
            n -= (B[il]+B[ir]);
        }
        //cout << m << ' ' << n << ' ' << (B[il]+B[ir]) << endl;
        //cout << ans << endl;
        B[idx] = n;
        if(B[idx] < A[idx]) {
            if((B[idx]-A[idx])%(B[il]+B[ir]) == 0){
                ans -= (A[idx]-B[idx])/(B[il]+B[ir]) ;
                B[idx] = A[idx];
            }else{
                cout << -1 << endl;
                return 0;
            }
        }
        if(B[idx] != A[idx]) que.push(P(B[idx], idx));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define maxn 1000000
using namespace std;
vector<int> G[maxn]; 
queue<int> q;
long long dis[maxn],w[maxn];
int in[maxn],nex[maxn],first[maxn],to[maxn],tot,vis[maxn],ins[maxn];
int n,m,p;
void add(int u,int v,int we)
{
	nex[++tot]=first[u];	
	first[u]=tot;
	to[tot]=v;
	w[tot]=we;
}
int spfa()
{
	while(q.size())q.pop();
	fill(dis,dis+n+1,1e12);
	dis[1]=0;
	q.push(1);
	while(q.size())
	{
		int u=q.front();
		q.pop();
		in[u]=0;
		for(int e=first[u];e;e=nex[e])
		{
			int v=to[e];
			if(w[e]+dis[u]<dis[v])
			{
				if(!ins[v])continue;
				dis[v]=dis[u]+w[e];
				if(in[v])continue;
				vis[v]++;
				if(vis[u]>=n)return 0; 
				q.push(v);
				in[v]=1;
			}
		}
	}
	return 1;
}
void bfs()
{
	q.push(n);
	while(q.size())
	{
		int u=q.front();
		ins[u]=1;
		q.pop();
		for(int i=0;i<G[u].size();i++)
		{
			int v=G[u][i];
			if(ins[v])continue;
			q.push(v);
		}
	}
}
inline bool dfs(int p){
	if(in[p])return 0;
	if(p==n)return 1;
	in[p]=1;
	for(int e=first[p];e;e=nex[e])if(dfs(to[e]))return 1;
	return 0;
}
int main()
{
//	freopen("in.txt","r",stdin);
	cin>>n>>m>>p;
	for(int i=1;i<=m;i++)
	{
		int u,v,val;
		scanf("%d%d%d",&u,&v,&val);
		G[v].push_back(u);
		add(u,v,-(val-p));
	}
 //	bfs();	
 	memset(ins,1,sizeof(ins));
 	for(int i=1;i<=n;++i){
		if(!dfs(i))ins[i]=0;
		memset(in,0,sizeof(in));
	}
	if(!spfa())cout<<-1<<endl;
	else cout<<(dis[n]>=0?0:-dis[n]);
	return 0;
}  

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

int main(){
    int H, W;
    cin >> H >> W;
    vector<char> header_footer(W+2, '#');

    for(int i=0; i < W+2; i++){
        cout << header_footer.at(i);
    }
    cout << endl;

    for(int h=0; h < H; h++){
        cout << '#';

        string buffer;
        cin >> buffer;
        cout << buffer;
        cout << '#' << endl;
    }

    for(int i=0; i < W+2; i++){
        cout << header_footer.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 256
/*
* @author:  codancer
* @createTime:  2020-09-27, 23:02:31
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
#define deb(x) cerr<<#x<<" = "<<(x)<<"\n"
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll Rand(ll B) {
	return (ull)rng() % B;
}
int n,m;
const int N = 2e5+100;
vector<int> G[N];
bool vis[N];
int u,v;
void DFS(int u){
	if(vis[u]) return ;
	vis[u]=1;
	for(int v:G[u]) DFS(v);
}
int main(){
	cin>>n>>m;
	rep(i,1,m){
		cin>>u>>v;
		G[u].pb(v);
		G[v].pb(u);
	}
	int ans=0;
	rep(i,1,n){
		if(!vis[i]){
			++ans;
			DFS(i);
		}
	}
	cout<<ans-1<<endl;
	return 0;
}

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

#define MOD 1000000007
#define ll long long int 
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll dp[1000][1000];

int main()
{
    off;

    int h, w;cin>>h>>w;

    string s[h];
    for (int i = 0; i < h; ++i)
    {
        cin>>s[i];
    }

    dp[h-1][w-1] = 1;

    for (int i = w-2; i >= 0; --i)
    {
        if(s[h-1][i]=='#') dp[h-1][i] = 0;
        else dp[h-1][i] = dp[h-1][i+1];
    }

    for (int i = h-2; i >= 0; --i)
    {
        for (int j = w-1; j >= 0; --j)
        {
            if(s[i][j]=='#')
                dp[i][j] = 0;
            else{
                dp[i][j] = dp[i+1][j];
                if(j!= w-1)
                    dp[i][j] = (dp[i][j] + dp[i][j+1])%MOD;
            }
            // cout<<dp[i][j]<<" ";
        }
        // cout<<endl;
    }

    cout<<dp[0][0];

    return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#include <math.h>
#include <iomanip>

const double PI = 3.14159265358979323846;

int main() {

	int A,B,H,M;
	double ans,ji,hun,angle;
	cin >> A >> B >> H >> M;

	ji = H * 30 + M*0.5;
	hun = M*6.0;
	angle = ji - hun;

	ans = sqrt(A*A + B*B - 2 * A*B*cos(2*PI*angle/360.0));

	cout << std::fixed << std::setprecision(15)<< ans;

	cin >> ans;

	return 0;


}

Measured memory_bytes: 4192
while True:
    h,w = map(int, input().split())
    if h==0 and w==0:
        break
    
    for i in range(h):
        for j in range(w):
            if i % 2 == 0:
                if j % 2 == 0:
                    print("#",end="")
                else:
                    print(".",end="")
            else:
                if j % 2 == 0:
                    print(".",end="")
                else:
                    print("#",end="")
        print()
    print()


Measured memory_bytes: 7004
// Contest.cpp : アプリケーションのエントリ ポイントを定義します。
//

#include"iostream"
#include"string"
#include"vector"
#include"algorithm"

using namespace std;


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

	if (a =="A") 
	{
		cout << "T" << endl;
	}
	if (a == "T")
	{
		cout << "A" << endl;
	}
	if (a == "G")
	{
		cout << "C" << endl;
	}
	if (a == "C")
	{
		cout << "G" << endl;
	}
	return 0;
}




Measured memory_bytes: 256
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll n,q,a[100010],b,c,i,ans=0;
  vector<int> s(100010,0);
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a[i];
    ans+=a[i];
    s[a[i]]++;
  }
  cin >> q;
  for(i=0;i<q;i++){
    cin >> b >> c;
    ans=ans-s[b]*b+s[b]*c;
    s[c]+=s[b];
    s[b]=0;
    cout << ans << endl;
  }
  return 0;
}

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){} //@shibh308's template
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

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

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

const int NMAX = 200;
bool flag;

bool comp(int x,int y){
    return abs(0-x)<abs(0-y);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    CIN(M1,D1,M2,D2);
    printf("%d\n",M2==M1+1&&D2==1?1:0);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// int main() {
//     // 3^45 mod. 1000000007 を計算してみる
//     cout << modpow(3, 2, 1000000007) << endl;
// }

const ll mod = 1000000000+7;

ll c[200010];

int main () {

    int n;cin>>n;

    ll ans=0;

    rep(i,n) {
        cin>>c[i];
    }

    sort(c,c+n);

    for (int i=1;i<=n;i++) {
        ans = (ans+((n-i)*modpow(2,n-2,mod)%mod+modpow(2,n-1,mod))%mod*c[i-1]%mod)%mod;
    }

    ans = (ans*modpow(2,n,mod))%mod;

    cout<<ans<<endl;

}

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

int main() {
  
  int A, B;
  cin >> A >> B;
  bool flag = false;
  
  for(int i=1; i<=20; i++){
    if( A*i==B ){
      flag = true; 
    }
  }
  
  if(flag){
    cout << A+B << endl;
  }
  else{
    cout << B-A << endl;
  }
}


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

using namespace std;

struct entry {
    string city;
    int score;
    int id;
};

bool compare_entries(entry left, entry right) { // returns true if left < right
    if (left.city != right.city){
        return left.city < right.city;
    }

    return left.score > right.score;

}

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

    vector<entry> entries;

    for (int i = 0; i < n; i++){
        string city;
        int score;
        cin >> city >> score;

        entries.push_back(entry{city, score, i+1});

    }

    sort(entries.begin(), entries.end(), &compare_entries);

    for(entry e : entries) {
        cout << e.id << "\n";
    }

    return 0 ;
}

Measured memory_bytes: 764
from itertools import product as prod
N,M,X=map(int,input().split())
B=[list(map(int,input().split())) for _ in range(N)]
ans=float('INF')
for v in prod(range(2),repeat=N):
  scores=[0]*M
  cost=0
  for i in range(N):
    if v[i]==1:
      cost+=B[i][0]
      for j in range(M):
        scores[j]+=B[i][1+j]
  if min(scores)>=X:
    ans=min(ans,cost)

print(ans if ans!=float('INF') else -1)

Measured memory_bytes: 9224
<?php
fscanf(STDIN,"%d",$n);
$arr=explode(' ',trim(fgets(STDIN)));

$min=0;
$cnt=count($arr);
for($i=0;$i<$cnt;$i++){
	$sum +=$arr[$i];
}
$kekka_arr=array();
for($i=0;$i<$cnt;$i++){
	$mae += $arr[$i];
	$ato  = $sum - $mae;
	$kekka_arr[$i]=abs($mae-$ato);
}

echo min($kekka_arr);
?>

Measured memory_bytes: 3956
from heapq import heappush,heappop
H,W = map(int,input().split())
inf=10**10
#[k][j][i]
dp=[[[inf]*10 for i in range(10)]for i in range(11)]
for j in range(10):
    c=[int(k) for k in input().split()]
    for i in range(10):
        dp[0][i][j]=c[i]#jiへのコスト

A=[[int(i) for i in input().split()] for i in range(H)]
for k in range(1,11):
    for j in range(10):
        for i in range(10):
            dp[k][j][i]=min(dp[k-1][j][i],dp[k-1][j][k-1]+dp[k-1][k-1][i])
ans =0
for i in range(W):
    for j in range(H):
        if A[j][i]!=-1 and A[j][i]!=1:
            ans += dp[10][1][A[j][i]]
print(ans)

Measured memory_bytes: 3444