akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] xs = new int[n];
        for (int i = 0; i < n; i++) xs[i] = input.nextInt();
        
        // sort
        int count = 0;
        for (int i = 0; i < xs.length; i++) {
            int min = i;
            for (int j = i; j < xs.length; j++) {
                if (xs[j] < xs[min]) {
                    min = j;
                }
            }
            if (i != min) {
                int temp = xs[i];
                xs[i] = xs[min];
                xs[min] = temp;
                count++;
            }
        }
        print(xs);
        System.out.println(count);
    }
    
    private void print(int[] xs) {
        StringBuilder sb = new StringBuilder();
        for (int x : xs) sb.append(x).append(' ');
        System.out.println(sb.toString().trim());
    }
}

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

ll cnt[200200];
ll sum (ll x){
return (x*(x+1))/2;
}
int main(){
	
	ll n; cin>>n; ll arr[n];
	for(int i = 0; i < n; i++){
		cin>>arr[i];
	}
	for(int i = 0; i < n; i++){
		cnt[arr[i]]++;
	}
	ll ans = 0;
	for(int i = 0; i < 200200; i++){
		if(cnt[i]) ans += sum(cnt[i]-1);
	}
	ll best = 0;
	//cout<<ans<<"\n";
	for(int i = 0; i < n; i++){
		best = ans - sum(cnt[arr[i]]-1);
		best = best + sum(cnt[arr[i]]-2);
		cout<<best<<"\n";
	}
	
	
	
}

Measured memory_bytes: 4736
n, a, b = map(int, input().split())
bo = a + b
sl = list(input())
pa, pb = 0, 0
              
for i in range(n):
  if pa + pb < bo:
    if sl[i] == 'c':
      print('No')
    elif sl[i] == 'a':
      print('Yes')
      pa += 1
    elif sl[i] == 'b' and pb < b:
      print('Yes')
      pb += 1
    else:
      print('No')
  else:
  	print('No')

Measured memory_bytes: 9980
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long i,j,n,r=0;
 string a,b,c;
 cin>>n>>a>>b>>c;
 for(i=0;i<n;i++)
 {
    if(a[i]==b[i] && b[i]==c[i]) continue;
    else if(a[i]==b[i]||b[i]==c[i]||c[i]==a[i]) r++;
    else r+=2;
 }
 cout<<r<<endl;
return 0;
}


Measured memory_bytes: 3588
//%std
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out = 0, fh = 1;
	char jp = getchar();
	while ((jp > '9' || jp < '0') && jp != '-')
		jp = getchar();
	if (jp == '-')
		fh = -1, jp = getchar();
	while (jp >= '0' && jp <= '9')
		out = out * 10 + jp - '0', jp = getchar();
	return out * fh;
}
const int P = 998244353;
int add(int a, int b)
{
	return a + b >= P ? a + b - P : a + b;
}
void inc(int &a, int b)
{
	a = add(a, b);
}
int mul(int a, int b)
{
	return 1LL * a * b % P;
}
int fpow(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b & 1)
			res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}
const int N = 1e5 + 10;
vector<int> G[3][N];
int n, m[3], mx = 0, SG[3][N], sum[3][N], cnt[3][N], bucket[N]; 
int main()
{
	n = read();
	for (int k = 0; k < 3; ++k)
	{
		m[k] = read();
		for (int i = 1; i <= m[k]; ++i)
		{
			int u = read(), v = read();
			if (u > v)
				swap(u, v);
			G[k][u].push_back(v);
		}
		for (int i = n; i >= 1; --i)
		{
			for (int x : G[k][i])
				bucket[SG[k][x]] = 1;
			for (int val = 0; val <= mx + 1; ++val)
				if (!bucket[val])
				{
					SG[k][i] = val;
					mx = max(mx, val);
					break;
				}
			inc(sum[k][SG[k][i]], fpow(10, 18 * i));
			for (int x : G[k][i])
				bucket[SG[k][x]] = 0;
		}
	}
	int ans = 0;
	for (int x = 0; x <= mx; ++x) if (sum[0][x])
		for (int y = 0; y <= mx; ++y) if (sum[1][y])
			inc(ans, mul(sum[0][x], mul(sum[1][y], sum[2][x ^ y])));
	printf("%d\n", ans);
	return 0;
}


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

int main(){
  string ss;
  string t;
  cin>>ss;
  cin>>t;

  int i,j,m;
  bool syori=0;
  for(i=0;i<ss.size();i++){
    // cout<<i<<endl;
    bool moji=0;
    if(ss.at(i)=='?'||ss.at(i)==t.at(0)){
      for(j=0;j<t.size();j++){
        if(i+j>=ss.size()){
          moji=0;
          break;
        }
        if(ss.at(i+j)=='?'||ss.at(i+j)==t.at(j)){
          moji=1;
        }
        else{
          moji=0;
          break;
        }
      }
    }
    if(moji){
      syori=1;
      m=i;
    }
  }

  if(syori){
    for(int k=0;k<t.size();k++){
      ss.at(m+k)=t.at(k);
    }
    for(int k=0;k<ss.size();k++){
      if(ss.at(k)=='?')
      ss.at(k)='a';
    }
    cout<<ss<<endl;
  }
  else
  cout<<"UNRESTORABLE"<<endl;

}

Measured memory_bytes: 256
import numpy as np
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
A = np.cumsum(A)
A = list(A)
dic = defaultdict(int)
for i in A:
    dic[i] += 1

