akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)

int main() {
  double a,b,h,m;cin >> a>>b>>h>>m;
  double pi = 4.0d * atan(1.0d);
  double ax = a * sin(2.0d * pi * (double)h / 12.0d + 2.0d * pi * (double)m / 720.0d);
  double ay = a * cos(2.0d * pi * (double)h / 12.0d + 2.0d * pi * (double)m / 720.0d);
  double bx = b * sin(2.0d * pi * (double)m / 60.0d );
  double by = b * cos(2.0d * pi * (double)m / 60.0d );
  double out = sqrt((ax-bx)*(ax-bx) + (ay-by)*(ay-by));
  cout << fixed << setprecision(15) << out << endl;
  return 0;
}


Measured memory_bytes: 4080
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(),std::greater<int>())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (v[i] >= c[i]) ans += v[i] - c[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//此程序使用了qt专属名称，请勿模仿。侵权必究！！！
//我真是太菜了…… 
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=10010,P=1<<30;
int n,a[N];
ll ans=0;
inline int read()
{
	int sum=0,flag=1;
	char c;
	for(;c<'0'||c>'9';c=getchar())if(c=='-') flag=-1;
	for(;c>='0'&&c<='9';c=getchar())sum=(sum<<1)+(sum<<3)+c-'0';
	return sum*flag;
}
inline int findx(int k)
{
	int l=1,r=n,m;
	while(l+1<r)
	{
		m=(l+r)>>1;
		if(a[m]>k)
		{
			r=m;
		}
		else
		{
			l=m;
		}
	}
	if(a[l]>k)
	{
		return l;
	}
	else
	{
		return r;
	}
}
inline int findy(int k)
{
	int l=0,r=n+1,m;
	while(l+1<r)
	{
		m=(l+r)>>1;
		if(a[m]<k)
		{
			l=m;
		}
		else
		{
			r=m;
		}
	}
	if(a[r]<k)
	{
		return r;
	}
	else
	{
		return l;
	}
}
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	for(int i=1;i<=n;++i)
	{
		a[i]=read();
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=n;++j)
		{
			if(i!=j)
			{
				int l=findx(abs(a[i]-a[j]));
				int r=findy(a[i]+a[j]);
				l=max(l,1);
				r=min(r,n);
				ans+=1ll*max(r-l+1-(i>=l&&i<=r)-(j>=l&&j<=r),0);
			}
		}
	}
	printf("%lld\n",ans/6);
	return 0;
}

Measured memory_bytes: 256
from collections import deque
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
import itertools

n, m, r = map(int,input().split())
rlist = list(map(int,input().split()))
for i in range(r):
    rlist[i] -= 1
e = np.zeros((n,n), dtype=int)

for i in range(m):
    a, b, c = map(int,input().split())
    a -= 1
    b -= 1
    e[a][b] = c
    e[b][a] = c
csr = csr_matrix(e)
f = floyd_warshall(csr)

ans = 10**18
for v in itertools.permutations(rlist,r):
    d = 0
    for i in range(r-1):
        d += f[v[i]][v[i+1]]
    ans = min(ans, d)
print(int(ans))

Measured memory_bytes: 38684
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<'='<<x<<' '
typedef long long ll;
typedef pair<int,int> pi;

const int MAXN = 1e5+5;
int N,K,A[MAXN],dp[MAXN];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> K;
    for (int i = 1; i <= N; i++) cin >> A[i];
    memset(dp,63,sizeof(dp));
    dp[1] = 0;
    dp[2] = abs(A[1]-A[2]);
    for (int i = 3; i <= N; i++) {
        for (int j = 1; j <= K; j++) {
            if (i >= j) dp[i] = min(dp[i],abs(A[i]-A[i-j])+dp[i-j]);
            else break;
        }
    }
    //for (int i = 1; i <= N; i++) debug(dp[i]);
    cout << dp[N];
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
#define mp make_pair
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return sorted 約数s 1 <= x <= n
vector<ll> divv(ll n) {
  vector<ll> v;
  for(ll i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.push_back(i);
      if(i*i != n) v.push_back(n/i);
    }
  }
  sort(ALL(v));
  return v;
}

int main() {
    ll n,m,l;
    string s;
    cin>>n;
    vector<pair<string, pair< ll, ll>>> v;
    rep(i,n){
        ll a;
        string s;
        cin>>s>>a;
        v.push_back(make_pair(s,make_pair(-a, i+1)));
    }
    sort(ALL(v));
    rep(i,n) {
        pr(v[i].second.second);
    }
    return 0;
}

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

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int p = 0, q = 0;
    int r = max(x, y) * 2;
    int ans = 1001001001;
    while (r >= 0) {
        p = max(0, x - r / 2);
        q = max(0, y - r / 2);
        ans = min(ans, a * p + b * q + c * r);
        r -= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// Main.java

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		long Y = sc.nextLong();
		int counter = 0;
		while(X <= Y) {
			X *= 2;
			counter++;
		}
		System.out.println(counter);
	}
}

