akhauriyash/Code-Regression huggingface dataset:
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}

//dp[i] - TRUE if the first player wins if there are i stones remaining


int main(){
    int n = nxt(), k = nxt();
    VI a(n);
    generate(all(a), nxt);
    vector<bool> dp(k + 1);
    for (int stones = 0; stones <= k; stones++){
        for(int x : a){
            if(stones >= x && !dp[stones-x]){
                dp[stones] = true;
            }
        }
    }
        puts(dp[k] ? "First" : "Second");
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<string> s(n);
	vector<int> march(5, 0);
	string tmp = "MARCH";
	rep(i, n) {
		cin >> s[i];
		rep(j, 5) {
			if (s[i].at(0) == tmp.at(j)) {
				march[j]++;
			}
		}
	}
	int ans = 0;
	for (int i = 0; i <= 2; i++) {
		for (int j = 1; i + j <= 3; j++) {
			for (int k = 1; i + j + k <= 4; k++) {
				ans += march[i] * march[i + j] * march[i + j + k];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;
#define MAXN 100000
#define ll long long
#define rint register int
#define gc() getchar()
inline int read(int r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}
ll N, K, Ans; inline ll Calc(ll k)//{ll Ans = 0; for(ll b = k+1; b <= N; Ans += (N-k)/b+!!k, b++); return Ans;}
{ll Ans = 0; for(ll d = k+1, p; d <= N-k; p = (N-k)/((N-k)/d), Ans += (N-k)/d*(p-d+1), d = p+1); Ans += (N-k)*!!k; return Ans;}
int main()
{
	N = read(), K = read(); if(N < K) return puts("0"),0;
	for(ll k = K; k <= N-1; Ans += Calc(k), k++); cout << Ans <<endl; return 0;
}

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

int main() {
  int N, L;
  cin >> N >> L; //L:文字列の長さ
  
  vector<string> vec(N);
  for(int i=0; i<N; i++){
    string S;
    cin >> S;
    vec[i] = S;
  }
  
  sort(vec.begin(), vec.end() );
  
  string S_min  = vec[0];
  for(int i=1; i<N; i++){
    S_min += vec[i];
  }
  
  cout << S_min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;

int main()
{
    int a;
    cin >> a;
    if (a / 100 == a % 10)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
	int n,t,a,h,i,m=1;
	scanf("%d%d%d",&n,&t,&a);
	float b,c=500*(t-a)/3;
	for(i=1;i<=n;i++){
		scanf("%d",&h);
		if(i==1){b=h;}
		else if(abs(h-c)<abs(b-c)){b=h;m=i;}
	}
	printf("%d",m);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
 
class Main {
 
  
 
  public static void main(String[] args) {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    
    int n = in.nextInt();
    long[] a = new long[n];
    for (int i = 0; i < n; i++) {
      a[i] = in.nextInt();
    }

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

    long[][] dp = new long[n][n];
    for (int i = 0; i < n; i++) {
      Arrays.fill(dp[i], Long.MAX_VALUE);
      dp[i][i] = 0;
    }

    
    for (int len = 2; len <= n; len++) {
      for (int i = 0; i < n; i++) {
        int j = len + i - 1;
        if (j >= n) {break;}
        for (int k = i; k < j; k++) {
          dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[k + 1][j] + a[j] - (i == 0 ? 0 : a[i - 1]));
        }
      }
    }

    System.out.println(dp[0][n - 1]);
  }
 
}

Measured memory_bytes: 24532
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a,b,c;
  vector<int> dp(3);
  cin >> a >> b >> c;
  dp[0] = a;
  dp[1] = b;
  dp[2] = c;
  for(int i = 1; i<n;i++){
    cin >> a >> b >> c;
    a+= max(dp[1], dp[2]);
    b+= max(dp[0], dp[2]);
    c+= max(dp[0], dp[1]);
    dp[0] = a; dp[1] = b; dp[2] = c; 
  }
  cout <<max({dp[0],dp[1],dp[2]})<<endl;
  return 0;

    

}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string a, b;
	cin >> a >> b;
	for (int i = 0; i < a.size(); i++) {
		if (a.size() > b.size() && i == a.size() - 1)cout << a[i];
		else cout << a[i] << b[i];
	}
	cout << endl;
	int x;
	cin >> x;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int a,b,x,y,r;
    bool in;
    in=1;
    cin >> a >> b >>x>>y>>r;
    if ((y+r)>b){
        in=0;
    }
    if ((y-r)<0){
        in=0;
    }
    if ((x+r)>a){
        in=0;
    }
    if ((x-r)<0){
        in=0;
    } 
    if (in) {
        cout << "Yes" <<endl;
    }else {
        cout << "No" << endl;
    }
    return 0;
}


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

int main()
{
  int N;
  while(cin >> N, N) {
    vector< string > s(N);
    
    bool flag = true;
    for(int i = 0; i < N; i++) cin >> s[i];
    bool graph[26][26] = {{}};
    for(int i = 1; i < N; i++) {
      bool update = false;
      for(int j = 0; j < min(s[i - 1].size(), s[i].size()); j++) {
        if(s[i - 1][j] != s[i][j]) {
          graph[s[i - 1][j] - 'a'][s[i][j] - 'a'] = true;
          update = true;
          break;
        }
      }
      flag &= update | (s[i - 1].size() <= s[i].size());
    }
    for(int k = 0; k < 26; k++) {
      for(int i = 0; i < 26; i++) {
        for(int j = 0; j < 26; j++) {
          graph[i][j] |= graph[i][k] & graph[k][j];
        }
        flag &= !graph[i][i];
      }
    }
    if(flag) cout << "yes" << endl;
    else cout << "no" << endl;
  }
}

Measured memory_bytes: 1244
#include<iostream>
#include<vector>
#include<cstring>
#include<iomanip>
using namespace std;
typedef long long ll;
#define ip(arr, n) for(int i=0; i<n; i++) cin>>arr[i];
#define op(arr, n) for(int i=0; i<n; i++) cout<<arr[i]<<" ";
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MAX 305

double dp[MAX][MAX][MAX];
int n,one,two,three;

/*
Logic:
First : what really matters is the number of dishes with 0, 1, 2 and 3 sushis and not the order of the dishes.
So answer for 2,1,0,2,1 is same as answer for 0,1,1,2,2.

Number of dishes with 0 sushis is easily determined by N - one - two - three, where one is the number of dishes with 1 sushi and N is the total number of dishes in the input.

Let F(x, y, z) be the expected moves needed for x dishes with 1 sushi, y with 2 and z with 3.

Now in the next move we can pick a dish with 1 sushi with a probability of x/N or p1. we can pick a dish with 2 sushi with a probability of y/N or p2. we can pick a dish with 3 sushi with a probability of z/N or p3. we can pick a dish with 0 sushi with a probability of (N - (x + y + z))/N or p0.

Now try to understand this :
F(x,y,z) = 1 + p0F(x,y,z) + p1F(x-1,y,z) + p2F(x+1,y-1,z) + p3F(x,y+1,z-1)

Here we add a 1 for the current move that we are making.
(Note : if you pick a dish with 3 sushi z decreases but y increases)

p1 -> one/(one+two+three)
p2 -> two/(one+two+three)
p3 -> three/(one+two+three)

p0 -> n-(one+two+three)/(one+two+three)

as we see all val have denominator (one+two+three), except 1(plus one)

F = ((one+two+three) + (n-(one+two+three)) + one*F + two*F + three*F)/(one+two+three)

F = (n + one*F + two*F + three*F)/(one+two+three)
*/

double solve(int one, int two, int three){
    if(one+two+three == 0 || one<0 || two<0 || three<0) return 0.0;

    if(dp[one][two][three] > -1) return dp[one][two][three];

    ll sum = one+two+three;
    double ans = n + (one*solve(one-1, two, three)) + (two*solve(one+1, two-1, three)) + (three*solve(one, two+1, three-1));

    return dp[one][two][three] = (double)ans/sum;
}

void topDown(){
    memset(dp, -1, sizeof(dp));
    cout<<fixed<<setprecision(14)<<solve(one, two, three)<<endl;
}

// void bottomUp(){
//     memset(dp, 0, sizeof(dp));

//     for(int k=0; k<=n; k++){
//         for(int j=0; j<=n; j++){
//             for(int i=0; i<=n; i++){
//                 int l = i + j + k;
//                 if(l>n) continue;
//                 dp[i][j][k] = (l==0) ? 0 : 1.0 * n / l;
//                 if(i>0) dp[i][j][k] += dp[i-1][j][k] * i / l;
//                 if(j>0) dp[i][j][k] += dp[i+1][j-1][k] * j / l;
//                 if(k>0) dp[i][j][k] += dp[i][j+1][k-1] * k / l;
//                 // cout << i << " " << j << " " << k << " "  << dp[i][j][k] << endl;
//             }
//         }
//     }
//     cout<<fixed<<setprecision(15)<<dp[one][two][three]<<endl;
// }

int main(){
    cin>>n;
    for(int i=0; i<n; i++){
        int x;
        cin>>x;
        if(x==1)one++;
        else if(x==2)two++;
        else three++;
    }
    topDown();
    return 0;
}

Measured memory_bytes: 221952
import sys
input = sys.stdin.buffer.readline

n = int(input())
a = list(map(int,input().split()))

#kane ha
b = 1000

#kabu ha
p = 0
q = 0

for e in a:
    b = max(b,p + q*e)

    q += p//e
    p = p%e

    p2 = b%e
    q2 = b//e

    if q2 > q:
        q = q2
        p = p2
    elif q2 == q:
        p = max(p,p2)

print(b)

Measured memory_bytes: 61784
#include<iostream>
#include<string>
using namespace std;
struct Edge {
	int next,to,dis;
} edge[500005];
int num_edge,n,m,u,v,d,s,t,mi;
int dis[10005],head[500005];
bool vis[100001];
void add_edge(int from,int to,int dis)
{
	edge[++num_edge].next=head[from];
	edge[num_edge].to=to;
	edge[num_edge].dis=dis;
	head[from]=num_edge;
}
void dij()
{
	for(int i=1; i<=n; i++)
		dis[i]=0x7fffffff;
	dis[s]=0;
	for(int i=1; i<=n; i++) {
		mi=0x3f3f3f3f,t=-1;
		for(int j=1; j<=n; j++) {
			if(!vis[j] && dis[j]<mi) {
				mi=dis[j];
				t=j;
			}
		}
		if(t==-1) break;
		vis[t]=1;
		for(int j=head[t]; j; j=edge[j].next) {
			if(!vis[edge[j].to]&&dis[edge[j].to]>(edge[j].dis+dis[t]))
				dis[edge[j].to]=edge[j].dis+dis[t];
		}
	}
}
char striii[10001];
int main()
{
    cin>>striii;
    if(striii[0]=='Y'&&striii[1]=='A'&&striii[2]=='K'&&striii[3]=='I')
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

Measured memory_bytes: 256
H = int(input())
W = int(input())
N = int(input())
k=0
if H<=W:
    for i in range(H):
        ans=0
        ans=(i+1)*W
        k=k+1
        if ans>=N:
            break
else:
    for i in range(W):
        ans=0
        ans=(i+1)*H
        k=k+1
        if ans>=N:
            break

print(k)

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = long long;
using vint = vector<int>;

string getStr(string& s, int a, int b) {
    return s.substr(a, b - a);
}

void Main() {
    string s;
    cin >> s;

    vector<string> chunk_list;
    vint ans(s.length(), 0);

    int r_count = 0;
    int l_count = 0;
    int cur_char_count = 0;

    rep(i, s.length()) {
        if (s[i] == 'R') {
            ++r_count;
        }

        if (i == s.length() - 1) {
            string cur_chunk = getStr(s, cur_char_count, s.length());
            if (cur_chunk.length() % 2 == 0) {
                ans[cur_char_count + r_count - 1] = cur_chunk.length() / 2;
                ans[cur_char_count + r_count] = cur_chunk.length() / 2;
            }
            else {
                if (r_count % 2 == 0) {
                    ans[cur_char_count + r_count - 1] = cur_chunk.length() / 2;
                    ans[cur_char_count + r_count] = cur_chunk.length() / 2 + 1;
                }
                else {
                    ans[cur_char_count + r_count - 1] = cur_chunk.length() / 2 + 1;
                    ans[cur_char_count + r_count] = cur_chunk.length() / 2;
                }
            }
            l_count = 0;
            r_count = 0;
            cur_char_count = i + 1;
            break;
        }
        else if (s[i] == 'L' && s[i + 1] == 'R') {
            string cur_chunk = getStr(s, cur_char_count, i + 1);
            if (cur_chunk.length() % 2 == 0) {
                ans[cur_char_count + r_count - 1] = cur_chunk.length() / 2;
                ans[cur_char_count + r_count] = cur_chunk.length() / 2;
            }
            else {
                if (r_count % 2 == 0) {
                    ans[cur_char_count + r_count - 1] = cur_chunk.length() / 2;
                    ans[cur_char_count + r_count] = cur_chunk.length() / 2 + 1;
                }
                else {
                    ans[cur_char_count + r_count - 1] = cur_chunk.length() / 2 + 1;
                    ans[cur_char_count + r_count] = cur_chunk.length() / 2;
                }
            }
            l_count = 0;
            r_count = 0;
            cur_char_count = i + 1;
        }
    }

    for (const auto& x : ans)
    {
        cout << x << ' ';
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

using namespace std;

#define int long long

int a[52];
int d[52][2];
int n;
int p;

signed main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> p;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	d[0][0] = 1;
	d[0][1] = 0;

	for (int i = 1; i <= n; i++)
	{
		if (a[i] % 2 == 0)
		{
			d[i][0] = d[i - 1][0] * 2;
			d[i][1] = d[i - 1][1] * 2;
		}
		else
		{
			d[i][0] = d[i][1] = d[i - 1][1] + d[i - 1][0];
		}
	}

	cout << d[n][p];
}

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

using namespace std;
int n, m;
char op[1005][1005];
bool vis[1005][1005];
int dp[1005][1005];
const int X[] = {-1, 0, 1, 0}, Y[] = {0, 1, 0, -1};

struct Node {
    int x, y;

    Node(int a, int b) : x(a), y(b) {}
};

queue<Node> que;

int main() {
    ios::sync_with_stdio(false), memset(dp, 127, sizeof(dp));
    cin >> n >> m;
    for (int i = 1; i <= n; i++)cin >> (op[i] + 1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (op[i][j] == '#') {
                for (int p = 0; p < 4; p++) {
                    int xx = i + X[p], yy = j + Y[p];
                    if (op[xx][yy] == '.' && !vis[xx][yy])vis[xx][yy] = true, dp[xx][yy] = 1, que.push(Node(xx, yy));
                }
            }
        }
    }
    while (!que.empty()) {
        Node s = que.front();
        que.pop(), vis[s.x][s.y] = false;
        for (int i = 0; i < 4; i++) {
            int xx = s.x + X[i], yy = s.y + Y[i];
            if (xx < 1 || xx > n || yy < 1 || yy > m)continue;
            if (op[xx][yy] == '.' && dp[xx][yy] > dp[s.x][s.y] + 1) {
                dp[xx][yy] = dp[s.x][s.y] + 1;
                if (!vis[xx][yy])que.push(Node(xx, yy)), vis[xx][yy] = true;
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (op[i][j] == '.')ans = max(ans, dp[i][j]);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 10368
N,K = [int(x.strip()) for x in input().split()]

L = [True] * N
for i in range(K):
    d = input()
    l = [int(a.strip()) for a in input().split()]
    for a in l:
        L[a-1] = False

ans = sum(v==True for v in L)
print(ans)

Measured memory_bytes: 8980
var input = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    input += chunk;
});
process.stdin.on('end', function() {
    var lines = input.split('\n').map(Number);
    for (var i = 0; i < lines.length && lines[i] != 0; i++) {
        console.log('Case %d: %d', i + 1, lines[i]);
    }
});

Measured memory_bytes: 13300
#include <iostream>
#include <algorithm>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <limits.h>
#include <bitset>
#include <cmath>

using namespace std;

#define rip(i, n, s) for (int i = (s);i < ( int )( n ); i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;

int main(){
    int h,w,a,b;
    cin >> h >> w >> a >> b;
    vector<vector<bool>> da(h,vector<bool>(w,false));
    rip(i,h,0){
        rip(j,w,0){
            da[i][j]=(j<a)^(i<b);
        }
    }
    rip(i,h,0){
        rip(j,w,0){
            if(da[i][j]){
                printf("1");
            }
            else{
                printf("0");
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,m,a[2000];
vector<int> t;
int main(){
  a[0]=0;
  while(cin>>n>>m&&n&&m){
    t.clear();
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=0;i<n;i++){
      for(int j=i;j<=n;j++){
	t.push_back(-(a[i]+a[j]));
      }
    }
    sort(t.begin(),t.end());
    int ans=0;
    for(int i=0;i<(int)t.size();i++){
      int x=-t[i];
      int y=m-x;
      if(y<0)continue;
      vector<int> :: iterator it;
      it = lower_bound(t.begin(),t.end(),-y);
      if(it==t.end())continue;
      int z = *it;
      ans=max(ans,x-z);
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++)

const char nl = '\n';
const int MOD = 1e9 +7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 + 5;


bool comp(pair<string, pair<int, int> > a, pair<string, pair<int, int> > b){
  if(a.fi == b.fi) return a.se.fi > b.se.fi;
    return a.fi < b.fi;
}
int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);

  int n, x; cin >> n >> x;
  int cnt  = 1;
  int d = 0;
  for(int i = 0; i < n; i++){
    int l; cin >> l;
    d+=l;
    if(d <=x)
      cnt++;

  }
  cout << cnt << nl;
return 0;




}


Measured memory_bytes: 3620
r, c = gets.split.map(&:to_i)
arrs = []
sum_arr = Array.new(c, 0)
ARGF.each_line do |line|
  arrs << line.split.map(&:to_i)
end

arrs.each do |arr|
  print arr.join("\s")
  print "\s"
  puts  arr.inject(:+)
  c.times do |i|
    sum_arr[i] += arr[i]
  end
end

print sum_arr.join("\s")
print "\s"
puts  sum_arr.inject(:+)

Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, h, r;
  cin >> N >> K; 

  r = 0;
  for (int i = 0; i < N; i++) {
    cin >> h;
    if (h >= K)
      r++;
  }  
  cout << r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(int i=x;i<(y);++i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const int inf = 1e15;

signed main(){
	IOS;
	int n,ans = inf; cin >> n;
	vector<int> a(n);
	for(auto &it : a) cin >> it;
	int res = 0;
	for(int i = 0, tmp=0;i<n;i++){
		tmp+=a[i];
		if(i&1){
			if(tmp>=0){
				res+=tmp+1;
				tmp=-1;
			}
		}
		else{
			if(tmp<=0){
				res+=-tmp+1;
				tmp=1;
			}
		}
	}
	ans = min(ans,res);
	res=0;
	for(int i = 0,tmp=0;i<n;i++){
		tmp+=a[i];
		if(i&1){
			if(tmp<=0){
				res+=-tmp+1;
				tmp=1;
			}
		}
		else{
			if(tmp>=0){
				res+=tmp+1;
				tmp=-1;
			}
		}
	}
	cout << min(ans,res) << '\n';
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm> 
#include<cstring>
#define ios ios::sync_with_stdio(false)
#define mem(arr) memset(arr,0,sizeof(arr))
using namespace std;
typedef long long ll;
const ll maxn = 1e6 + 10;
int main()
{
	ll a,b,c,d;
	ll sum;
	cin>>a>>b>>c>>d;
	sum = max(b * c,b * d);
	sum = max(sum,a * c);
	sum = max(sum,a * d);
	cout<<sum<<endl;
	return 0;
} 

Measured memory_bytes: 3588
n=int(input())
a=list(map(int,input().split()))
d={}
for b in a:
  if b not in d:
    d[b]=0
  d[b]+=1

ans=0
for c in d:
  ans+=(d[c]*(d[c]-1))//2
  
for k in range(n):
  e=a[k]
  print(ans-(d[e]*(d[e]-1))//2+(d[e]-1)*(d[e]-2)//2)

Measured memory_bytes: 32220
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var S = cin.Read.Reverse();
            var words = new string[] { "maerd", "remaerd", "esare", "resare" };
            var flag = true;
            for (int i = 0; i < S.Length;)
            {
                var flag2 = false;
                foreach (var x in words)
                    if (S.Length - i < x.Length) continue;
                    else if (S.Substring(i, x.Length) == x) { flag2 = true; i += x.Length; }
                if (!flag2) { flag = false; break; }
            }
            if (flag) WriteLine("YES");
            else WriteLine("NO");
            
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }
}




Measured memory_bytes: 13224
def divisors(N):
    U = int(N ** 0.5)
    L = [i for i in range(1, U) if N % i == 0]
    C = [U] if N % U == 0 else []
    R = [N // r for r in reversed(L)]
    return L + C + R

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))


Measured memory_bytes: 3060
N = int(input())
C = {'AC' : 0, 'WA' : 0, 'TLE' : 0, 'RE' : 0}
for i in range(N):
    s = input()
    C[s] = C[s] + 1
for k, v in C.items():
    print("{} x {}".format(k, v))

Measured memory_bytes: 9180
N = int(input())
 
testimony = [[] for _ in range(N)]
 
for i in range(N):
    num = int(input())
    for j in range(num):
        person, state = map(int, input().split())
        testimony[i].append([person-1, state])
        
honest = 0
for i in range(1, 2**N):
    flag = 0
    for j in range(N):
        if (i>>j)&1 == 1: # j番目は正直と仮定
            for x,y in testimony[j]:
                if (i>>x)&1 != y: # j番目は正直だが矛盾を発見
                    flag = 1
                    break
    if flag == 0:  # 矛盾がある場合はflag == 1になる
        honest = max(honest, bin(i)[2:].count('1'))  # 1の数をカウントし最大となるものを選択
print(honest)

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

class FirstGrader{
public:
	FirstGrader(int _N);
	~FirstGrader();

	long long int Execute(){ return correctEq(0, num[0]); }

private:
	int N;
	int num[100];
	long long int memo[100][21];
	long long int correctEq(int index, int sum);
};

FirstGrader::FirstGrader(int _N) : N(_N){
	for (int i = 0; i < _N; i++){
		cin >> num[i];
	}
	// memoを-1で初期化
	for (int i = 0; i < 100; i++){
		for (int j = 0; j < 21; j++){
			memo[i][j] = -1;
		}
	}
}
FirstGrader::~FirstGrader(){};

long long int FirstGrader::correctEq(int index, int sum){
	if (index == N-2) {
		if (sum == num[N-1]) return 1;
		else return 0;
	}
	if (memo[index][sum] >=0) return memo[index][sum];

	memo[index][sum] = 0;
	if (sum + num[index + 1] <= 20) memo[index][sum] += correctEq(index+1, sum+num[index+1]);
	if (sum - num[index + 1] >= 0)  memo[index][sum] += correctEq(index+1, sum-num[index+1]);

	return memo[index][sum];
}

int main(){
	int N;
	cin >> N;
	
	FirstGrader* fg = new FirstGrader(N);
	cout << fg->Execute() << endl;
	
	delete fg;
	return 0;
}

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

    N -= 2;

    int res = 0;
    rep(i, 0, N)
    {
        res += (i + 1);
    }
    return res;;
}

void _main()
{
    int N, K;
    cin >> N >> K;

    int num = A(N);

    if (K > num)
    {
        cout << -1 << endl;
        return;
    }

    vector<pair<int, int>> edges;
    rep(i, 0, N - 1)
    {
        edges.emplace_back(1, 2 + i);
    }

    int src = 2;
    int dist = 1;
    while (num != K)
    {
        edges.emplace_back(src, src + dist);
        if (src + dist == N)
        {
            src = 2;
            ++dist;
        }
        else
        {
            ++src;
        }

        --num;
    }

    cout << edges.size() << endl;
    for (const auto edge : edges)
    {
        cout << edge.first << " " << edge.second << endl;
    }
}


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

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

    vector<int> x(n);
    for(int i = 0; i < n; i++) cin >> x[i];

    int ans = 1e9;
    for(int i = 1; i <= 100; i++) {
        int cost = 0;
        for(int j = 0; j < n; j++) {
            cost += (x[j] - i) * (x[j] - i);
        }
        if(ans > cost) ans = cost;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
#define dbg(x...) do { cout << "\033[32;1m" << #x <<" -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<class T, class... Ts> void err(const T& arg,const Ts&... args) { cout << arg << " "; err(args...); }

typedef long double db;
const db eps = 1e-8;
const db pi = acosl(-1.0);
int sgn(db x){if(fabs(x) < eps) return 0; return x < 0 ? -1 : 1;}
struct Point{
    db x, y;
    Point(){}
    Point(db x, db y):x(x), y(y){}
    void input(){cin >> x >> y;}
    Point operator - (const Point &b) const{
        return Point(x - b.x, y - b.y);
    }
    Point operator + (const Point &b) const{
        return Point(x + b.x, y + b.y);
    }
    db operator ^ (const Point&b)const{
        return x * b.y - y * b.x;
    }
    db operator * (const Point &b) const{
        return x * b.x + y * b.y;
    }
    db len2(){
        return x * x + y * y;
    }
    db len(){
        return sqrtl(len2());
    }
};
struct Line{
    Point s, e;
    Line(){};
    Line(Point s, Point e) :s(s), e(e){}
    void input(){ s.input(); e.input(); }
    int isParallel(Line v) {
        db val = (e - s) ^ (v.e - v.s);
        if(sgn(val) == 0) return 2;
        if(sgn(fabs(val) - (e - s).len() * (v.e - v.s).len()) == 0) return 1;
        return 0;
    }
}l1, l2;


int main(){
#ifndef ONLINE_JUDGE
//freopen("i.in","r",stdin);
//  freopen("o.out","w",stdout);
#endif
    
    int T;scanf("%d", &T);
    while(T--){
        l1.input(); l2.input();
        cout << l1.isParallel(l2) << endl;
    }

    return 0;
}


Measured memory_bytes: 3324
#include<iostream>
using namespace std;
int main(){
  int n,cnt=0;
  int a[101]={};
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  int flag=1;
  while(flag){
    flag=0;
    for(int i=n-1;i>=1;i--)
      if(a[i]<a[i-1]){
	int temp=a[i];
	a[i]=a[i-1];
	a[i-1]=temp;
	flag=1;
	cnt++;
    }
  }
    for(int i=0;i<n-1;i++)
      cout<<a[i]<<' ';
    cout<<a[n-1]<<endl<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n;
  cin >> n;
  vector<i64> a(n);
  for (i64 i = 0; i < n; i++)
    cin >> a[i];
  i64 q;
  cin >> q;
  vector<pair<i64, i64>> xy(q);
  for (i64 i = 0; i < q; i++)
  {
    cin >> xy[i].first >> xy[i].second;
    xy[i].first--;
    xy[i].second--;
  }
  vector<i64> s = a;
  sort(s.begin(), s.end());
  i64 dif = 0;
  for (i64 i = 0; i < n; i++)
    if (a[i] != s[i])
      dif++;
  if (dif == 0)
  {
    cout << 0 << endl;
    return 0;
  }
  for (i64 i = 0; i < q; i++)
  {
    i64 now[2] = {a[xy[i].first], a[xy[i].second]}, aft[2] = {s[xy[i].first], s[xy[i].second]};
    i64 d = (now[1] == aft[0]) + (now[0] == aft[1]) - (now[0] == aft[0]) - (now[1] == aft[1]);
    dif -= d;
    if (dif == 0)
    {
      cout << i + 1 << endl;
      return 0;
    }
    swap(a[xy[i].first], a[xy[i].second]);
  }
  cout << -1 << endl;
  return 0;
}



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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a + b) == (c + d)) {
    cout << "Balanced";
  } else if ((a + b) > (c + d)) {
    cout << "Left";
  } else {
    cout << "Right";
  }
}

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

const ll MOD = (ll)(1e9) + 7;
ll dp[101][4][4][4];

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

    // A -> 0, C -> 1, G -> 2, T -> 3
    // 012, 102, 021, 0?12, 01?2
    dp[0][3][3][3] = 1;
    for (int len = 1; len <= n; len++) {
        rep(c1, 4) { // 右から1文字目
            rep(c2, 4) {  // 右から2文字目
                rep(c3, 4) { // 右から3文字目
                    rep(a, 4) { // 新たに追加する文字
                        if (a == 2 && c1 == 1 && c2 == 0) continue;
                        if (a == 2 && c1 == 0 && c2 == 1) continue;
                        if (a == 1 && c1 == 2 && c2 == 0) continue;
                        if (a == 2 && c1 == 1 && c3 == 0) continue;
                        if (a == 2 && c2 == 1 && c3 == 0) continue;
                        dp[len][a][c1][c2] += dp[len-1][c1][c2][c3];
                        dp[len][a][c1][c2] %= MOD;
                    }
                }
            }
        }
    }

    ll ans = 0;
    rep(c1, 4) {
        rep(c2, 4) {
            rep(c3, 4) {
                ans += dp[n][c1][c2][c3];
                ans %= MOD;
            }
        }
    }

    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
function main(input) {
  const S = parseInt(input, 10);
  let ary = [];
  let ans;
  
  ary.push(S);
  
  for (let n = 2; ; n++) {
    num = check(ary[n-2]);
    if (ary.includes(num)) {
	  ans = n;
      break;
    } else {
      ary.push(num);
    }
  }
  
  console.log(ans);
}

function check(n) {
  if (n % 2 === 0) {
    return n / 2;
  } else {
    return (3 * n) + 1;
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 30680
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int a;
  cin>>a;
  cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3636
#include<iostream>

using namespace std;

int main(void){
	std::ios_base::sync_with_stdio();

	int n;
	int cnt;

	while(1){
		cin>>n;
		if(n==0) break;
		cnt=0;
		while(1){
			if(n==1) break;
			if(n%2==0) n/=2;
			else n=n*3+1;
			cnt++;
		}
		cout<<cnt<<endl;
	}

	return 0;
}

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

using namespace std;

int main() {
    vector<int> rank;

    int n, q;
    cin >> n >> q;

    for (int i = 0; i < n; i++) {
        rank.push_back(i);
    }

    for (int i = 0; i < q; i++) {
        int c;
        int x, y;

        cin >> c >> x >> y;
        if (c == 0) {
            int a = rank[x];
            int b = rank[y];

            if (a == b) {
                continue;
            }
            for (int j = 0; j < n; j++) {
                if (rank[j] == b)
                    rank[j] = a;
            }
        } else {
            if (rank[x] == rank[y]) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }
}

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

using namespace std;
#define REP(i, n)  for(int i=0;i<(int)(n);++i)
#define FOR(i, b, n)  for(int i=b;i<(n);++i)
#define ALL(c) (c).begin(),(c).end()
#define PB(c) push_back(c)
#define SS size()
#define ST first
#define ND second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }
template<typename T> void sout(T &w) {
  for (auto x : w) cout << x << ", ";
  cout << endl;
}


int main() {
  ios::sync_with_stdio(0);
  int n; cin >> n;
  vi low(11), hig(11);
  low[1] = 1;
  hig[1] = 9;
  FOR(i,1,10) {
    low[i+1] = low[i] * 10;
    hig[i+1] = hig[i] * 10 + 9;
  }
  int dig = 0;
  int nn = n;
  while(nn>0) dig++, nn/=10;
  int ans = 0;
  FOR(i,1,10) {
    if (i%2) {
      if (dig==i) {
        ans += n - low[i] + 1;
        break;
      } else {
        ans += hig[i] - low[i] + 1;
      }
    }
    if (i>=dig) break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream> 
using namespace std;
 
int main(){
    string S, T;
    cin >> S >> T;
    for(int i = S.size() - T.size(); i >= 0; i--){
        bool if_ok = false;
        for(int j = 0; j < T.size(); j++){
            if(S[i + j] != '?' && S[i + j] != T[j]){
                if_ok = true;
                break;
            }
        }
        if(!if_ok){
            for(int j = 0; j < i; j++){
                if(S[j] == '?'){
                    S[j] = 'a';
                }
            }
            for(int j = i; j < i + T.size(); j++){
                S[j] = T[j - i];
            }
            for(int j = i + T.size(); j < S.size(); j++){
                if(S[j] == '?'){
                    S[j] = 'a';
                }
            }
            cout << S << endl;
            return 0;
        }
    }
    cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

B = [A[i]-i-1 for i in range(N)]
B.sort()
if N%2:
        b = B[(N-1)//2]
else:
        b = (B[N//2]+B[N//2 - 1])//2

print(sum([abs(A[i]-b-i-1) for i in range(N)]))

Measured memory_bytes: 27712
#include <stdio.h>

int main()
{
	int a, b,
		div, rem;
	double fValue;
	
	scanf("%d %d", &a, &b);
	
	div    = a / b;
	rem    = a % b;
	fValue = (double)a / (double)b;
	
	printf("%d %d %.6f\n", div, rem, fValue);
	
	return 0;
}


Measured memory_bytes: 2748
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdlib>
typedef long long ll;
using namespace std;
#define M 1020751

long long convert(string word);
void insert(long long *d,long long key);
int find_key(long long *d,long long key);
int h1(long long key);
int h2(long long key);
int main(){
  int i,n;
  cin>>n;
  string order,word;
  long long key;
  long long d[M];
  queue<string> q;
  for(i=0;i<M;i++){
    d[i]=-1;
  }
  for(i=0;i<n;i++){
    cin>>order>>word;
    key=convert(word);
    if(order[0]=='i'){
      insert(d,key);
    }else{
      int flag=find_key(d,key);
      if(flag==1){
        q.push("yes");
      }else{
	q.push("no");
      }
    }
  }
  while(!q.empty()){
    cout<<q.front()<<endl;
    q.pop();
  }
}
    
long long convert(string word){
  long long i,num=0,keta=1;
  for(i=0;i<word.size();i++){
    if(word[i]=='A'){
      num+=keta;
    }else if(word[i]=='C'){
      num+=keta*2;
    }else if(word[i]=='G'){
      num+=keta*3;
    }else{
      num+=keta*4;
    }
    keta*=10;
  }
  return num;
}
void insert(long long *d,long long key){
  int h,i=1;
  h=h1(key);
  while(d[h]!=-1){
    h=(h1(key)+i*h2(key))%M;
    i++;
  }
  d[h]=key;
}
int find_key(long long *d,long long key){
  int h,i=0;
  h=h1(key);
  while(1){
    if(d[h]==-1){
      return 0;
    }else if(d[h]!=key){
      i++;
      h=(h1(key)+i*h2(key))%M;
    }else{
      return 1;
    }
  }   
}
int h1(long long key){
  return key%M;
}
int h2(long long key){
  return 1+(key%(M-1));
}

Measured memory_bytes: 34556
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

bunpu_hash = A.group_by { |i| i }
bunpu_array = bunpu_hash.map { |k,v| v.size }
bunpu_array.sort!

puts N - bunpu_array.reverse[0...K].inject(:+)

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#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の二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n, m, a;
    cin >> n >> m;
    priority_queue<ll> pq;
    REP(i, n){
        cin >> a;
        pq.push(a);
    }
    REP(i, m){
        ll tmp = pq.top();
        pq.pop();
        tmp /= 2;
        pq.push(tmp);
    }
    ll ans = 0;
    REP(i, n){
        ans += pq.top();
        pq.pop();
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
using ll = long long;
signed main(){
    ll N,M;
    string S,T;
    cin>>N>>M>>S>>T;
    ll K=__gcd(N,M);
    for(ll i=0;i<K;i++)
        if(S[N/K*i]!=T[M/K*i]){
            puts("-1");
            return 0;
        }
    cout<<N/K*M<<endl;
}

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

i=1
j=1

c=a
d=b

while(i<b):
  c+=a*(10**i)
  i+=1

while(j<a):
  d+=b*(10**j)
  j+=1

list=[str(c),str(d)]
list.sort()

if(a==b):
  print(str(c))
else:
  print(list[0])

Measured memory_bytes: 3064
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
for i in range(n):
    A = list(map(int,input().split()))
    ans = 0
    for j in range(m):
        ans += A[j]*b[j]
    ans = ans + c
    if ans > 0:
        count+= 1
print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define MAX 105000
int main(){
  bool prime[MAX + 1] = {};
  int sum = 0, cnt = 0;
  vector< int > vc;
  vc.push_back(2);

  for(int i = 3 ; cnt < 10001 ; i += 2 ){
    if(!prime[i]){
      vc.push_back(i + vc[cnt++]);
      for(int j = 3 ; i * j <= MAX ; j += 2 ){
	prime[i * j] = true;
      }
    }
  }

  int n;
  while(cin >> n , n){
    cout << vc[n - 1] << endl;
  }
}

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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int main() {
    ll n,d;
    cin >> n >> d;

    pl((n+d*2+1-1)/(d*2+1))

    return 0;
}


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

using namespace std;

int main(){
	long long p[10]={};
	long long h,w,n;
	cin >> h >> w >> n;
	int a,b,count;
	pair<int,int> tmp;
	vector<pair<int,int> > v;
	for(int i=0;i<n;i++){
		cin >> a >> b;
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if((a-1+j)>1&&(a-1+j)<h&&(b-1+k)>1&&(b-1+k)<w){
					tmp = make_pair(a-1+j,b-1+k);
					v.push_back(tmp);
				}
			}
		}
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		if(i==0){
			count=1; 
		}else if(i==v.size()-1){
			if(v[i-1].first==v[i].first&&v[i-1].second==v[i].second){
				count +=1;
				p[count]+=1;
			}else{
				p[count]+=1;
				p[1]+=1;
			}
		}else{
			if(v[i-1].first==v[i].first&&v[i-1].second==v[i].second){
				count+=1;
			}else{
				p[count]+=1;
				count=1;
			}
		}
	}
	p[0]=(h-2)*(w-2);
	for(int i=1;i<10;i++){
		p[0] -=p[i];
	}
	for(int i=0;i<10;i++){
		cout << p[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 8556
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	var count = input[0]-0;
	var values = input[1].split(" ");
	for(var i = 0; i < count; i++) values[i] = values[i] - 0;
	values.sort(function(a,b){ return a - b; });
	var previous = values[0];
	for(var i = 1; i < count; i++) {
		previous = (previous + values[i]) / 2;
	}
	console.log(previous);

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

Measured memory_bytes: 7500
def main():
    H, W, D = map(int, input().split())
    A = tuple(tuple(map(int, input().split())) for _ in [0] * H)
    Q = int(input())
    LR = tuple(tuple(map(int, input().split())) for _ in [0] * Q)

    grid = dict()
    for i, a in enumerate(A):
        for j, b in enumerate(a):
            grid[b] = (i + 1, j + 1)

    l = H * W
    dist = [0] * (l + 1)
    for i in range(l, 0, -1):
        if i + D <= l:
            dist[i] = abs(grid[i][0] - grid[i+D][0]) + abs(grid[i][1] - grid[i+D][1]) + dist[i+D]
        else:
            dist[i] = 0

    for l, r in LR:
        print(dist[l] - dist[r])

main()


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

int main() {
  string S;
  cin >> S;
  string Y;
  string M;
  
  Y = Y + S.at(0) + S.at(1);
  M = M + S.at(2) + S.at(3);
  
  if (Y == "01" || Y == "02" || Y == "03" || Y == "04" || Y == "05" || Y == "06" ||
      Y == "07" || Y == "08" || Y == "09" || Y == "10" || Y == "11" || Y == "12" ) {
    if (M == "01" || M == "02" || M == "03" || M == "04" || M == "05" || M == "06" ||
        M == "07" || M == "08" || M == "09" || M == "10" || M == "11" || M == "12") {
      cout << "AMBIGUOUS" << endl;
    }
    else {
      cout << "MMYY" << endl;
    }
  }
  else {
    if (M == "01" || M == "02" || M == "03" || M == "04" || M == "05" || M == "06" ||
        M == "07" || M == "08" || M == "09" || M == "10" || M == "11" || M == "12") {
      cout << "YYMM" << endl;
    }
    else {
      cout << "NA" << endl;
    }
  }
}


Measured memory_bytes: 256
n, k = list(map(int, input().split()))
MOD = 1000000007
dp = [[0] * 2002]
dp[0][1] = 1
for i in range(1, 2002):
  dp.append([0] * 2002)
  for j in range(1, 2002):
    dp[i][j] = (dp[i-1][j] + dp[i-1][j-1]) % MOD
for i in range(1, k+1):
  print((dp[n-k + 1][i+1] * dp[k-1][i]) % MOD)


Measured memory_bytes: 98348