# print (dic)

ans = 0
for i in dic:
    ans += dic[i] * (dic[i] - 1)
ans //= 2

if 0 in dic:
    ans += dic[0]

print (ans)

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

inline ll gcd(ll a, ll b) {
	if(a==0) return b;
	if(a>b) return gcd(a%b, b);
	else return gcd(b%a, a);
}

ll primeNum(ll g) {
	ll cnt = 1;
	ll i = 2;
	ll now = g;
	while (now > 1) {
		if(now%i==0) cnt++;
		while(now%i==0) {
			now /= i;		
		}
		i++;
		if(i*i>g) {
			cnt++;
			break;
		}
	}
	return cnt;
}

int main(){
	ll a,b;
	cin >> a >> b;
	ll g = gcd(a,b);
	ll num = primeNum(g);
	cout << num << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll n;
	cin >> n;
	ll m = 3*n;
	vector<ll> a(m);
	for(ll i = 0; i < m; i++){
		cin >> a[i];
	}

	sort(all(a));
	reverse(all(a));

	ll ans = 0;
	for(ll i = 1; i <= n; i++){
		ans += a[i*2-1];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
def roll(dice,dir)
  case dir
  when "N" then dice[0],dice[1],dice[5],dice[4] = dice[1],dice[5],dice[4],dice[0]
  when "S" then dice[0],dice[1],dice[5],dice[4] = dice[4],dice[0],dice[1],dice[5]
  when "E" then dice[0],dice[2],dice[5],dice[3] = dice[3],dice[0],dice[2],dice[5]
  when "W" then dice[0],dice[2],dice[5],dice[3] = dice[2],dice[5],dice[3],dice[0]
  end
  dice
end

def same?(d1,d2)
  yn = false    
  for i in 1..6
    d = Marshal.load(Marshal.dump(d2))
    case i
    when 2 then d = roll(d,"S")
    when 3 then d = roll(roll(d,"W"),"S")
    when 4 then d = roll(d,"N")
    when 5 then d = roll(roll(d,"E"),"S")
    when 6 then d = roll(roll(d,"S"),"S")
    end
    next if d[1] != d1[1]
    next if d[4] != d1[4]
    for j in 1..4
      d = roll(d,"W")
      yn = (d == d1)
      break if yn
    end
    break if yn
  end
  yn
end

n = gets.to_i
ds = Array.new(n){gets.split(" ").map{|i| i.to_i}}
yn = false

for i in 1..n-1
  for j in 0..i-1
    yn = same?(ds[i],ds[j])
    break if yn
  end
  break if yn
end

puts(yn ? "No" : "Yes")

Measured memory_bytes: 10000
#include <stdio.h>
#include <math.h>

int main(){
	double xa,ya,ra,xb,yb,rb;
	int num,i;
	double d;
	int result;
	scanf("%d",&num);
	for(i=0;i<num;i++){
		scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);
		d=hypot((double)(xa-xb),(double)(ya-yb));
		
		if(d>ra+rb){
			result=0;
		}else if(d+rb<ra){
			result=2;
		}else if(d+ra<rb){
			result=-2;
		}else{
			result=1;
		}
		
		printf("%d\n",result);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll N;
vector<ll> A;

int main() {
	cin >> N;
	A.resize(N + 2,0);
	for (ll n = 1; n <= N; n++)cin >> A[n];
	for (ll n = 1; n <= N + 1; n++) {
		A[n] += A[n - 1];
	}
	ll ans = LLONG_MAX;
	for (ll n = 1; n < N; n++) {
		ll res = A[n] - (A[N] - A[n]);
		ans = min(ans, abs(res));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
const int maxn = 105;
char s[maxn][maxn];
int r[maxn][maxn], c[maxn][maxn];
int f[maxn * maxn >> 2][maxn * maxn >> 2];
int h, w, X, Y;
 
inline int encode(int l, int r, int M) {
	return r * M + l;
}
 
inline void chkmax(int& x, int v) {
	x = max(x, v);
}
 
int dfs(int lX, int rX, int lY, int rY) {
	int cX = encode(lX, rX, X), cY = encode(lY, rY, Y);
	if (f[cX][cY] >= 0) return f[cX][cY]; f[cX][cY] = 0;
	if (lX < X - 1) {
		chkmax(f[cX][cY], dfs(lX + 1, rX, lY, rY) + (rX + 1 <= X - lX - 1 ? max(0, r[X - lX - 1][min(Y + rY, w - lY)] - r[X - lX - 1][max(Y - lY, rY + 1) - 1]) : 0));
	}
	if (rX < h - X) {
		chkmax(f[cX][cY], dfs(lX, rX + 1, lY, rY) + (X + rX + 1 <= h - lX ? max(0, r[X + rX + 1][min(Y + rY, w - lY)] - r[X + rX + 1][max(Y - lY, rY + 1) - 1]) : 0));
	}
	if (lY < Y - 1) {
		chkmax(f[cX][cY], dfs(lX, rX, lY + 1, rY) + (rY + 1 <= Y - lY - 1 ? max(0, c[min(X + rX, h - lX)][Y - lY - 1] - c[max(X - lX, rX + 1) - 1][Y - lY - 1]) : 0));
	}
	if (rY < w - Y) {
		chkmax(f[cX][cY], dfs(lX, rX, lY, rY + 1) + (Y + rY + 1 <= w - lY ? max(0, c[min(X + rX, h - lX)][Y + rY + 1] - c[max(X - lX, rX + 1) - 1][Y + rY + 1]) : 0));
	}
	return f[cX][cY];
}
 
int main() {
	scanf("%d%d", &h, &w);
	for (int i = 1; i <= h; ++i) scanf("%s", s[i] + 1);
	for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) 
		if (s[i][j] == 'E') X = i, Y = j;
	for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) {
		r[i][j] = r[i][j - 1] + (s[i][j] == 'o');
		c[i][j] = c[i - 1][j] + (s[i][j] == 'o');
	}
	memset(f, -1, sizeof(f));
	return printf("%d\n", dfs(0, 0, 0, 0)), 0;
}

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

#define int long long
#define fs first
#define sc second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define vc vector
#define pr pair
#define endl "\n"
#define endd "\n"; return 0;
#define all(v) v.begin(), v.end()

using namespace std;

const int MAXN = 1e5;
const int INF = 1e10;
const int MOD = 1e9 + 7;

main() {
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    map<int, int> k;
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        k[a]++;
        k[b]++;
    }
    for (int i = 0; i < n; i++){
        cout << k[i + 1] << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> x(N);
  for(int i=0;i<N;i++)  cin >> x.at(i);

  int ans=300000001;
  for(int i=0;i<N-K+1;i++){
    int left=x.at(i);
    int right=x.at(i+K-1);
    int time=min(abs(left)+abs(right-left),abs(right)+abs(right-left));
    if(time<ans)  ans=time;
  }
  cout << ans << endl;

  return 0;
}


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


int len[100001];
int a[100001];
int n,k;

int main(){
  for(;;){
    cin >> n >> k;
    if(!n && !k)break;
    for(int i=0;i<k;i++)cin >> a[i];
    for(int i=0;i<=n;i++)len[i] = 0;
    sort(a,a+k);

    int pos=0;
    int dif=1;

    if(!a[0])pos++;
    while(pos<k){
      while(pos+dif<k && a[pos+dif-1]+1==a[pos+dif])dif++;
      for(int i=0;i<dif;i++)len[a[pos]+i] = dif;
      pos += dif;
      dif = 1;
    }

    int m=0;
    if(a[0]){
      for(int i=0;i<=n;i++)m = max(m,len[i]);
    }else{
      for(int i=0;i<=n;i++)
	if(i && i!=n-1 && !len[i])m = max(m,len[i-1] + len[i+1] + 1);
    }
    cout << m << endl;
  }
}

Measured memory_bytes: 0
#include<cstdio>

int main(void) {
	int l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, v1, v2;
	int sum, num;
	double p;

	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l1, &l2, &l3, &l4, &l5, &l6, &l7, &l8, &l9, &l10, &v1, &v2) != EOF) {
		sum = l1 + l2 + l3 + l4 + l5 + l6 + l7 + l8 + l9 + l10;
		p = (double)sum * v1 / (v1 + v2);
		if(p <= l1) { num = 1; }
		else if(p <= l1 + l2) { num = 2; }
		else if(p <= l1 + l2 + l3) { num = 3; }
		else if(p <= l1 + l2 + l3 + l4) { num = 4; }
		else if(p <= l1 + l2 + l3 + l4 + l5) { num = 5; }
		else if(p <= l1 + l2 + l3 + l4 + l5 + l6) { num = 6; }
		else if(p <= l1 + l2 + l3 + l4 + l5 + l6 + l7) { num = 7; }
		else if(p <= l1 + l2 + l3 + l4 + l5 + l6 + l7 + l8) { num = 8; }
		else if(p <= l1 + l2 + l3 + l4 + l5 + l6 + l7 + l8 + l9) { num = 9; }
		else { num = 10; }
		printf("%d\n", num);
	}

	return 0;
}

Measured memory_bytes: 0
s = int(input())
x1 = 0
y1 = 0
x2 = int(1e9)
y2 = 1
x3 = (x2-s%x2)%x2
y3 = int((s+x3)/x2)
print(x1,y1,x2,y2,x3,y3)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

typedef ll Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

const ll INF = 1e12;
int n, m;
vector<tuple<int, int, int>> v;

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	cin >> n >> m;
	Graph g(n);
	REP(i, m)
	{
		ll l, r, d; cin >> l >> r >> d;
		l--; r--;
		v.emplace_back(l, r, d);
		add_edge(g, l, r, d);
		add_edge(g, r, l, -d);
	}
	vi dist(n, INF);
	REP(i, n)
	{
		if (dist[i] != INF) continue;
		dist[i] = 0;
		queue<ll> que;
		que.push(i);
		while (!que.empty())
		{
			ll t = que.front();
			que.pop();
			for (auto e : g[t])
			{
				if (dist[e.to] != INF) continue;
				dist[e.to] = dist[t] + e.cost;
				que.push(e.to);
			}
		}
	}
	bool ans = true;
	for (auto t : v)
	{
		ll l, r, d;
		tie(l, r, d) = t;
		if (dist[r] - dist[l] != d) ans = false;
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 16944
#include <bits/stdc++.h>
using namespace std;
#define int long long

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int N;cin>>N;
  typedef pair<int,int> P;
  vector<int> rc(N,-1),cr(N);
  int out=0;
  for(int i=0;i<N;i++){
    int r,c;cin>>r>>c;r--;c--;
    if(~rc[r])out++;
    rc[r]=c;
    cr[c]=r;
  }
  if(out)fin(-1);
  int ans=0;
  for(int i=0;i<N;i++){
    if(rc[i]==i)continue;
    ans++;
    int tmp=rc[i];
    swap(rc[i],rc[cr[i]]);
    swap(cr[tmp],cr[i]);
  }
  fin(ans);
}



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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int n;
string s[50];

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

	cin >> n;
	rep(i, 0, n) cin >> s[i];

	map<char, int> m[n];
	rep(i, 0, n) {
		rep(j, 0, s[i].size()) {
			m[i][s[i][j]]++;
		}
	}

	string res = "";
	map<char, int> tmp;
	map<char, int> used;
	rep(j, 0, 26) tmp[char('a' + j)] = 51;
	rep(i, 0, n) rep(j, 0, 26) {
		tmp[char('a' + j)] = min(tmp[char('a' + j)], m[i][char('a' + j)]);
		used[char('a' + j)]++;
	}

	rep(i, 0, 26) {
		int num = tmp[char('a' + i)];
		if(used[char('a' + i)] == n) {
			rep(j, 0, num) {
				res += char('a' + i);
			}
		}
	}

	cout << res << endl;

}