Measured memory_bytes: 21844
//0000111110001について考えたら解けた。
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
string s;
vector<int> a;

signed main() {
	int i;
	
	cin >> s;
	a.push_back(0);
	
	int len = 1;
	for (i = 1; i < s.length(); i++) {
		if (s[i - 1] == s[i]) { len++; }
		else { a.push_back(len); len = 1; }
	}
	a.push_back(len);
	a.push_back(0);
	
	int pre = a[0];
	int suf = s.length() - a[0] - a[1];
	int ans = 0;
	for (i = 1; i < a.size() - 1; i++) {
		int eval = min(pre, suf) + a[i];
		ans = max(ans, eval);
		pre += a[i];
		suf -= a[i + 1];
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
#define int ll
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define int ll

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).last()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = INT_MAX;


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

	int cnt = 0;
	bool ok = 0;
	F0R(i, n) {
		int a, b;
		cin >> a >> b;

		if (a == b) cnt++;
		else cnt = 0;

		if (cnt == 3) ok = 1;
	}
	if (ok) cout << "Yes";
	else cout << "No";
}

int32_t main() {
	_

#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
	solve();
	cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}

Measured memory_bytes: 3804
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <string>
using namespace std;
vector<int> pos[3];
int main(){
    int n;
    string s;
    cin>>n>>s;
    for(int i=0; i<n; i++){
        if(s[i]=='R'){
            pos[0].push_back(i);
        }else if(s[i]=='G'){
            pos[1].push_back(i);
        }else{
            pos[2].push_back(i);
        }
    }
    long long res = 0;
    for(int i=0; i<pos[0].size(); i++){
        for(int j=0; j<pos[1].size(); j++){
            int a = pos[0][i], b = pos[1][j];
            if(a>b) swap(a, b);
            int ite;
            long long now=pos[2].size();
            
            if((b-a)%2 == 0){
                ite = (b-a)/2;
                vector<int>::iterator it = find(pos[2].begin(), pos[2].end(), a+ite);
                if(it!=pos[2].end()) --now;
            }
            ite = b-a;
            if(b+ite<n){
                vector<int>::iterator it = find(pos[2].begin(), pos[2].end(), b+ite);
                if(it!=pos[2].end()) --now;
            }
            if(a-ite>=0){
                vector<int>::iterator it = find(pos[2].begin(), pos[2].end(), a-ite);
                if(it!=pos[2].end()) --now;
            }
            res += now;
        }
    }
    cout<<res<<endl;
    
    return 0;
}




Measured memory_bytes: 3668
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int n, a[100], average = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
    average += a[i];
  }

  average = average / n + (n - (average % n) > average % n ? 0 : 1);
  long ans = 0;
  for(int i = 0; i < n; i++){
    ans += ((long)a[i] - (long)average) * ((long)a[i] - (long)average);
  }
  printf("%ld\n", ans);

  return 0;
}


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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N){
    cin >> A.at(i);
  }
  vector<ll> a(N);
  vector<ll> b(N);
  rep(i, N){
    a.at(A.at(i)-1)++;
    b.at(A.at(i)-1)+=a.at(A.at(i)-1)-1;
  }
  ll sum = 0;
  rep(i, N){
    sum += b.at(i);
  }
  rep(i, N){
    ll ans = 0;
    ans = sum - a.at(A.at(i)-1)+1;
    cout << ans << endl;
  }
}


Measured memory_bytes: 7296
def func(a,b,x):
    return int(a*x/b)-a*int(x/b)

a,b,n = map(int,input().split())
if b==1 or a==1:
    print(0)
    exit()
if n<b:
    print(func(a,b,n))
else:
    print(func(a,b,b-1))

Measured memory_bytes: 9184
#include <iostream>
#include <cstdio>
#include <complex>

using namespace std;
typedef long long ll;

typedef double R;
typedef complex<R> P;

const R EPS = 1e-10;
const R PI = acos(-1);
int sgn(R a) {
    if (a < -EPS) return -1;
    if (a > EPS) return 1;
    return 0;
}


bool near(P a, P b) {
    return !sgn(abs(a-b));
}

double cross(const P &a, const P &b) { return imag(conj(a)*b); }
double dot(const P &a, const P &b) { return real(conj(a)*b); }

