akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
#define repd(i,a,b) for (int i=a;i<int(b);i++)
#define rep(i,n) repd(i,0,n)
#define VARNAME(v) #v
using P = pair<int,int>;


int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  constexpr int BEAM = 550;
  int d;vector<int> c(26);cin>>d;rep(i,26)cin>>c[i];
  vector<array<int, 26>> s(d);
  rep(i,d)rep(j,26)cin>>s[i][j];
  vector<int> curs = {0};
  vector<array<int, 26>> curl(1);
  vector<vector<int>> cura(1);
  rep(i,d){
    int len = int(curs.size()) * 26, ind = 0;
    vector<P> nxs(len);
    vector<array<int, 26>> nxl(len);
    vector<vector<int>> nxa(len);
    rep(j, curs.size()){
      rep(t, 26){
        int score = curs[j];
        array<int, 26> last = curl[j];
        vector<int> ans = cura[j];
        score += s[i][t];
        last[t] = i+1;
        rep(k,26)score -= c[k]*(i+1 - last[k]);
        ans.emplace_back(t);
        nxs[ind] = P(score, ind);
        nxl[ind] = last;
        nxa[ind] = ans;
        ind++;
      }
    }
    sort(nxs.rbegin(), nxs.rend());
    len = min(len, BEAM);
    curs.resize(len);curl.resize(len);cura.resize(len);
    rep(j,len){
      curs[j] = nxs[j].first;
      curl[j] = nxl[nxs[j].second];
      cura[j] = nxa[nxs[j].second];
    }
  }
  int ans = 0;
  rep(i,min(int(curs.size()), BEAM)){
    if(curs[ans] < curs[i])ans = i;
  }

  for(auto x : cura[ans]){
    cout << x+1 << endl;
  }
}


Measured memory_bytes: 27044
col = {}
N, K = [int(i) for i in input().split()]
for _ in range(N):
	a_i, b_i = [int(i) for i in input().split()]
	if not a_i in col:
		col[a_i] = b_i
	else:
		col[a_i] += b_i

count = 0
for i in sorted(col.items()):
	count += i[1]
	if count >= K:
		print(i[0])
		break

Measured memory_bytes: 14556
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	String s = sc.next();
    	int[] cnt = new int[2];
    	
    	for( int i = 0; i < N; i++ ) {
    		if( s.charAt(i) == 'R' ) {
    			cnt[0]++;
    		}
    		else {
    			cnt[1]++;
    		}
    	}
    	
    	if( cnt[0] > cnt[1] ) {
    		System.out.println( "Yes" );
    	}
    	else {
    		System.out.println( "No" );
    	}
    	
    	sc.close();
    }
}

Measured memory_bytes: 21716
import std.stdio;
import std.string;
import std.conv;
import std.bigint;
import std.typecons;
import std.algorithm;
import std.array;
import std.math;
import std.range;
 
void main() {
    auto N = readln.chomp.to!int;
    auto K = readln.chomp.to!int;
    auto x = 1;
    foreach (i; 0..N) {
        if (x < K) x *= 2;
        else x += K;
    }
    writeln(x);
}


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

using namespace std;