Measured memory_bytes: 384
#include <stdio.h>

int main(void) {  
  int N=0, M=0;
  int vote[100];
  scanf("%d%d",&N,&M);
  int count = 0;
  int sum = 0;
  for (int i = 0; i < N; ++i) { 
    scanf("%d",&vote[i]);
    sum += vote[i];
  }
  
  for (int i = 0; i < N; ++i){
    if (vote[i] >= (double)sum/(4*M)) count++;
  }
  
  if (count >= M) printf("Yes");
  else printf("No");
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int unsigned long long
const int mod=1e9+7;
using namespace std;
int fact[300005],infact[300005],a,b,h,w,sum=0;
int C(int k,int n)
{
	int temp1=(fact[n]%mod*infact[k]%mod)%mod;
	return (temp1%mod*infact[n-k]%mod)%mod;
}
int power(int n,int k)
{
	if(k==1) return n%mod;
	else if(k==0) return 1;
	else
	{
		int tmp=power(n,k/2)%mod;
		if(k%2==0)
		return ((tmp%mod)*(tmp%mod))%mod;
		else return (((tmp%mod)*(tmp%mod))%mod*(n%mod))%mod;
	}
}
signed main()
{
	fact[0]=1;
	infact[0]=1;
	for(int i=1;i<=205505;i++)
	{
		fact[i]=(i%mod*fact[i-1]%mod)%mod;
		infact[i]=power(fact[i]%mod,mod-2)%mod;
	}
	//cout<<C(44444,100000);
	cin>>h>>w>>a>>b;
	for(int j=b+1;j<=w;j++)
	{
		sum=(sum+(C(j-1,j-1+h-a-1)%mod*C(a-1,a-1+w-j)%mod)%mod)%mod;
	//	cout<<j-1<<" "<<j-1+h-a-1<<" "<<C(a-1,a-1+w-j)<<"\n";		
	}
	cout<<sum;
}

Measured memory_bytes: 3840
#include<stdio.h>
int main(){
  int arr[3];
  int i;
  for(i=0;i<3;i++){
    scanf("%d ",&arr[i]);
  }
  int j,count=1;
  for(i=1;i<3;i++){
    int flag=1;
    for(j=0;j<i;j++){
      if(arr[i]==arr[j]){
        flag=0;
        break;
      }
    }
    if(flag==1) count++;
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1732
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    s=[readline().strip() for _ in range(n)]

    for i in range(n):
        if i==0:
            alp=np.zeros(26,dtype=np.int64)
            t=s[i]
            for j in range(len(t)):
                alp[ord(t[j])-97]+=1
        else:
            tmp=np.zeros(26,dtype=np.int64)
            t=s[i]
            for j in range(len(t)):
                tmp[ord(t[j])-97]+=1
            alp=np.minimum(alp,tmp)

    ans=""
    for i in range(26):
        if alp[i]>=1:
            ans+=chr(i+97)*alp[i]

    print(ans)

if __name__=="__main__":
    main()

Measured memory_bytes: 12500
#include <stdio.h>

int main(void) {
    int i, j, N;
    double p[3010], dp[3010][3010] = {0.0}, r;
    scanf("%d", &N);
    for (i=1;i<=N;i++) scanf("%lf", &p[i]);

    dp[0][0] = 1.0;
    for (i=1;i<=N;i++) {
        for (j=0;j<=i;j++) {
            if (j<i) dp[i][j] += dp[i-1][j] * (1.0 - p[i]);
            if (j>0) dp[i][j] += dp[i-1][j-1] * p[i];
        }
    }

    r = 0.0;
    for (j=N;j>N/2;j--) r += dp[N][j]; 
    printf("%.13lf\n", r);
    return 0;
}

Measured memory_bytes: 70912
N=int(input())
W=list(map(int,input().split()))
S1=W[0]
S2=sum(W[1:N])
M=abs(S1-S2)
for i in range(1,N):
    S1+=W[i]
    S2-=W[i]
    newM=abs(S1-S2)
    if newM<M:
        M=newM
print(M)

Measured memory_bytes: 3060
import collections 
N=int(input())
A=list(map(int,input().split()))
A_count = collections.Counter(A)
#print(A_count)
Q=int(input())
S=sum(A)
for i in range(Q):
  B,C=map(int,input().split())
  S += (C-B)*A_count[B]
  A_count[C] += A_count[B]
  A_count[B]= 0
  print(S)

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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

#define DEBUG



// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    // Failed to predict input format

    ll N, K;
    cin >> N >> K;

    vec<ll> targets;
    for(int i=0; i < N; i++){
        int a;
        cin >> a;
        a--;
        targets.push_back(a);
        
    }

    vec<ll> appeared(N, -1);
    appeared.at(0) = 0;
    ll loopStart = -1;
    ll loopSize = -1;
    ll pos = 0;
    ll step = 0;
    while(true){
        pos = targets.at(pos);
        step++;
        if(appeared.at(pos) != -1){
            loopStart = appeared.at(pos);
            loopSize = step - appeared.at(pos);
            break;
        }
        appeared.at(pos) = step;
    }

    ll equivStep = loopStart + (K - loopStart) % loopSize;
    if(loopStart == -1 || K-loopStart < 0){
        // ループにとうたつしなかった
        equivStep = K;
    }

    pos = 0;
    for(ll i=0; i < equivStep; i++){
        pos = targets.at(pos);
    }

    cout << pos + 1 << endl;


    return 0;
}


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

int main(){
  int n; cin>>n;
  vector<pair<ll, ll>> ab(n);
  for (auto &&i : ab)
  {
    cin >> i.second >> i.first;
  }
  sort(ab.begin(), ab.end());
  ll tmpsum = 0;
  for (auto &&i : ab)
  {
    tmpsum += i.second;
    i.second = tmpsum;
  }
  for (auto &&i : ab)
  {
    if (i.second > i.first)
    {
      cout << "No" << endl;
      return 0;
    }
    
  }
  cout << "Yes" << endl;
  return 0;
  
}

Measured memory_bytes: 6408
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    vector<int> y = x;
    sort(x.begin(),x.end());
    int a1 = x[n/2-1];
    int a2 = x[n/2];
    rep(i,n){
        if(y[i]>a1) cout << a1 << endl;
        else cout << a2 << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#define m 1000003
using namespace std;

int T[m];

int h(int k,int i){
  return  (k%m+i*(1+k%(m-1)))%m;
}

int  insert(int k){
  int i=0;
  while(1){
    int j=h(k,i);
    if(j<m && T[j]==0 ){ T[j]=k;return j;}
    else i++;
  }
}

int find(int k){
  int i=0;
  while(1){
    int j=h(k,i);
    if(j<m && T[j]==k) return 1;
    else if((j<m && T[j]==0) || i>=m) return 0;
    else i++;
  }
}


int change(string str1){
  int k=0;
  for(int i=str1.size();i>=0;i--){
    if(str1[i]=='A') k+=1;
    else if(str1[i]=='C') k+=2;
    else if(str1[i]=='G') k+=3;
    else if(str1[i]=='T') k+=4;
    if(i>0) k*=4;
  }
  return k;
}

int main(){
  int n,k,f;
  string str,str1;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>str>>str1;
    k=change(str1);
    if(str[0]=='i') insert(k);
    else{
      f=find(k);
      if(f==1) cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5104
#include <iostream>
using namespace std;
int main()
{
    int n, count = 0;
    string s;
    cin >> n >> s;
    for(int i = 0; i < n - 2; i++) {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<stack>
#include <cstring>
#include <climits>
using namespace std;
#define rep(i,n) for(int (i)=0;(i) < (n); (i)++)
#define rrep(f,i,n) for(int (i)=0;(i) < (f); (i)++)
#define FIND(v, k) find((v).begin(), (v).end(), k)
#define MAX 101
#define MAX_V 15
#define mset(a,x) memset(a,x,sizeof(a))
int a[100000];
int main() {
	int n;
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a, a + n);
	long long sum = 0;
	int i = 0;
	int st = 0;
	while (i < n - 1){
		sum = 0;
		rep(j, st + 1) {
			sum += a[j];
		}
		while (sum * 2 >= a[i + 1]) {
			if (i == n - 1) {
				goto END;
			}
			else {
				i++;
				sum += a[i];
			}
		}
		if(st == i){
			i++;
			st = i;
		}
		else {
			st = i;
		}
	}
END:;
	cout << n - st << endl;
	return 0;
}

Measured memory_bytes: 640
import bisect 
n = int(input())
a = list(map(int, input().split()))
if n == 2:
  print(abs(a[0]-a[1]))
  exit()
com_a = [0 for _ in range(n)]
com_a[0] = a[0]
for i in range(1, n):
  com_a[i] = a[i] + com_a[i-1]

sum_a = sum(a)
middle  = 0
left = 0
for i in range(n):
  if com_a[i] > sum_a/2:
    if com_a[i] - sum_a/2 > sum_a/2 - com_a[i-1]:
      middle = i-1 
    else:
      middle = i
      left += a[i]
    break
  left += a[i]
#middle = bisect.bisect_left(com_a, sum_a/2)
right = sum_a - left
print(abs(left-right))


Measured memory_bytes: 26024
import collections
d = collections.deque([])
n, p = map(int, input().split())
for i in range(n):
    name, t = input().split()
    d.append((name, int(t)))
tt = 0
while len(d) > 0:
    name, t = d.popleft()
    if t <= p:
        tt += t
        print("{0} {1}".format(name, tt))
    elif t > p:
        t = t - p
        tt += p
        d.append((name, t))


Measured memory_bytes: 12532
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
#include <sstream>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

 
int main() {
    ll ans = 0;

    ll n;
    vector<ll> a;

    cin >> n;

    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        a.push_back (temp);
    }

    ll x = 0;

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

    cout << x ;

    for (int i = 0; i < n-1; i++) {
        x = 2 * a[i] - x;
        cout << " " << x;
    }

    cout << endl;

    
}

Measured memory_bytes: 2164
N = int(input())
S = list(input())
a = [0]*(N+1)
r = [0]*(N+1)
rr = [0]*(N+1)
l = [0]*(N+1)
ll = [0]*(N+1)
a = [0]*(N+1)

for i in range(1,N+1):
    if S[i-1] == "E":
        r[i] = r[i-1] + 1
    else:
        r[i] = r[i-1]
for i in range(1,N+1):
    if S[N-i] == "E":
        rr[i] = rr[i-1] + 1
    else:
        rr[i] = rr[i-1]

for i in range(N+1):
    l[i] = i - r[i]
for i in range(N+1):
    ll[i] = i - rr[i] 

for i in range(N+1):
    a[i] = ll[N-i] + r[i]
    
"""
print(r)
print(rr)
print(l)
print(ll)
print(a)
"""

print(N-max(a))

Measured memory_bytes: 76092
# AtCoder Beginner Contest 146 - A
# -*- encoding: UTF-8 -*-

s = input()
result = 0
week = ["MON","TUE","WED","THU","FRI","SAT","SUN"]

if s == "SUN" :
  result = 7
else:
  idx = week.index(s)
  result = 6 - idx
  
print(result)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {

  

    ios::sync_with_stdio(0);
    cin.tie(0);

    ll n;
    int m;
    cin >> n >> m;
    int a[m], sum = 0;
    rep(i, 0, m) cin >> a[i];
    rep(i, 0, m) sum += a[i];
    if (n >= sum)
        cout << n - sum << endl;
    else
        cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;

#define sz(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
///////////////////////

int h, w, n;
ll ans[10];

map<pii, int> d;

void add(int y, int x){
	rep(dy, -2, 1) rep(dx, -2, 1){
		int ny = y + dy;
		int nx = x + dx;
		if(ny <= 0 || ny > h) continue;
		if(nx <= 0 || nx > w) continue;
		if(ny + 2 > h) continue;
		if(nx + 2 > w) continue;
		if(d.find(mp(ny, nx)) == d.end()){
			--ans[0];
			++ans[1];
			d[mp(ny, nx)] = 1;
		}else{
			int bef = d[mp(ny, nx)];
			--ans[bef];
			++ans[bef+1];
			d[mp(ny, nx)] += 1;
		}
	}
}

void solve(){
	cin >> h >> w >> n;
	ans[0] = (h-2) * 1LL * (w-2);
	rep(i, 0, n){
		int y, x;
		cin >> y >> x;
		add(y, x);
	}

	rep(i, 0, 10) cout << ans[i] << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

Measured memory_bytes: 56448
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long

int main(){
	ll N,A;
  	cin >> N >> A;
  	ll ans=0;
  	for(ll i =0;i<N;i++){
		ll inp; cin >> inp;
      	ans += min(inp, A-inp);
    }
  	
	cout << 2*ans << endl;
}

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

int main() {
  string s;
  REP(i,3) { cin >> s; cout << char(s[0]-'a'+'A'); }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<string>
#include<sstream>
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<ios>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<type_traits>
#include<random>
#include<vector>
#include<map>

using namespace std;

	

int main()
{
	int A,B;
	cin >>A>>B;
	if(A+B>2*A-1 and A+B>2*B-1)
	{
		cout << A+B << endl;
	}
	else if(2*B-1>2*A-1)
	{
		cout << 2*B-1 << endl;
	}
	else
	{
		cout << 2*A-1 << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (ll i = 0; i < n; i++)
    {
        cin >> b[i];
    }

    ll sum = 0;
    for (ll i = 0; i < n; i++)
    {
        ll tmp = a[i] - b[i];
        if (tmp >= 0)
        {
            sum += tmp;
        }
        else
        {
            sum += (tmp / 2);
        }
    }

    if (sum > 0)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 384
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
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};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m;
    cout << (n-1)*(m-1) << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector <ll> vec(n);
  rep(i, n) cin >> vec[i];
  sort(vec.begin(), vec.end());
  for (int i = 1; i < n; ++i) {
    if (vec[i] == vec[i-1]) {
      cout << "NO" << '\n';
      return 0;
    }
  }
  cout << "YES" << '\n';
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		String S = reader.next();
		String str = "abcdefghijklmnopqrstuvwxyz";
		String ans = "None";
		for (int i = 0; i < S.length(); i++) {
			char ch = S.charAt(i);
			str = str.replace(Character.toString(ch), "");
		}
		if (str.length() > 0) {
			ans = Character.toString(str.charAt(0));
		}

		System.out.println(ans);
		reader.close();
	}


}





Measured memory_bytes: 58796
N, M = map(int, input().split())
l_list =list()
r_list = list()
for i in range(M):
    l, r = map(int, input().split())
    l_list.append(l)
    r_list.append(r)

ans = 0
for i in range(max(l_list), min(r_list)+1):
    ans += 1
print(ans)

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

int main(){
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for(int i = 0; i < m; i++) cin >> b[i];
    int ans = 0;
    for(int i = 0; i < n; i++){
        int coans = 0;
        for(int j = 0; j < m; j++){
            int a;
            cin >> a;
            coans += a*b[j];
        }
        coans += c;
        if(coans > 0) ans++;
    }

    cout << ans << endl;
    return 0;
}

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

int main() {
  int N;
  char C;
  bool Y = false;
  cin >> N;
  for (;N>0;N--) {
    cin >> C;
    if (C=='Y')
      Y = true;
  }
  if (Y==true)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;
}

Measured memory_bytes: 256
// ＡＢＣのＡ過去問を解くだけだよ

// フォント:Electroharmonix
// x:小文字(ｘ)    X:大文字(Ｘ)
// +:プラス(＋)    &:アンド(＆)

#include <bits/stdc++.h>

using namespace std;

void Main()
{
    int R;
    cin >> R;

    if (R < 1200)
        cout << "ABC";
    else if (R < 2800)
        cout << "ARC";
    else
        cout << "AGC";
}

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

    //std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
    {
        Main();
        cout << std::endl;
    }
#endif

    Main();
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		if(a==b) System.out.println(a+b);
		else System.out.println((Math.max(a,b)*2)-1);

	}

}


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

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

    for (int i = 0; i <= N; i++) {
        for (int j = i; j <= N; j++) {
            int a = i, b = j - i, c = N - i - (j-i);
            int s = 10000 * a + 5000 * b + 1000 * c;
            if (s == Y) {
                cout << a << " " << b << " " << c << endl;
                return 0;
            }
        }
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define vi vector<int>
#define vull vector<ull>
#define vll vector<ll>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define si set<int>
#define sll set<ll>
#define ins insert
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define db double
using namespace std;
struct interval{
	db x,y;
};
db calc(int p[],int n,interval a[]){
	db ans=0;
	rep(i,n-1){
	ans+=sqrt((a[p[i]].x-a[p[i+1]].x)*(a[p[i]].x-a[p[i+1]].x)+((a[p[i]].y-a[p[i+1]].y)*(a[p[i]].y-a[p[i+1]].y)));	
	}
	return ans;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	int p[n];
	rep(i,n){
		p[i]=i;
	}
	interval a[n];
	rep(i,n){
		cin>>a[i].x>>a[i].y;
	}
	db ans=0;
	int cnt=0;
	do { 
        ans+=calc(p, n,a); 
        cnt++;
    } while (next_permutation(p, p + n)); 
	cout<<setprecision(10)<<ans/cnt;
	return 0;
}

Measured memory_bytes: 256
// 課題5_3 AtCoder Beginner Contest 107 B - Grid Compression
// nk777
 
#include<stdio.h>
#define LIM 100

int main(void){
    // H行line,W列col,,for文のカウンタi,j,黒がある行と列を記憶する配列lineBlack,colBlack(初期値0)
    int line, col, i, j, lineBlack[LIM+1] = {0}, colBlack[LIM+1] = {0};
    // 入力格納2次元配列matrix
    char matrix[LIM+1][LIM+1];

    // line, colを受け取る
    scanf("%d %d", &line, &col);
    

    for (i = 0; i < line; i++)
    {
        for (j = 0; j < col; j++)
        {
            // 入力されるマス目の色を受け取る
            scanf(" %c", &matrix[i][j]);
            // もし黒だったら
            if (matrix[i][j] == '#')
            {
                // 黒があることを記録
                lineBlack[i] = 1;
                colBlack[j] = 1;
            } 
        }
    }

    // 黒が一つでもある行と列を出力
    for (i = 0; i < line; i++)
    {
        if (lineBlack[i] == 1)
        {
           for (j = 0; j < col; j++)
           {
               if (colBlack[j] == 1)
               {
                    // 行も列も黒があるときだけ表示
                    printf("%c", matrix[i][j]);
               }
           }

            // 1行終わるごとに改行する
            printf("\n");
        }
    }
    
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	for(int i = 0; i < N; i++) {
		int n,k;
		cin >> n >> k;
		int px = -1;
		vector<int> dx;
		for(int j = 0; j < n; j++) {
			int x;
			cin >> x;
			if(px != -1) {
				dx.push_back(x - px);
			}
			px = x;
		}
		if(n <= k) {
			cout << 0 << endl;
		} else {
			sort(dx.begin(), dx.end());
			int s = 0;
			for(int j = 0; j < n-k; j++) s += dx[j];
			cout << s << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1864
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;


    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            
            int n,i,j;
            cin>>n;
            ll ar[n+1],x;
            for(i=1;i<=n;++i)
                cin>>ar[i];
            vector<ll> v;
            int q;
            for(i=1;i<=n;++i)
            {
                v.pb(ar[i]);
                q=v.size();
                while(q>2 && v[q-2]>=v[q-1] && v[q-2]>=v[q-3])
                {
                    //cout<<q<<endl;
                    x=v[q-3]+v[q-1]-v[q-2];
                    v.pop_back();
                    v.pop_back();
                    v.pop_back();
                    v.pb(x);
                    q=v.size();
                }
            }

            ll ans=0;
            int l=0,r=v.size()-1,flag=1;
            while(l<=r)
            {
                if(v[l]>v[r])
                {
                    ans=ans+flag*v[l];
                    ++l;
                }
                else
                {
                    ans=ans+flag*v[r];
                    --r;
                }
                flag=flag*-1;
            }
            cout<<ans<<endl;
        }
        return 0;
    }


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

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define lp(start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll n,k;
	cin >> n >> k;
	ll arr[n+1];
	for(ll i=1;i<=n;i++)
		cin >> arr[i];
	sort(arr+1,arr+1+n);
	ll ans=0;
	for(ll i=1;i<=k;i++)
		ans+=arr[i];
	cout << ans << endl;
	return 0;	
}


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

#define ll long long
#define ull unsigned ll

#define vi vector <int>
#define ii pair <int, int>
#define vii vector <ii>
#define INFLL 9e18
#define INF 2e9
#define EPS 1e-9
#define pb push_back
#define emp emplace_back
#define PI acos(-1.0)
#define endl "\n"
#define mp make_pair
#define DEBUG 0

int main ()

{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;

    if (k <= a) cout << k << endl;
    else if (k > a && k <= a+b) cout << a << endl;
    else cout << a - (k- a- b) << endl;
          

    return 0;
}

Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        int ans = 0;
        for (int i = 0; i < N; i++) {
            int h = scan.nextInt();
            if (K <= h) {
                ans += 1;
            }
        }
        System.out.println(ans);
    }
}


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

int main(){
    int n,l;
    cin>>n>>l;
    vector<string> s;
    for(int i=0;i<n;i++){
        string str;
        cin>>str;
        s.push_back(str);
    }
    sort(s.begin(),s.end());
    string ans("");
    for(int i=0;i<n;i++){
        ans+=s[i];
    }
    cout<<ans<<endl;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
using ll = long long;
const static ll MOD = 1e9 + 7;

int main() {
    ll a, b;
	cin >> a >> b;
    MSG(max(max(a+b, a-b), a*b))
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int maxn=2e5+5;
inline int read()
{
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+c-'0';c=getchar();}
	return t*f;
}
int n,c[maxn],t[maxn],cnt;
int ksm(int a,int b){
	int ans=1;
	while(b>0){
		if(b&1)ans=1ll*ans*a%mod;
		a=1ll*a*a%mod;b>>=1;
	}
	return ans;
}
int last[maxn],f[maxn];
int main()
{
	n=read();
	for(int i=1;i<=n;i++)c[i]=read();
	for(int i=1;i<=n;i++){
		if(c[i]!=c[i-1])t[++cnt]=c[i];
	}
	f[0]=1;
	for(int i=1;i<=cnt;i++){
		f[i]=f[i-1];
		if(last[t[i]]!=0){
			f[i]=(f[i]+f[last[t[i]]])%mod;
		}
		last[t[i]]=i;
	}
	printf("%d\n",f[cnt]);
	return 0;
}


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

struct Item{
  int v,w;
};

int main() {
  int W;    
  Item item[1001];
  int dp[1001][1001];
  int cnt = 0;
  while( cin >> W , W ) {
    int n; cin >> n;
    char ch;

    for ( int i = 0; i <= n; i++ ) {
      for ( int j = 0; j <= W; j++ ) dp[i][j] = 0;
    }

    for ( int i = 1; i <= n; i++ ) {
      cin >> item[i].v >> ch >> item[i].w;
    }

    for ( int i = 1; i <= n; i++ ) {
      for ( int j = 1; j <= W; j++ ) {
	if ( item[i].w <= j ) {
	  if ( item[i].v + dp[i-1][ j - item[i].w ] > dp[i-1][j] ) 
	    dp[i][j] = item[i].v + dp[i-1][ j - item[i].w ];
	  else dp[i][j] = dp[i-1][j];
	}else dp[i][j] = dp[i-1][j];
      }
    }
    
    /* for ( int i = 1; i <= n; i++ ) {
      for ( int j = 1; j <= W; j++ ) {
	cout << dp[i][j] << " ";
      }
      cout << endl;
    }
    */
    cnt++;
    cout << "Case" << " " << cnt << ":" << endl;
    cout << dp[n][W] << endl;
    for ( int i = 0; i <= W; i++ ) {
      if ( dp[n][i] == dp[n][W] ) {
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}

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

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, k, n){
        if(a[i-k] < a[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define rd(x) cin >> x;
#define rda(a,n) for(int i=1;i<=n;i++) cin >> a[i];
#define wr(x) cout << x << ' ';
#define wrl(x) cout << x << '\n';
#define wra(a,n) for(int i=1;i<=n;i++) cout << a[i] << ' '; cout << '\n';
#define lg length()
#define pb(x) push_back(x)
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
struct comp{
    bool operator()(long long a, long long b){
        return a>b;
    }
};

long long n,m,ans,mod=1e9+7;

int main(){
    ios_base :: sync_with_stdio(0);
    cin >> n >> m;
    if(abs(n-m)<=1){
        if(!abs(n-m)) ans=2;
        else ans=1;
        for(int i=1;i<=n;i++){
            ans*=i;
            ans%=mod;
        }
        for(int i=1;i<=m;i++){
            ans*=i;
            ans%=mod;
        }
    }
    cout << ans;
}


Measured memory_bytes: 256