P p[4];
void solve() {
    p[0] -= p[3];
    p[1] -= p[3];
    p[2] -= p[3];
    int u = 0;
    for (int i = 0; i < 3; i++) {
        P p1 = p[i], p2 = p[(i+1)%3];
        if (p1.imag() > p2.imag()) swap(p1, p2);
        if (p1.imag() > 0 || p2.imag() <= 0) continue;
        if (cross(p1, p2) < 0) continue;
        u++;
    }
    if (u == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


int main() {
    while (true) {
        for (int i = 0; i < 4; i++) {
            R x, y;
            cin >> x >> y;
            p[i] = P(x, y);
        }
        if (cin.eof()) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1228
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
// define
#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()
// typedef
typedef long long lint;
typedef double Double;
typedef pair<int, int> pii;
//
typedef vector< int > Array;
typedef vector< Array > Matrix;
typedef vector< Double > DArray;
typedef vector< DArray > DMatrix;
typedef vector< string > SArray;
typedef vector< pii > PArray;
// popcount
inline int POPCNT(int _x) { return __builtin_popcount(_x); }
inline int POPCNT(lint _x) { return __builtin_popcountll(_x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
Double EPS = 1e-9;
// in range
inline bool in_range(int _v, int _mx, int _mi) { return _mi <= _v && _v < _mx; }
inline bool in_range(Double _v, Double _mi, Double _mx) { return -EPS < _v - _mi && _v - _mx < EPS; }
inline bool in_range(int _x, int _y, int _W, int _H) { return 0 <= _x && _x < _W && 0 <= _y && _y < _H; }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
inline void modAdd(int& _a, int _b, int _m) { _a = (_a + _b) % _m; }
inline void modAdd(lint& _a, lint _b, lint _m) { _a = (_a + _b) % _m; }
inline void minUpdate(int& _a, int _b) { _a = min(_a, _b); }
inline void minUpdate(lint& _a, lint _b) { _a = min(_a, _b); }
inline void maxUpdate(int& _a, int _b) { _a = max(_a, _b); }
inline void maxUpdate(lint& _a, lint _b) { _a = max(_a, _b); }

int n;

void rec(int x, Array& v, int sum) {
	if (sum > n) return;
	
	int len = size_of(v);
	
	if (sum == n) {
		for_(i,0,len) {
			if (i < len - 1) cout << v[i] << " ";
			else cout << v[i] << endl;
		}
	}

	for_rev(i,x,1) {
		if (len > 0 && v[len - 1] < i) continue;
		v.push_back(i);
		rec(max(x, x - i), v, sum + i);
		v.pop_back();
	}
}

void solve() {
	Array v;
	rec(n, v, 0);
}

int main() {
	while (cin >> n, n) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 1220
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

typedef struct obj{
	struct obj **word;
	int isIn;
}words;

words *createObj(){
	int i;
	words *W;
	mymalloc(W,1);
	mymalloc(W->word,4);
	for(i=0;i<4;i++){
		W->word[i]=NULL;
	}
	W->isIn=0;
	return W;
}

int num(char w){
	if(w=='A'){
		return 0;
	}else{
	if(w=='T'){
		return 1;
	}else{
	if(w=='G'){
		return 2;
	}else{
	if(w=='C'){
		return 3;
	}}}}
}

void insert(words *W,char *key){
	int i,l;
	words *w;
	l=strlen(key);
	w=W;
	for(i=0;i<l;i++){
		if(w->word[num(key[i])]!=NULL){
			w=w->word[num(key[i])];
		}
		else{
			w->word[num(key[i])]=createObj();
			w=w->word[num(key[i])];
		}
	}
	w->isIn=1;
	
}

int find(words *W,char *key){
	int i,l;
	words *w;
	l=strlen(key);
	w=W;
	for(i=0;i<l;i++){
		if(w->word[num(key[i])]!=NULL){
			w=w->word[num(key[i])];
		}
		else{
			return 0;
		}
	}
	if(w->isIn==1){return 1;}
	else{return 0;}
}

void freeWord(words *W,int depth){
	int i;
	for(i=0;i<4;i++){
		if(W->word[i]!=NULL){
			freeWord(W->word[i],depth+1);
		}
	}
	free(W->word);
	free(W);
}
	
	
main(){
	int i,n,mes;
	char com[7],str[14];
	words *W;
	W=createObj();
	scanf("%d ",&n);
	for(i=0;i<n;i++){
		scanf(" %s %s",com,str);
		if(strcmp(com,"find")==0){
			mes=find(W,str);
			if(mes==0){
				puts("no");
			}
			else{
				puts("yes");
			}
		}
		else{
			insert(W,str);
		}
	}
	freeWord(W,0);
	return 0;
}

Measured memory_bytes: 27764
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static int[] S ;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		if(W.charAt(2)==W.charAt(3)&&W.charAt(4)==W.charAt(5)){
			System.out.println("Yes");
		}else{
			System.out.println("No");

		}


	}

}


Measured memory_bytes: 21204
(r,c) = tuple(map(int,input().split()))
graph = []
for i in range(r):
  lst = list(map(int,input().split()))
  lst.append(sum(lst))
  graph.append(lst)
lsf = []
for i in range(c + 1):
  s = 0
  for j in range(r):
    s += graph[j][i]
  lsf.append(s)
for l in graph:
  print(' '.join(map(str,l)))
print(' '.join(map(str,lsf)))




Measured memory_bytes: 5700
h,w,k=map(int,input().split())
c = [list(input()) for i in range(h)]
#print(c[1])
sum=0
f=[0]*h
g=[0]*w
for i in range(0,h):
	f[i]=c[i].count("#")
	sum+=f[i]
#for i in range(0:h)
	#for j in range(0:w):
		#if c[i][j]=="#"
			#g[j]+=1
ans=0
for bit in range(1<<h+w):
	d=list(range(h)) #赤にならない列番号
	e=sum #各選び方での黒の数
	for j in range(h+w):
		if(bit>>j)&1:
			if j<h:
				d.remove(j)
				e-=f[j]
				#print(j,d,e)
			else:
				for l in d:
					if c[l][j-h]=="#":
						e-=1
	if e==k:
		ans+=1

print(ans)

Measured memory_bytes: 9196
//	ZapZu's code hohoho
//	#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef double db;
typedef long long li;
typedef long double ld;

typedef pr<int, int> ii;
typedef pr<ld,ld> dd;

typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;

typedef set<int> s_i;
typedef set<char> s_c;

const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
int s[2005], t[2005];
li dp[2005][2005];
signed main()
{
//	freopen(".inp", "r", stdin);
//	freopen(".out", "w", stdout);
	int n, m;
	cin>>n>>m;
	dp[0][0]=1;
	for(int i=1; i<=n; i++)
	{
		cin>>s[i];
		dp[i][0]=1;
	}
	for(int j=1; j<=m; j++)
	{
		cin>>t[j];
		dp[0][j]=1;
	}
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=m; j++)
		{
			if(s[i]==t[j]) dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
			else dp[i][j]=(dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]+MOD)%MOD;
//			cout<<i<<" "<<j<<dp[i][j]<<endl;
		}
	}
//	for(int i=0;i<=n;i++)
//	{
//		for(int j=0;j<=m;j++)
//		{
//			cout<<dp[i][j]<<" ";
//		}
//		cout<<endl;
//	}
	cout<<dp[n][m];
}


Measured memory_bytes: 31616
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve s | x > y     = show x
        | otherwise = show y
 where
  [a, b, c, d] = fmap read (words s) :: [Int]
  x            = a * b
  y            = c * d

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 508
s=input()
f=int(s[0:2])
l=int(s[2:4])

if 12>=f>=1 and 12>=l>=1:
    k=3
elif not(12>=f>=1) and 12>=l>=1:
    k=1
elif not(12>=l>=1) and 12>=f>=1:
    k=2
else:
    k=4
ans=['','YYMM','MMYY','AMBIGUOUS','NA']
print(ans[k])


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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;

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()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  vector<int> check(N);
  for (int i = 0; i < N; i++)
  {
    check[A[i]]++;
  }
  bool can = true;
  if (N % 2 != 0)
  {
    if (check[0] != 1)
      can = false;
  }
  for (int i = N - 1; i > 0; i -= 2)
  {
    if (check[i] != 2)
      can = false;
  }
  if (!can)
    cout << 0 << endl;
  else
  {
    ll ans = modpow(2, N / 2, MOD);
    cout << ans << endl;
  }
  return 0;
}

// Nが偶数の場合はN - 1, N - 3, N - 5,..., 3, 1が2個ずつなかったらアウト．奇数の場合はこれ＋0が1個なかったらアウト．okの場合は2^(N/2)となる．（切り捨てだから奇数のときも偶数のときも成り立つ）


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

 
int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    long long res = LONG_LONG_MAX;

    bool F[2] = {true,false};
    rep(i,2){
        bool flag = F[i];
        long long sum = 0;
        long long count = 0;
        rep(i,N){
            sum += A[i];
            if(flag){
                if(sum < 1){
                    count += 1 - sum;
                    sum = 1;
                }
                flag = false;
            }else{
                if(sum > -1){
                    count += sum + 1;
                    sum = -1;
                }
                flag = true;
            }
        }
        res = min(res,count);
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
using namespace std;

int main()
{
  int n;
  cin>>n;
  vector<long long> a(n),b(n);
  for(int i=0;i<n;i++)cin>>a[i]>>b[i];
  long long ans=0ll;

  for(int i=n-1;i>=0;i--){
    ans+=(b[i]-(a[i]+ans)%b[i])%b[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <vector>
#define ll long long
#define INF 1000000001;
using namespace std;
struct Edge{int from, to, cost;};

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

    int Q,H,S,D;
    cin >> Q >> H >> S >> D;
    int N;
    cin >> N;

    int a = Q;
    int b = min(a*2, H);
    int c = min(b*2, S);
    int d = min(c*2, D);


    ll cost = 0;
    
    ll a_l = (N/2);
    cost += a_l*d;
    N -= a_l*2;
    if(N != 0){
        ll b_l = floor(N);
        cost += b_l*c;
        N -= b_l;  
    }
    if(N != 0){
        ll c_l = 1;
        cost += c_l*b;
        N -= c_l;
    }
    if(N != 0){
        ll d_l = 1;
        cost += d_l*a;
        N -=d_l;
    }

    
    cout << cost << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
ll n, i;
ll a[200200];
using namespace std;

int main(){
    cin >> n;
    ll tmp;
    a[0] = 0;
    for(i = 1; i <= n; i++){
        cin >> tmp;
        a[i] = tmp + a[i-1];
    }
    ll m = 2e9+1;
    for(i = 1; i < n; i++){
        m = min(m, abs(2*a[i] - a[n]));
    }
    cout << m << endl;
    return 0;
}

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

using namespace std;
#define pb push_back
#define db(x) cerr << #x << " = " << x << endl;
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define vi vector<int>
#define vll vector<ll>
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define ll long long
#define ull unsigned long long
typedef long double ld;

const int MAXN = 112;
const int MAXK = 112345;

int n, k;
int vals[MAXN];
int vis[MAXK][2];
bool dp[MAXK][2];

bool solve(int r, int t)
{
    if (vis[r][t])
        return dp[r][t];
    vis[r][t] = 1;
    
    bool winner;
    if (t)
    {
        winner = 0;
        for (int i = 0; i < n; i++)
        {
            if (r - vals[i] >= 0)
                winner |= solve(r - vals[i], !t);
        }
    }
    else
    {
        winner = 1;
        for (int i = 0; i < n; i++)
        {
            if (r - vals[i] >= 0)
                winner &= solve(r - vals[i], !t);
        }
    }

    return dp[r][t] = winner;
}

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

    if (solve(k, 0))
        printf("Second\n");
    else
        printf("First\n");
}

Measured memory_bytes: 7424
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

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

    int p,q,r;
    p = q = r = -1;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n-i ; ++j) {
            int k = n-i-j;
                if(10000*i+5000*j+1000*k == y) {
                    p = i; q = j; r = k;
            }
        }
    }

    cout << p << " " << q << " " << r << endl;

    return 0;
}


Measured memory_bytes: 256
import sys

input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)