void solve() {
    int N, M; cin >> N >> M;
    vector<int> A(N, -1);

    for (int i = 0; i < M; i++) {
        int s, c; cin >> s >> c;
        s--;
        if (A[s] == -1 || A[s] == c) A[s] = c;
        else {
            cout << -1 << endl;
            return;
        }
    }

    if (N == 1 && (A[0] == -1 || A[0] == 0)) {
        cout << 0 << endl;
        return;
    }

    if (A[0] == 0) {
        cout << -1 << endl;
        return;
    }
 
    if (A[0] == -1) A[0] = 1;
    for (int i = 1; i < N; i++) {
        if (A[i] == -1) A[i] = 0;
    }

    for (int i = 0; i < N; i++) {
        cout << A[i];
    }
    cout << endl;
}


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

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

    ll ret = n-1;
    for(ll i=1; i*i<=n; ++i) {
        if(n%i==0) {
            chmin(ret, i+n/i-2);
        }
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long LL;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
const int N=110;
int h[N][N],u[N][N];
int f[N][N][N],g[N][N][N];
inline void upd(int &x,int y) { x<y?x=y:0; }
int main()
{
	int n=gi(),m=gi(),i,j,x,y,lx,rx,ly,ry,t;
	char c;
	for (i=1;i<=n;i++)
		for (j=1;j<=m;j++) {
			h[i][j]=h[i][j-1];u[i][j]=u[i-1][j];
			while ((c=getchar())!='.'&&c!='E'&&c!='o');
			if (c=='E') x=i,y=j;
			else if (c=='o') h[i][j]++,u[i][j]++;
		}
	for (lx=0;lx<x;lx++) {
		memcpy(g,f,sizeof(g));
		memset(f,0,sizeof(f));
		for (rx=0;rx<=n-x;rx++)
			for (ly=0;ly<y;ly++)
				for (ry=0;ry<=m-y;ry++) {
					t=g[rx][ly][ry];
					upd(f[rx][ly][ry],t+(x-lx-1>rx?h[x-lx-1][min(y+ry,m-ly)]-h[x-lx-1][max(y-ly-1,ry)]:0));
					upd(g[rx+1][ly][ry],t+(x+rx+1<=n-lx?h[x+rx+1][min(y+ry,m-ly)]-h[x+rx+1][max(y-ly-1,ry)]:0));
					upd(g[rx][ly+1][ry],t+(y-ly-1>ry?u[min(x+rx,n-lx)][y-ly-1]-u[max(x-lx-1,rx)][y-ly-1]:0));
					upd(g[rx][ly][ry+1],t+(y+ry+1<=m-ly?u[min(x+rx,n-lx)][y+ry+1]-u[max(x-lx-1,rx)][y+ry+1]:0));
				}
	}
	printf("%d\n",g[n-x][y-1][m-y]);
	return 0;
}


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

using namespace std;

static const int MMAX = 20;
static const int NMAX = 50000;
static const int INFTY = (1<<29);

int main(){
  int n, m;
  int C[MMAX + 1];
  int T[NMAX + 1];
  
  cin >> n >> m;

  for(int i = 1; i <= m; i++){
    cin >> C[i];
  }

  for(int i = 0; i <= NMAX; i++) T[i] = INFTY;
  T[0] = 0;
  for(int i = 1; i <= m; i++){
    for(int j = 0; j + C[i] <= n; j++){
      T[j + C[i]] = min(T[j + C[i]], T[j] + 1);
    }
  }

  cout << T[n] << endl;

  return 0;
}

Measured memory_bytes: 1356
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_RC = 3005;
ll val[MAX_RC][MAX_RC];
ll dp[MAX_RC][MAX_RC][4];

int main()
{
	int R,C,K;
	cin >> R >> C >> K;
	rep(i,K)
	{
		int r,c;
		ll v;
		cin >> r >> c >> v;
		r--; c--;
		val[r][c] = v;
	}
	dp[0][0][0] = 0;
	dp[0][0][1] = val[0][0];
	rep(i,MAX_RC)
	{
		rep(j,MAX_RC)
		{
			if (i+1 < R && j < C)
			{
				rep(k,4)
				{
					dp[i+1][j][0] = max(dp[i+1][j][0],dp[i][j][k]);
				}
				dp[i+1][j][1] =  dp[i+1][j][0] + val[i+1][j];
			}
			if (i < R && j+1 < C)
			{
				rep(k,4)
				{
					dp[i][j+1][k] = max(dp[i][j+1][k],dp[i][j][k]);
				}
				rep(k,3)
				{
					dp[i][j+1][k+1] = max(dp[i][j+1][k+1],dp[i][j][k]+val[i][j+1]);
				}
			}
		}
	}
	ll ans = dp[R-1][C-1][0];
	rep(i,3)
	{
		ans = max(ans,dp[R-1][C-1][i+1]);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  int n;
  cin >> n;
  int dp[n+1][n+1];
  rep(i, 1, n+1) dp[i][i] = 0;
  int p[n+1];
  rep(i, 0, n) cin >> p[i] >> p[i+1];
  
  rep(l, 2, n+1) {
    rep(i, 1, n-l+2) {
      int j = i+l-1;
      dp[i][j] = 1000000007;
      rep(k, i, j) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j]);
      }
    }
  }
  
  cout << dp[1][n] << "\n";
}


Measured memory_bytes: 3164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			int num_case = Integer.parseInt(br.readLine());
			boolean table[] = new boolean[3];

			for(int loop = 0; loop < num_case; loop++){

				int ans = 0,num_out = 0;
				for(int i = 0; i < 3; i++){

					table[i] = false;
				}

				while(num_out < 3){

					String event = br.readLine();

					switch(event){
					case "HIT":

						if(table[2]){
							ans += 1;
						}
						table[2] = table[1];
						table[1] = table[0];
						table[0] = true;
						break;

					case "HOMERUN":

						ans += 1;

						for(int i = 0; i < 3; i++){
							if(table[i]){
								ans += 1;
								table[i] = false;
							}
						}
						break;

					case "OUT":
						num_out += 1;
						break;
					}
				}

				System.out.println(ans);
			}

		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string x;
    cin >> x;
    int sum = 0;
    rep(i, x.size()) sum += x[i] - '0';

    if (stoi(x) % sum == 0)
        OP("Yes");
    else
        OP("No");
    return 0;
}

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

const int mod = 1e9 + 7;

string s[1002];
int dp[1002][1002];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

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

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

    // for the base case.
    // reaching the first block ways = 1;

    dp[0][0] = 1;

    for(int i = 0; i<h; i++){
        for(int j = 0; j<w; j++){
            if(s[i][j] == '#')
            {
                dp[i][j] = 0;
                continue;
            }

            if(i > 0)
                dp[i][j] += dp[i-1][j];
            dp[i][j] %= mod;
            if(j > 0)
                dp[i][j] += dp[i][j-1];
            dp[i][j] %= mod;
        }
    }

    cout<<dp[h-1][w-1]<<endl; 
    

    return 0;
}


Measured memory_bytes: 8636
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    for (i in 1..N) {
        val a = Array(10) { sc.nextInt() }
        val container = arrayOf(0, 0)
        var flag = true
        for (n in a) {
            if (container[0] < n) container[0] = n
            else if (container[1] < n) container[1] = n
            else { flag = false; println("NO"); break }
            container.sortDescending()
        }
        if (flag) println("YES")
    }
}