n=int(input())
edge=[[] for i in range(n)]
for i in range(n-1):
    v,w=map(int,input().split())
    edge[v-1].append(w-1)
    edge[w-1].append(v-1)

if n==2:
    exit(print(1,2))

leafcnt=[0]*n
for v in range(n):
    for nv in edge[v]:
        if len(edge[nv])==1:
            leafcnt[v]+=1

used=[False]*n
line=[]
def line_check(v):
    used[v]=True
    line.append(leafcnt[v])
    flag=False
    for nv in edge[v]:
        if not used[nv] and len(edge[nv])!=1:
            if not flag:
                line_check(nv)
                flag=True
            else:
                return False
    return True

for v in range(n):
    if not used[v] and len(edge[v])-leafcnt[v]<=1 and len(edge[v])!=1:
        if not line:
            check=line_check(v)
            if not check:
                exit(print(-1))
        else:
            exit(print(-1))


line_rev=line[::-1]
res=min(line,line_rev)
res=[0]+res+[0]
res[1]-=1
res[-2]-=1

ans=[]
L=1
for val in res:
    R=L+val
    for i in range(L+1,R+1):
        ans.append(i)
    ans.append(L)
    L=R+1

print(*ans)


Measured memory_bytes: 201864
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

ll euclidean_gcd(ll a, ll b) {
    if(a < b) euclidean_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

int M[201][201] = {0};

int main() {
    int K;
    cin >> K;
    for (int i = 1; i <= 200; i++) {
        for (int j = 1; j <= 200; j++) {
            M[i][j] = euclidean_gcd(i, j);
        }
    }
    
    ll sum = 0;
    for (int a = 1; a <= K; a++) {
        for (int b = 1; b <= K; b++) {
            for (int c = 1; c <= K; c++) {
                int pgcd = M[a][b];
                int result = M[pgcd][c];
                sum += result; 
            }
        }
    }
    cout << sum << endl;
}


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

using namespace std;

int gcd(int x, int y){
    if( x < y )
        swap(x,y);
    while( y > 0){
        int r = x%y;
        x = y;
        y = r;
    }

    return x;
}

int main()
{
    int x, y;
    cin >> x >> y;
    int d = gcd(x,y);

    cout << d << endl;

    return 0;

}


Measured memory_bytes: 3116
#include<stdio.h>
int data[31][100]={0};
void find(int t)
{
	int i,j,s=1,f;
	for(i=30;i>=0;i--)
	{
		f=0;
		for(j=0;data[i][j]!=0;j++)
		{
			f=1;
			if(data[i][j]==t)
			{
				printf("%d\n",s);
				return;
			}
		}
		if(f)
			s++;
	}
}
int main()
{
	int i,n,s;
	while(1)
	{
		scanf("%d,%d",&n,&s);
		if(n==0&&s==0)
			break;
		for(i=0;data[s][i]!=0;i++);
		data[s][i]=n;
	}
	while(scanf("%d",&n)!=EOF)
		find(n);
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define Rep(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int
const int MAX = 510000;


using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

//UnionFind(重みなし, sizeあり）
//UnionFind
class UnionFind {
    vector<int>par, sz;
public:
    UnionFind() {}
    UnionFind(int n) {
        par = sz = vector<int>(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            sz[i] = 1;
        }
    }
    int find(int x) {
        if (par[x] == x)return x;
        return par[x] = find(par[x]);
    }
    void merge(int x, int y) {
        x = find(x); y = find(y);
        if (x == y)return;
        if (sz[x] > sz[y]) {
            par[y] = x;
            sz[x] += sz[y];
        }
        else {
            par[x] = y;
            sz[y] += sz[x];
        }
    }
    bool issame(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return sz[find(x)];
    }
};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k, l;
    cin >> n >> k >> l;
    UnionFind uf_1(n), uf_2(n);
    rep(i, k){
        int p, q;
        cin >> p >> q;
        uf_1.merge(p - 1, q - 1);
    }
    rep(i, l){
        int r, s;
        cin >> r >> s;
        uf_2.merge(r - 1, s - 1);
    }
    map<P, int> M;
    rep(i, n){
        M[P(uf_1.find(i), uf_2.find(i))]++;
    }
    rep(i, n)cout << M[P(uf_1.find(i), uf_2.find(i))] << " ";
    cout << endl;

}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define M 1000000007
#define N 100010
inline int read(){
	char ch=getchar(); int x=0;
	for (;ch>'9'||ch<'0';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}
int n,inv[N],S[N],fac[N],ans;
int pw(int a,int b){int res=1; for (;b;b>>=1,(a*=a)%=M) if (b&1) (res*=a)%=M; return res;}
signed main(){
	n=read();
	inv[1]=1; for (int i=2;i<=n;i++) inv[i]=1LL*inv[M%i]*(M-M/i)%M;
	for (int i=1;i<=n;i++) S[i]=(S[i-1]+inv[i])%M;
	fac[0]=1; for (int i=1;i<=n;i++) fac[i]=fac[i-1]*i%M;
	for (int i=1;i<=n;i++){
		int x=read();
		(ans+=x*(S[i]+S[n-i+1]-1)%M)%=M;
	}
	(ans*=fac[n])%=M;
	printf("%lld\n",ans);
	return 0;	
}


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

// #include <atcoder/all>

// #LIB#

using namespace std;
// using namespace atcoder;
using ll = long long;
#define double long double
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x, c) for (auto&& x : (c))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))
#ifdef ONLINE_JUDGE
#define endl _endl
const char _endl = (cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout.precision(16), '\n');
#endif

const string Yes = "Yes";
const string No = "No";
int main() {
  ll n;
  cin >> n;
  vector<vector<ll>> d(n, vector<ll>(2));
  rep(i, n) rep(j, 2) cin >> d[i][j];
  bool ans = false;
  repr(i,2,n){
    if(d[i-2][0]==d[i-2][1]&&d[i-1][0]==d[i-1][1]&&d[i][0]==d[i][1]){
      ans = true;
    }
  }
  cout << (ans ? Yes : No) << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
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 string dir = "DRUL";
*/
int H,W,N;
string S,T;
bool solve(int t, int mx, int sx){
    //Nターン後は、
    //[0, N-1]の区間に入っていられるかどうか
    char plus = 'D';
    char minu = 'U';
    if(t == 1){
        plus = 'R';
        minu = 'L';
    }
    // [l, r)の区間
    int l = 0, r = mx;
    //cerr<<endl;
    for(int i = N-1;i >= 0;i--){
        //cerr << "start: " <<l << " " << r <<endl;
        if(l == r)return false;
        if(T[i] == minu){
            r++;
            chmin(r, mx);
        }
        else if(T[i] == plus){
            l--;
            chmax(l, 0);
        }
        //cerr << l << " " << r << endl;
        if(S[i] == plus){
            r--;
        }
        else if(S[i] == minu){
            l++;
        }
        //cerr << l << " " << r << endl;
    }
    //cerr << "finished" << endl;
    //cerr << sx << endl;
    if(sx < l || r <= sx){
        return false;
    }
    return true;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int sx, sy;
    cin >> H >> W >> N;
    cin >> sx >> sy;
    sx--;sy--;
    cin >> S >> T;
    bool ok = true;
    if(!solve(0, H, sx)){
        ok = false;
    } 
    if(!solve(1, W, sy)){
        ok = false;
    }
    cout << (ok ? YES :NO) << endl;
}

Measured memory_bytes: 920
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	string x;
	map<string,int>::iterator mit;
	map<string,int> s;
	int i;
	for (i=0;i<N;i++){
		cin>>x;
		mit=s.find(x);
		if (mit==s.end()){
			s[x]=1;
		}else{
			(*mit).second++;
		}
	}
	int M;
	cin>>M;
	map<string,int> t;
	for (i=0;i<M;i++){
		cin>>x;
		mit=t.find(x);
		if (mit==t.end()){
			t[x]=1;
		}else{
			(*mit).second++;
		}
	}
	map<string,int>::iterator mitS;
	for (mit=t.begin();mit!=t.end();mit++){
		for (mitS=s.begin();mitS!=s.end();mitS++){
			if (!(*mit).first.compare((*mitS).first)){
				(*mitS).second-=(*mit).second;
				break;
			}
		}
	}
	int Max=0;
	for (mitS=s.begin();mitS!=s.end();mitS++){
		if (Max<(*mitS).second){
			Max=(*mitS).second;
		}
	}
	cout<<Max<<endl;
	return 0;
}

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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;