Measured memory_bytes: 29184
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    string S;
    cin >> S;
    string days[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    int ans = -1;
    REP(i, 7){
        if(S==days[i]){
            ans = 7 - i;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;
#define ALL(x)			(x).begin(),(x).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF				(int)2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))	
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)	
#define FloorN(x, n)	((x)-(x)%(n))			
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long			ll;
typedef unsigned long long	ull;
typedef pair<ll, ll>		P;
typedef vector<ll>			VLL;
typedef vector<VLL>			VVLL;
typedef vector<VVLL>		VVVLL;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	vector<int> p(N);
	REP(i, N) cin >> p[i];

	int swapCnt = 0;
	REP(i, N) {
		if (p[i] == i + 1) {
			int swapIdx;
			if (0 == i) {
				swapIdx = i + 1;
			} else if (N - 1 == i) {
				swapIdx = i - 1;
			} else {
				swapIdx = i + 1;
			}
			swap(p[i], p[swapIdx]);
			swapCnt++;
		}
	}
	cout << swapCnt << endl;
	return 0;
}


Measured memory_bytes: 640
def main():
    N = int(input())
    M = N // 7
    if N % 7 ==  0:
        print("Yes")
        return
    for i in range(M + 1):
        if (N - (7 * i)) % 4 == 0:
            print("Yes")
            return
    print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
def divisor(n):
    ass = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass
 
 
 
n = int(input())
l = sorted(divisor(n))
if len(l) % 2 == 1:
    print(l[(len(l) // 2)] * 2 - 2)
else:
    print(l[(len(l)//2 - 1)] + l[(len(l)//2)] - 2)

Measured memory_bytes: 3296
n, l = map(int, input().split())
S = n*l + (n * (n + 1)) // 2 - n
pd = S + 1
for x in range(1, n + 1):
    d = - l - x + 1
    if pd > abs(d):
        ans = S + d
    pd = d

print(ans)


Measured memory_bytes: 9100
#include<stdio.h>
#define N 100
#define INF 1000
#define WHITE 0
#define GRAY 1
#define BLACK 2
void init(void);
void print(void);
void bfs(void);
int n, graph[N][N], d[N];

int main() {
	int i, j, l, m, in;

	init();

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &l, &m);
		for (j = 0; j < m; j++) {
			scanf("%d", &in);
			graph[l - 1][in - 1] = 1;
		}
	}

	bfs();
	print();

	return 0;
}
void bfs(void) {
	int i, v;
	int head, tail, que[N*N], color[N];

	head = -1;
	tail = 1;
	for (i = 0; i < n; i++) {
		d[i] = INF;
		color[i] = WHITE;
	}
	color[0] = GRAY;
	que[++head] = 0;
	d[0] = 0;

	while (head != tail) {
		v = que[head++];
		for (i = 0; i < n; i++) {
			if (graph[v][i] == 1 && color[i] == WHITE) {
				color[i] = GRAY;
				que[tail++] = i;
				d[i] = d[v] + 1;
			}
		}
		color[v] = BLACK;
	}
}
void init(void) {
	int i, j;

	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			graph[i][j] = 0;
		}
	}
	return ;
}
void print(void) {
	int i;
	for (i = 0; i < n; i++) {
		printf("%d ", i + 1);
		if (d[i] == INF) printf("-1\n");
		else			 printf("%d\n", d[i]);
	}
	return ;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
        ll n;
        scanf("%ld", &n);
        char s[n+1];
        scanf("%s", s);

        std::vector<ll> r(n+1, 0), g(n+1, 0), b(n+1, 0);

        for(ll i=0; i<n; i++){
                if(s[i]=='R') r[i+1]++;
                if(s[i]=='G') g[i+1]++;
                if(s[i]=='B') b[i+1]++;
        }
        for(ll i=0; i<n; i++){
                r[i+1] += r[i];
                g[i+1] += g[i];
                b[i+1] += b[i];
        }

        ll ans = 0;
        for(ll i=0; i<n; i++){
                if(s[i]=='R'){
                        ll tmp = g[i] * (b[n]-b[i+1]) + (g[n]-g[i+1]) * b[i];
                        for(ll j=1; i+j<n && i-j>=0; j++){
                                if(s[i-j]=='G' and s[i+j]=='B' or s[i-j]=='B' and s[i+j]=='G') tmp--;
                        }
                        ans += tmp;
                }
                if(s[i]=='G'){
                        ll tmp = r[i] * (b[n]-b[i+1]) + (r[n]-r[i+1]) * b[i];
                        for(ll j=1; i+j<n && i-j>=0; j++){
                                if(s[i-j]=='R' and s[i+j]=='B' or s[i-j]=='B' and s[i+j]=='R') tmp--;
                        }
                        ans += tmp;
                }
                if(s[i]=='B'){
                        ll tmp = g[i] * (r[n]-r[i+1]) + (g[n]-g[i+1]) * r[i];
                        for(ll j=1; i+j<n && i-j>=0; j++){
                                if(s[i-j]=='G' and s[i+j]=='R' or s[i-j]=='R' and s[i+j]=='G') tmp--;
                        }
                        ans += tmp;
                }
        }

        printf("%ld\n", ans);
        return 0;
}


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

using namespace std;
using ll = long long;

ll sum(ll n) {
    ll ret = 0;
    while (n > 0) {
        ll t = n % 10;
        ret += t;
        n /= 10;
    }
    return ret;
}

int main() {
    ll n;
    cin >> n;
    ll ans = (ll)9e9;
    for (ll a = 1; a < n; a++) {
        ll b = n - a;
        ans = min(ans, sum(a) + sum(b));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
main() {
  int n, m, i, j;
  char a, t[100];
 
  while(1) {
    scanf("%d", &n);
    if(n==0) break;
     
    for(i=0 ; i<n*2 ; i++) {
      scanf(" %c", &t[i]);
    }
     
    scanf("%d", &m);
    for(i=0 ; i<m ; i++) {
      scanf(" %c", &a);
      for(j=0 ; j<n*2 ; j+=2) {
    if(a == t[j]) {
      a = t[j+1];
      break;
    }
      }
      printf("%c", a);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int a[100][100];
int b[100][100];
bool dp[100][100][20000];

int main(){
    int h, w;
    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];

    dp[0][0][abs(a[0][0] - b[0][0])] = true;

    rep(i, h){
        rep(j, w){
            rep(k, 20000){
                if (dp[i][j][k]){
                    dp[i+1][j][abs(k + a[i+1][j] - b[i+1][j])] = true;
                    dp[i+1][j][abs(k + b[i+1][j] - a[i+1][j])] = true;
                    dp[i][j+1][abs(k + a[i][j+1] - b[i][j+1])] = true;
                    dp[i][j+1][abs(k + b[i][j+1] - a[i][j+1])] = true;
                }
            }
        }
    }
    int ans = 20000;
    rrep(k, 20000) if (dp[h-1][w-1][k]) ans = min(ans, k);

    cout << ans << endl;

    return 0;
}


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

int main() {
  int N, X; cin >> N >> X;
  int x = X, L = 0;
  while (x > 0) {
    x >>= 1;
    L += 1;
  }
  L = 1<<L;
  vector< vector<int>> dp0(L, vector<int>(X+1, 0));
  vector< vector<int>> dp1(L, vector<int>(X+1, 0));
  int mod = 998244353;
  for (int i = 0; i <= X; i++) {
    dp0[i][i] = 1;
  }
  for (int i = 0; i < N-1; i++) {
    for (int j = 0; j < L; j++) {
      for (int k = 0; k < X; k++)
        dp0[j][k+1] = (dp0[j][k+1]+dp0[j][k])%mod;
    }
    for (int j = 0; j < L; j++) {
      for (int k = 0; k <= X; k++)
        dp1[j][k] = dp0[j^k][k];
    }
    dp0 = dp1;
  }
  long long ans = 0;
  for (int i = 0; i <= X; i++) {
    ans = (ans+dp0[X][i])%mod;
  }
  cout << ans % mod << endl;
}



Measured memory_bytes: 5000
from collections import Counter
n = int(input())
ar = list(map(int, input().split()))

t = int(input())
c = Counter(ar)
s = sum(ar)
for i in range(t):
    a, b = list(map(int, input().split()))
    if b in c:
        c[b] += c[a]
    else:
        c[b] = c[a]
    s += ((b-a)*c[a])
    print(s)
    c[a] = 0


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

#define MAX_V 210

//// bipartite match
int V;
multiset<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void init(int v){
  V=v;
  for(int i=0;i<V;i++)G[i].clear();
}

void add_edge(int u,int v){
  //printf("%d <=> %d\n", u,v);
  G[u].insert(v);
  G[v].insert(u);
}

void rem_edge(int u,int v){
  //printf("%d <=> %d\n", u,v);
  G[u].erase(G[u].find(v));
  G[v].erase(G[v].find(u));
}

bool dfs(int v){
  used[v]=true;
  for(int u : G[v]){
    int w=match[u];
    if(w<0||(!used[w]&&dfs(w))){
      match[v]=u;
      match[u]=v;
      return true;
    }
  }
  return false;
}

int bipartite_match(){
  int res=0;
  memset(match,-1,sizeof(match));
  for(int v=0; v<V;v++){
    if(match[v]<0){
      memset(used,0,sizeof(used));
      if(dfs(v))res++;
    }
  }
  return res;
}

int N,M;
vector<vector<int>> A;

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

  cin>>N>>M;
  vector<vector<vector<int>>> nums(N,vector<vector<int>>(N,vector<int>()));
  rep(i,N){
    vector<int> tmp(M);
    rep(j,M){
      cin>>tmp[j];
      tmp[j]--;
    }
    A.push_back(tmp);
  }

  init(2*N);
  rep(i,N){
    rep(j,M){
      nums[i][(A[i][j]/M)].push_back(A[i][j]);
      add_edge(i,(A[i][j]/M)+N);
    }
  }

  vector<vector<int>> resa(N,vector<int>(M,-1));
  rep(k,M){
    bipartite_match();
    rep(u,N){
      int v=match[u]-N;
      //dbg(u); dbg(v);
      int num=nums[u][v].back();
      nums[u][v].pop_back();
      resa[u][k]=num+1;
      rem_edge(u,v+N);
    }
  }

  vector<vector<int>> resb(N,vector<int>(M,-1));
  rep(j,M){
    vector<int> tmp;
    rep(i,N)tmp.push_back(resa[i][j]);
    sort(all(tmp));
    rep(i,N)resb[i][j]=tmp[i];
  }

  rep(i,N){
    rep(j,M)cout<<resa[i][j]<<" ";
    cout<<endl;
  }
  rep(i,N){
    rep(j,M)cout<<resb[i][j]<<" ";
    cout<<endl;
  }

  return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
using namespace std;

int main(){
 long long a,b; cin>>a>>b;
 if((a+b) %2 == 0) cout<<(a+b)/2<<endl;
 else cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 764
N,K = map(int,input().split())
A = list(map(int,input().split()))
X = 10**9+7
count_self=0
for i,a in enumerate(A):
    j=N-1
    while i<j:
        if a>A[j]:
            count_self+=1
        j-=1
num = [0]*2000
for a in A:
    num[a-1]+=1
count=0
a=0
for n in num:
    if n != 0:
        if a == 0:
            a=n
        else:
            count = count + n*a
            a+=n
print((count_self*K + count*K*(K-1)//2)%X)

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


int main(){
    int n, m, l;
    long long t1[100][100], t2[100][100], t3[100][100];

    cin >> n >> m >> l;

    for (int i = 0; i < n; i++)
        for (int j =0; j < m; j++) cin >> t1[i][j];

    for (int i = 0; i < m; i++)
        for (int j =0; j < l; j++) cin >> t2[i][j]; 

    for (int i = 0; i < n; i++){
        for (int j = 0; j < l; j++){
            t3[i][j] = 0;
            for (int k = 0; k < m; k++){
                t3[i][j] += t1[i][k] * t2[k][j];
            }
        }   
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++){
            if (j) cout << " ";
            cout << t3[i][j];
        }
        cout << endl;
    }
   
}



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

using namespace std;

int main() {
    int n , q ; cin>>n>>q;
    string s; cin>>s;
    int dp[10000000] = {0};
    for(int i = 0 ; i < n; ++i){
        string x = "";
        x += s[i]; x+= s[i + 1];
        dp[i+1] = dp[i] + ((x == "AC")?1 : 0);
    }
    for(;q--;){
        int l , r ; cin>>l>>r;
        cout<<dp[r - 1] - dp[l - 1]<<endl;
    }
}


Measured memory_bytes: 40064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.stream.LongStream;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int n = ni();
        long x = nl();
        long[] a = nla(n);

        long[] before = Arrays.copyOf(a, a.length);
        long ans = LongStream.of(a).sum();

        for (int i = 1; i < n; i++) {
            long[] after = new long[n];
            for (int j = 0; j < n; j++) {
                after[j] = Math.min(before[j], a[(j - i + n) % n]);
            }
            ans = Math.min(ans, LongStream.of(after).sum() + i * x);

            before = after;
        }

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

#define deb(x) cout << #x << " " << x << "\n";
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)
#define endl "\n"
#define ll long long
#define vi vector<int>

// memset(arr, value, size);

int t, i, arr[200000 + 20], a[1000000 + 20];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> t;

	Fo(i, 1, t + 1) {
		cin >> arr[i];
	}

	sort(arr + 1, arr + t + 1);

	Fo(i, 1, t + 1) {
		if (arr[i] == arr[i - 1])
			a[arr[i]] = 1;
	}
	int count = 0;
	Fo(i, 1, t + 1) {
		if (!a[arr[i]])
			count++;
		if (arr[i] != arr[i - 1]) {
			for (int j = arr[i] * 2; j <= 1000000; j += arr[i])
				a[j] = 1;
		}
	}

	cout <<  count;

	return 0;
}

Measured memory_bytes: 8280
fn main() {
    proconio::input! {
        q: usize,
        lr: [(usize,usize);q],
    }
    let m=lr.iter().map(|lr|lr.1).max().unwrap()+1;
    let mut p=vec![true;m];
    p[0]=false;
    p[1]=false;
    for i in 2..m/2 {
        if p[i] {
            for p in p[i*2..].iter_mut().step_by(i) {
                *p=false;
            }
        }
    }
    let mut s=vec![0;m];
    for i in 2..m {
        s[i]=s[i-1]+if p[i]&&p[(i+1)/2] {1} else {0};
    }
    for (l,r) in lr {
        println!("{}",s[r]-s[l-1]);
    }
}

Measured memory_bytes: 5252
import collections
n=int(input())
S=[ collections.Counter(sorted(list(input()))) for i in range(n) ]
chars=[ chr(i) for i in range(97,97+26) ]
nums=[ min( [S[i][char] for i in range(n)] ) for char in chars ]
ans=''.join([ chars[i]*nums[i] for i in range(26)])
print(ans)

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

using namespace std;

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

  string s;
  cin >> s;
  deque<char> d;
  for (char c : s) {
    d.push_back(c);
  }
  int q;
  cin >> q;
  int rev = 0;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      rev ^= 1;
    } else {
      int f;
      char c;
      cin >> f >> c;
      if (rev) {
        f = 3 - f;
      }
      if (f == 1) {
        d.push_front(c);
      } else {
        d.push_back(c);
      }
    }
  }
  if (rev) {
    reverse(d.begin(), d.end());
  }
  cout << string(d.begin(), d.end());

  return 0;
}

Measured memory_bytes: 1232
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  string s;cin>>s;
  ll n=s.size();
  for(ll i=n-2;i>=0;i-=2){
    //cout<<s.substr(0,i/2)<<" "<<s.substr(i/2)<<endl;
    if(s.substr(0,i/2)==s.substr(i/2,i/2)){
      
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val N, M = sc.nextInt
    val A = Array.fill(M)(sc.nextInt)
    var ans = math.max(A(0) - 1, N - A(M - 1))
    for (i <- Range(1, M)) {
      ans = math.max(ans, (A(i) - A(i - 1)) / 2)
    }
    println(ans)
  }

  def gcd(i: Int, j: Int): Int = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}


Measured memory_bytes: 78848
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define sz 100010
#define BeatMeScanf ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

int const mod = 1e9;

int main()
{
    BeatMeScanf;
    char ch;
    cin>>ch;

    if(ch>=65 && ch<=90) cout<<"A"<<endl;
    else cout<<"a"<<endl;
    return 0;
}


Measured memory_bytes: 3588
s=input()
l=len(s)
def base(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out.rjust(l-1,'0')
ans=0
for i in range(2**(l-1)):
    b=base(i,2)
    p=1
    ans+=int(s[-1])
    for j in range(1,l):
        if b[-j]=="0":
            p*=10
            ans+=int(s[-j-1])*p
        else:
            p=1
            ans+=int(s[-j-1])

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
ll f(ll h,ll tim)
{
	if(h==1)return 1*tim;
	return f(h/2,tim*2)+tim;
}
int main(){
	ll H;scanf("%lld",&H);
	printf("%lld\n",f(H,1));
	return 0;
}


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

int main() {
    int N, Y;
    int total = 0;
    int f = 0;
    int yukichi, higuchi, noguchi;
    cin >> N >> Y;
    for(yukichi = 0; yukichi <= N; ++yukichi) {
        for(higuchi = 0; higuchi <= N - yukichi; ++higuchi) {
            noguchi = N - higuchi - yukichi;
            total = 10000 * yukichi + 5000 * higuchi + 1000 * noguchi;
            if(total == Y) {
                f = 1;
                break;
            }
        }
        if(f == 1) {
            break;
        }
    }
    if(f == 0) {
        yukichi = -1;
        higuchi = -1;
        noguchi = -1;
    }
    cout << yukichi << " " << higuchi << " " << noguchi << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;

int main() {

	long long x, y;
	cin >> x >> y;

	long long v = abs(x) - abs(y);
	v = abs(v);

	if (y * x < 0) {
		v += 1;
	}
	else if (y * x == 0 && y - x < 0) {
		v += 1;
	}
	else if (y - x < 0) {
		v += 2;
	}

	cout << v << endl;

	return 0;
}

Measured memory_bytes: 3588
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int l = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int[] apple = new int[n];
        for (int i = 0; i < n; i++) {
            apple[i] = l + i;
        }

        int min = Integer.MAX_VALUE;
        for (int a : apple) {
            if (min < 0) {
                min = Math.max(min, a);
            } else {
                min = Math.min(min, a);
            }
        }

        int sum = Arrays.stream(apple).sum();
        int result = sum - min;

        // 出力
        System.out.println(result);
    }
}


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

using namespace std;

const int N = 303, S = N * N, mod = 998244353;
int a[N];

int dp[N][S * 2][3];

void add(int & var, int val) {
  var += val;
  if (var >= mod)
    var -= mod;
}

int main() {
  int n;
  scanf("%d", &n);
  dp[0][S][0] = 1;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
    for (int j = 0; j < 2 * S; ++j) {
      for (int k = 0; k < 3; ++k) {
        int now = dp[i][j][k];
        if (now == 0) continue;
        // cerr << i << " " << j-S << " " << k << " = " << now << endl;
        if (j + a[i] < 2 * S) {
          add(dp[i+1][j+a[i]][k], now);
        }
        if (j - a[i] >= 0) {
          if (k == 0)
            add(dp[i+1][j-a[i]][1], now);
          else {
            add(dp[i+1][j-a[i]][k], now);
            add(dp[i+1][j-a[i]][min(k+1, 2)], now);
          }
        }
      }
    }
  }
  int ans = 1;
  for (int i = 0; i < n; ++i)
    ans = (1LL * ans * 3) % mod;
  int sum = 0;
  for (int i = S; i < 2 * S; ++i) {
    int mul = 3;
    for (int k = 0; k <= 2; ++k) {
      if (dp[n][i][k] == 0) continue;
      // cerr << i - S << " " << k << " " << dp[n][i][k] << endl;
      if (k)
        mul = 6;
      if (k == 1 && i == S)
        mul = 3;
      add(sum, 1LL * mul * dp[n][i][k] % mod);
    }
  }
  // cerr << sum << endl;
  ans = (ans - sum) % mod;
  if (ans < 0) ans += mod;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 645376
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>

using namespace std;

long double len(pair<int, int> a, pair<int, int> b) {
    return sqrt((b.first - a.first) * (b.first - a.first) + (b.second - a.second) * (b.second - a.second));
}

int fac(int n) {
    int res = 1;
    for (int i = 1; i <= n; i++)
        res *= i;
    return res;
}

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

    long double sum = 0;
    int n;
    cin >> n;

    vector<pair<int, int>> c(n);
    for (int i = 0; i < n; i++)
        cin >> c[i].first >> c[i].second;

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

    do {
        for (int i = 0; i < n - 1; i++)
            sum += len(c[p[i]], c[p[i + 1]]);
    } while (next_permutation(p.begin(), p.end()));

    cout << fixed << setprecision(20);
    cout << sum / fac(n) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()


void solution(){

	int n, k; cin >> n >> k;
	vector<int> h(n); for(auto& x : h) cin >> x;

	vector<int> dp(n,1e9);

	dp[0] = 0;

	for(int i = 0; i < n; i++){
		for(int x = 1; x <= k; x++){
			if(i + x == n) break;
			dp[i+x] = min(dp[i+x], dp[i] + abs(h[i] - h[i+x]));
		}
	}

	cout << dp[n-1] << endl;



	
}	

int main(){ 

	fio; // fast input output
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// GOOGLE //
		// cout << "Case #" << i << ": ";

		solution();
	} 
	return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

int main(){
	string s;cin>>s;
	
	int s1=0;
	
	if(s[0]=='A'){
		s1=1;
	}
	
	int c=0;
	
	for(int i=2;i<s.length()-1;i++){
		if(s[i]=='C'){
			c++;
		}
	}
	
	if(!(s1&&c==1)){
		cout<<"WA"<<endl;return 0;
	}
	
	int g=0;
	
	for(int i=0;i<s.length();i++){
		if(!(s[i]-'a'>=0&&s[i]-'a'<26)){
			g++;
		}
	}
	
	//cout<<g<<endl;
	
	if(s1&&c==1&&g==2){
		cout<<"AC"<<endl;
	}
	else{
		cout<<"WA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
typedef long long int ll;
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EFOR(i,a,b) for (int i=(a);i<=(b);i++)
const ll MOD = (10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7);

typedef long long ll;
ll N, a, b, ans = 1, temp, buff[510], alw = 0, c = 0;
char ms[510][510];
bool flag = false, lp = false;
int main() {
	scanf("%lld", &N);
	REP(i, N) {
		scanf("%s", &ms[i]);
	}
	REP(i, N) {//白マスの行数と全白マスの判定
		REP(j, N) {
			if (ms[j][i] == '.') {
				if (lp == false) {
					c++;
					lp = true;
				}
				alw++;
			}
		}
		lp = false;
	}
	if (alw == N*N) {
		printf("-1");
		return 0;
	}

	REP(i, N) {//行に白マス何個か。
		REP(j, N) {
			if (ms[j][i] == '#') {
				flag = true;
			}
			if (ms[i][j] == '.') {
				buff[i]++;
			}
		}

		if (!flag)buff[i]++;//列に#がなければ1を足す
		if (i != 0) {
			if (buff[i]<temp) {
				temp = buff[i];
			}
		}
		else temp = buff[i];

		flag = false;
	}
	ans = temp + c;
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 512
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}
fn gcd(a: usize, b: usize) -> usize {
    if a % b == 0 {
        b
    } else {
        gcd(b, a % b)
    }
}
fn lcm(a: usize, b:usize) -> usize {
    a / gcd(a, b) * b
}
fn main() {
    let input = read_vec::<usize>();
    let (a,b) = (input[0], input[1]);

    let ans = lcm (a, b);

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
using namespace std;
int n, a;
int main() {
	cin >> n;
	int dp[n];
	fill(dp, dp+n, 1001001001);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		*lower_bound(dp, dp+n, a) = a;
	}
	printf("%d\n", (int)(lower_bound(dp, dp+n, 1001001001)-dp));
}

Measured memory_bytes: 3592
#include <cstdio>
#include <algorithm>
int main(){int n,S,r[10000];while(scanf("%d%d",&n,&S),n){for(int i=0;i<n;i++){scanf("%d",r+i);}std::sort(r,r+n);int res = 0;for(int i=0;i+1<n;i++){res += std::distance(std::upper_bound(r+i+1,r+n,S-r[i]),r+n);}printf("%d\n",res);}}

Measured memory_bytes: 1080
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int prime[100100];


int main()
{

int a,b,c,x,y;
cin >> a >> b >> c >> x >> y;

if(a >=c*2 && c*2<= b)
{
    int mx = max(x,y);
    c*=2;

    cout << (mx*c) << endl;
}
else if(a>=c*2 )
{
    c*=2;
    int baki = 0;
    if(y>x)baki = y-x;

    cout << x*c+baki*b << endl;


}
else if(b>=c*2)
{
    c*=2;
    int baki = 0;
    if(x>y)baki = x-y;

    cout << y*c+baki*a << endl;

}
else if(a+b>=c*2)
{

    int mn = min(x,y);

    if(x>mn)
    {
        int baki = x-mn;
        cout << (mn*c*2)+baki*a << endl;
    }
    else if(y>mn)
    {
           int baki = y-mn;
        cout << (mn*c*2)+baki*b << endl;
    }
    else
    {
        cout << mn*c*2 << endl;
    }

}
else
    cout << a*x+b*y<< endl;


}


Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main()
{
    int a1;
    cin >> a1;
  	int a2;
    cin >> a2;
    int a3;
    cin >> a3;
  
    if((a1+a2+a3) <= 21) 
      cout << "win" << endl;
    else
      cout << "bust" << endl;
 
    return 0;
}

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

mtemp = math.fabs(A - (T - Hn[0] * 0.006))
midx = 0
for idx, v in enumerate(Hn):
    tmp = math.fabs(A - (T - v * 0.006))
    if tmp < mtemp:
        mtemp = tmp
        midx = idx

print(midx + 1)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
 int a,b,c;
 cin >> a >> b >> c;
 set<int> s;
 s.insert(a);
 s.insert(b);
 s.insert(c);
 cout << s.size();
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define mo 1000000007
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
#define adiii \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);  \
  cout.tie(NULL);									
 
ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
ll gcd(ll a,ll b) {if (b == 0) return a;return gcd(b, a % b);}
 
ll binpow(ll a, ll b) {ll res = 1;while (b > 0) {if (b & 1) res = res * a;a = a * a;b >>= 1;}return res;}
 
 
 
int main(){
	adiii
	string s,t;cin>>s>>t;
	ll n1 = s.length(),n2 = t.length();
	ll dp[n1+1][n2+1];
	memset(dp,0,sizeof(dp));
	rep(i,0,n1){
		rep(j,0,n2){
			if(s[i] == t[j]){
				dp[i+1][j+1] = dp[i][j] + 1;
			}
			else{
				dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
			}

		}
		//cout<<i<<"ddd "<<endl;
		//rep(j,0,n2) cout<<dp[i+1][j+1]<<" ";
		//cout<<endl;
	}
	ll i = n1-1,j=n2-1;
	string ans = "";
	while(i>=0 && j>=0){
		//cout<<i<<" "<<j<<endl;
		if(s[i] == t[j]){
			ans+=s[i];
			i--;j--;
		} 
		else{
			if(dp[i+1][j] > dp[i][j+1]){
				j--;
			}
			else i--;
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}


Measured memory_bytes: 70656
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define fi first
#define se second
//#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;

const int N = 5100;
typedef long long ll;
int p[N],vis[N];
ll c[N];
ll n,k;
ll res = -1e9 - 10;

ll sol(ll cir[],int size,ll k){
	if(!k)
		return 0ll; 
	ll sum = 0,res = -1e9 - 10,que1[N<<1],que2[N<<1];
	int h = 0,t = -1;
	que1[++t] = 0;
	que2[t] = 0;
	repi(i,1,size){
		sum += cir[i];
		while(i - que2[h] > k && h <= t) h++;
		res = max(res,sum - que1[h]);
//		cout<<sum<<' '<<sum - que1[h]<<endl;
		while(t >= h && sum <= que1[t]) t--;
		que1[++t] = sum;
		que2[t] = i;
		while(i + 1 - que2[h] > k && h <= t) h++;
	}
	return res;
}

int main(){
	sl(n),sl(k);
	repi(i,1,n){
		si(p[i]);
	}
	repi(i,1,n){
		sl(c[i]);
	}
	ll cir[N<<2],size;
	repi(i,1,n){
		if(vis[i])
			continue;
		int t = i;
		ll sum = 0;
		size = 0;
		while(1){
			vis[t] = 1;
			cir[++size] = c[t];
			sum += c[t];
			if(vis[p[t]])
				break;
			t = p[t];
		}
		repi(i,1,size){
			cir[i + size] = cir[i];
//			cout<<cir[i]<<' ';
		}
//		cout<<endl; 
//		cout<<sum * (k / size)<<endl; 
		res = max(res,sol(cir,2 * size,k));
		if(sum > 0 && k > size){
			res = max(res,sum * (k / size) + sol(cir,2 * size,k % size));
			res = max(res,sum * (k / size - 1) + sol(cir,2 * size,size));
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;
    int cnt = 0;
    int ans = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'A'){
            cnt++;
            if(ans < cnt){
               ans = cnt;
            }
        }
        else if(S[i] == 'C'){
            cnt++;
            if(ans < cnt){
               ans = cnt;
            }
        }
        else if(S[i] == 'G'){
            cnt++;
            if(ans < cnt){
               ans = cnt;
            }
        }
        else if(S[i] == 'T'){
            cnt++;
            if(ans < cnt){
               ans = cnt;
            }
        }
           else{
            cnt = 0;
            }
    }
    cout << ans << endl;
}

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

int main()
{
	int n,k;
	cin>>n>>k;
	vector<string>v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++)
		cout<<v[i];

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;
vector<ll>r{-1,0,1,0};
vector<ll>l{0,-1,0,1};

int main(){
  ll h,w;
  cin >> h >> w;
  vector<vector<ll>>length(h,vector<ll>(w,-1));
  queue<pair<ll,ll>>que;
  for(int i=0; i<h; i++){
   for(int j=0; j<w; j++){
     char a;
     cin >> a;
     if(a=='#'){
       length[i][j]=0;
       que.push({i,j});
     }
   }
  }
  ll MAX=0;
  while(que.size()>0){
    ll x=que.front().first,y=que.front().second;
    que.pop();
    for(int i=0; i<4; i++){
      if(x+r[i]<0 || x+r[i]>=h || y+l[i]<0 || y+r[i]>=w) continue;
      if(length[x+r[i]][y+l[i]]!=-1) continue;
      length[x+r[i]][y+l[i]]=length[x][y]+1;
      que.push({x+r[i],y+l[i]});
      MAX=max(MAX,length[x+r[i]][y+l[i]]);
    }
  }
  
  cout << MAX << endl;
  
}
  
  
  
  


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

int main(){
  int n;
  set<string> s;

  cin >> n;

  for (int i = 0; i < n; i++){
    string t;
    cin >> t;
    s.insert(t);
  }

  cout << s.size() << endl;

  return 0;
}


Measured memory_bytes: 19148