const int mod = 998244353;
const ll inf = 3e18 + 5;

int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

int main(){
    int a, b;
    cin >> a >> b;
    int s = b * 10;
    int sol1, sol2;
    sol1 = (s * 8) / 100;
    sol2 = s / 10;
    while(sol1 <= a && sol2 <= b){
        sol1 = (s * 8) / 100;
        sol2 = s / 10;
        if(sol1 > 100 || sol2 > 100)
            break;
        if(sol1 == a && sol2 == b)
            break;
        s++;
    }
    if(sol1 == a && sol2 == b)
        cout << s;
    else
        cout << -1;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
 
int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
long long merge_sort(int *first, int *last) {
    const int N = (int)(last - first);
    if(N < 2) return 0;
    int *mid = first + N / 2;
    const int N1 = (int)(mid - first);
    const int N2 = (int)(last - mid);
    int *left = malloc(sizeof(int) * (N1 + 1));
    int *right = malloc(sizeof(int) * (N2 + 1));
    memcpy(left, first, sizeof(int) * (N1 + 1));
    memcpy(right, mid, sizeof(int) * (N2 + 1));
    left[N1] = right[N2] = 1 << 30;
 
    long long cnt = 0;
    cnt += merge_sort(left, left + N1);
    cnt += merge_sort(right, right + N2);
 
    for(int *it = first, i = 0, j = 0; it != last; ++it) {
        if(left[i] <= right[j]) *it = left[i++];
        else *it = right[j++], cnt += N / 2 - i;
    }
    return cnt;
}
int main(int argc, char **argv) {
    int n = get_uint();
    int a[200001];
    for(int i = 0; i < n; ++i) a[i] = get_uint();
    printf("%lld\n", merge_sort(a, a + n));
    return 0;
}



Measured memory_bytes: 26012
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }

int main() {
    ios::sync_with_stdio(0);
    int n, q;
    cin >> n >> q;
    //cout << n << " " << q << endl;
    using P = pair<int, ll>;
    set<P> s;
    s.insert(P(-1, 3*TEN(13)));
    s.insert(P(n-1, 0));

    for (int i = 0; i < q; i++) {
        int a; ll b;
        cin >> a >> b; a--;
        while (b) {
            auto it = s.lower_bound(P(a, -1));
            auto pr = *it; it--;
            auto pl = *it;
            int d = a-pl.first;
            if (a == pr.first) s.erase(pr);
            if (d*(pl.second-pr.second) <= b) {
                s.erase(pl); 
                s.insert(P(a, pl.second));
                b -= d*(pl.second-pr.second);
            } else {                
                s.insert(P(a, pr.second + b/d));
                if (b%d) {
                    s.insert(P(pl.first + b%d, pr.second + b/d + 1));
                }
                if (pr.second + (b+d-1)/d == pl.second) {
                    s.erase(pl);
                }
                b = 0;
            }
        }
    }

    ll res[n];
    int b = -1;
    for (auto p: s) {
        for (int i = b+1; i <= p.first; i++) {
            res[i] = p.second;
        }
        b = p.first;
    }

    for (int i = 0; i < n; i++) {
        cout << res[i] << endl;
    }
    return 0;
}



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

int main()
{
	int n, m;
	cin >> n >> m;
	int A[n][m];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> A[i][j];
	int b[m];
	for (int i = 0; i < m; i++)
		cin >> b[i];
	int c[n] {0};
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			c[i] += A[i][j] * b[j];
		}
		cout << c[i] << endl;
	}
}



Measured memory_bytes: 3092
#include<iostream>
using namespace std;
typedef long long LL;
LL f(LL b, LL n)
{
	if(n<b) return n;
	else return f(b,n/b)+(n%b);
}
LL solve()
{
	LL n, s; cin >> n >> s;
	
	LL b;
	for(b = 2; b*b <= n; b++)
		if(f(b,n)==s)
			return b;
	
	//else, b = first value such that b*b > n
	// b > n/b > floor(n/b), therefore b > q
	
	for(LL q = b; q > 0; q--)
		if((n-(s-q))/q > 1 && f((n-(s-q))/q,n)==s)
			return (n-(s-q))/q;
	
	if(n==s) return n+1;
	return -1;
}
int main()
{
	cout<<solve()<<endl;
	return 0;
}

Measured memory_bytes: 3604
import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val Array(n, k) = input.nextLine().split(" ").map(_.toInt)
      val ns          = input.nextLine().split(" ").map(_.toInt)

      val minIndex = ns.indexOf(1)

      val leftCount  = minIndex
      val rightCount = n - minIndex - 1

      val u = k - 1
      val r = leftCount % u + rightCount % u
      val result =
        (leftCount / u) +
          (rightCount / u) +
          (if (r % u == 0) r / u else r / u + 1)

      output.println(result)
    }
  }

}


Measured memory_bytes: 45668
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstdio>
using namespace std;

#define int long long
#define INF 1e18

signed main() {
    int n; cin >> n;
    bool flag = false;
    for(int i = 0; i < n; i++) {
        string s; cin >> s;
        if(s == "Y") flag = true;
    }

    cout << (flag ? "Four" : "Three") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main(){
    char inp;
    cin >> inp;

    bool success = false;
    char judge[] = {'a', 'i', 'u', 'e', 'o'};
    rep(i, 5) if(inp == judge[i]) success = true;

    if(success) cout << "vowel" << endl;
    else cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<algorithm>
using namespace std;
string s;
bool input(){
  if(getline(cin,s)){
    if(s==".")return false;
    return true;
  }
  return false;
}
bool solve(){
  stack<char> st;
  for(int i=0;i<s.size();i++){
    if(s[i]=='('||s[i]=='['){
      st.push(s[i]);
    }else if(s[i]==')'||s[i]==']'){
      if(st.empty())return false;
      char tmp = st.top();st.pop();
      if(s[i]==')'){
        if(tmp != '(')return false;
      }else{
        if(tmp != '[')return false;
      }
    }
  }
  if(st.empty()){
    return true;
  }else{
    return false;
  }
}

int main(){
  while(input()){
    if(solve()){
      cout<<"yes"<<endl;
    }else{
      cout<<"no"<<endl;
    }
  }
}

Measured memory_bytes: 1176
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
typedef long long ll;

int main() {
  int n, y;
  cin >> n >> y;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j+i <= n; j++) {
      int k = n-(i+j);
      if (10000*i + 5000*j + 1000*k == y) {
        cout << i << ' ' << j << ' ' << k << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;
  return 0;
}

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


int main()
{
    int N, C;
    cin >> N >> C;
    vector<int> s(N), t(N), c(N);
    for( int i = 0; i < N; ++i ) cin >> s[i] >> t[i] >> c[i];
    
    const int T = 2e+5+2;
    vector<int> numChannels(T);

    for(int i = 1; i <= C; i++ ){
        vector<int> temp(T);
        for( int j = 0; j < N; j++ ){
            if( c[j] == i ){
                temp[s[j]*2-1]++;
                temp[t[j]*2]--;
            }
        }
        for( int j = 1; j < T; j++ ){
            temp[j] += temp[j-1];
        }
        for( int j = 0; j < T; j++ ){
            if( temp[j] > 0 ) numChannels[j]++;
        }
    }
    
    int ans = 0;
    for( int i = 0; i < T; i++ ) ans = max( ans, numChannels[i] );
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 3072
using System;
using System.Linq;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	long g, L;
	public K()
	{
		var I = ReadLine().Split().Select(long.Parse).ToArray();
		var N = I[0];
		L = I[1];
		var root = new object[2];
		for (var i = 0; i < N; i++)
		{
			var s = ReadLine();
			var n = root;
			for (var j = 0; j < s.Length; j++)
			{
				var x = s[j] - '0';
				n = (object[])(n[x] = n[x] ?? new object[2]);
			}
		}
		DFS(root, 0);
		WriteLine(g != 0 ? "Alice" : "Bob");
	}
	int C(object o)
	{
		return o == null ? 0 : 1;
	}
	void DFS(object[] n, int d)
	{
		if (C(n[0]) + C(n[1]) == 1) g ^= F(L - d);
		foreach (var c in n) if (c != null) DFS((object[])c, d + 1);
	}
	long F(long n)
	{
		var c = 1L;
		while (n % 2 == 0) { c <<= 1; n >>= 1; }
		return c;
	}
}

Measured memory_bytes: 31068
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	cin >> n;
	int ans = 1;
	while (ans * 2 <= n)ans *= 2;
	cout << ans << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	s := make([]string, h)
	for i := range s {
		fmt.Scan(&s[i])
	}

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if s[i][j] == '.' {
				continue
			}
			bad := true
			if i > 0 && s[i-1][j] == '#' {
				bad = false
			}
			if i < h-1 && s[i+1][j] == '#' {
				bad = false
			}
			if j > 0 && s[i][j-1] == '#' {
				bad = false
			}
			if j < w-1 && s[i][j+1] == '#' {
				bad = false
			}
			if bad {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}


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

int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;

  cout << Z << " " << X << " " << Y << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define inf1 1e18+1
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(a>b)swap(a,b);if(!a)return b;return gcd(b%a,a);}

void solve(){
	ll n;
	cin>>n;
	ll a[n];
	rep(i,n)cin>>a[i];
	ll b[n-1];
	ll an1=0;
	for(int i=0;i<n-1;i+=2){b[i]=a[i]-a[i+1];an1+=b[i];}
	ll c[n];
	c[0]=(a[n-1]+an1)/2;
	for(int i=1;i<n;i++)c[i]=a[i-1]-c[i-1];
	rep(i,n)cout<<2ll*c[i]<<" ";
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3712
# coding: utf-8

import math

# input
a, b = input().split()
ab = int("{}{}".format(a, b))

def check(ab):
    sqrt = math.floor(math.sqrt(ab))
    if ab == sqrt ** 2:
        return "Yes"
    else:
        return "No"

# output
print(check(ab))


Measured memory_bytes: 2940