akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  int a, b, c;
  cin >> a >> b >> c;
  int K;
  cin >> K;
  FOR(i, 0, K) {
    FOR(j, 0, K) {
      FOR(k, 0, K) {
        if ((i + j + k) != K) continue;
        int na, nb, nc;
        na = a * pow(2, i);
        nb = b * pow(2, j);
        nc = c * pow(2, k);
        if (na < nb && nb < nc) {
          cout << "Yes" << endl;
          return;
        }
      }
    }
  }
  cout << "No" << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


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

#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long LL;
using namespace std;

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

	puts(n == m ? "Yes" : "No");
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define int long long int

main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int h, w, k;
	cin>>h>>w>>k;
	char arr[h][w];
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin>>arr[i][j];
		}
	}
	int ans=0;
	for(int i=0; i<(1<<h); i++){
		for(int j=0; j<(1<<w); j++){
			int cnt=0;
			for(int r=0; r<h; r++){
				for(int c=0; c<w; c++){
					if(arr[r][c]=='#' && ((1<<r)&i)==0 && ((1<<c)&j)==0){
						cnt++;
					}
				}
			}
			if(cnt==k){
				ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}

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

int main () {
	int H, W;
	cin >> H >> W;
	int N;
	cin >> N;
	int m[100*100];
	int idx = 0;
	for (int i = 0; i < N; i++) {
		int temp;
		cin >> temp;
		for (int j = 0; j < temp; j++) {
			m[idx] = i+1;
			idx++;
		}
	}
	for (int i = 0; i < H; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < W; j++) {
				if (j != 0) cout << " ";
				cout << m[i*W+j];
			}
			cout << endl;
		} else {
			for (int j = 0; j < W; j++) {
				if (j != 0) cout << " ";
				cout << m[i*W+(W-1-j)];
			}
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
# coding:utf-8

def main():
    stdIn = int(input())
    stdOut = solve(stdIn)
    print(stdOut)


"""
方針
パターン数としては
(0を少なくとも一つ含む場合 + 9を少なくとも一つ含む場合 - 0,9どちらか一つを含む場合)
= (10^n - 9^n) * 2 - (10^n - 8^n)
10^n + 8^n - 2 * 9^n
正しn<=10^6なので単純に計算するとオーバーフローする
逐次計算して10^9+7を超えたら減らす方針にする

"""

mod = 1000000007


def solve(n):
    # s = 10 ** n + 8 ** n - 9 ** n * 2
    n10 = modpow(10, n, mod)
    n8 = modpow(8, n, mod)
    n9 = modpow(9, n, mod)
    s = n10 + n8 - n9 * 2
    while s < 0:
        s += mod
    return s

# a^n mod を計算する


def modpow(a, n, p):
    bi = str(format(n, "b"))  # 2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res * res) % p
        if bi[i] == "1":
            res = (res * a) % p
    return res

if __name__ == "__main__":
    main()


Measured memory_bytes: 9212
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val array = Array(n, {0})
    for(i in 0..n-1){
      array[i] = scanner.nextInt()
    }
    var count = 0
    for(i in 1..n-2){
        if((array[i] < array[i-1] && array[i] > array[i+1] || (array[i] > array[i-1] && array[i] < array[i+1])))
                    count++
    }
    println(count)
}

Measured memory_bytes: 29352
import re
n=int(input())
A=[]
for i in range(n):
    B=["."]*n
    for x,y in [list(map(int,input().split())) for k in range(int(input()))]:
        B[x-1]=str(y)
    A.append("".join(B))
ans=0
for i in range(2**n):
    num=format(i,"b").zfill(n)
    cnt,flag=0,1
    for k,j in enumerate(num):
        result=re.search(r"".join(A[k]),num)
        if result!=None and j=="1":
            cnt +=1
        elif (result!=None and j=="0") or (result==None and j=="1"):
            flag=0
            break
    if flag:
        ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,i,j,n ;
    string str;
    cin>>n>>str;
    for(i=0 ; i<str.size() ; i=i+1)
    {
    	a = str[i] ;
    	char ch = a+n ;
    	if(a+n>90)
    	{
    		j = a+n - 90 ;
    		a = 64 + j ;
    		ch = a ;
		}
		cout<<ch ;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

const int N_MAX = 1e5 + 10;
vector<ll> v(N_MAX);
vector<ll> ans(N_MAX);

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  rep(i,N)cin >> v[i];
  ll pre[N+1];
  ll suf[N+1];
  pre[0] = 0;
  suf[N] = 0;
  int l = 1;
  rep(i,N){
    pre[i+1] = pre[i] + l*v[i];
    l*=-1;
  }
  l = 1;
  per(i,N){
    suf[i] = suf[i+1] + l*v[i];
    l*=-1;
  }
 // rep(i,N+1) cout << pre[i] SPF;
 // cout << endl;
 // rep(i,N+1) cout << suf[i] SPF;
 // cout << endl;
  rep(i,N){
    if(i&1){
      cout << v[i] + pre[i] - suf[i+1] SPF;
    }else{
      cout << v[i] - pre[i] + suf[i+1] SPF;
    }
  }
  cout << endl;
  return 0;
}


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

int main() {
	int n, q;
	cin >> n;
	int* S = new int[n+1];

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

	cin >> q;
	int* T = new int[q];

	int count = 0;

	for(int i = 0; i < q; i++)
	{
		cin >> S[n];
		int j = 0;
		while(S[j] != S[n])
			j++;

		if(j != n)
			count++;
	}

	cout << count << endl;

	return 0;
}

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


int main(){
  string S, T;
  cin >> S >> T;

  if(S != T.substr(0,S.length())){
    cout << "No";
  }else if(S.length() +1 != T.length()){
    cout << "No";
  }else{
    cout << "Yes";
  }
  return 0;
}


Measured memory_bytes: 3624
A,B,M=map(int,input().split())
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
m=[[] for i in range(M)]
for i in range(M):
  m[i]=[int(x) for x in input().split()]
  
for i in range(M):
  m[i]=a[m[i][0]-1]+b[m[i][1]-1]-m[i][2]
if(min(m)>min(a)+min(b)):
  print(min(a)+min(b))
else:
  print(min(m))

Measured memory_bytes: 36864
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]
v_max = 10 ** 3 * n
w_max = 10 ** 18
dp = [[w_max for _ in range(v_max + 1)] for _ in range(n + 1)]

for i in range(n):
    dp[i][0] = 0

for i in range(n):
    w_, v_ = wv[i]
    for j in range(v_max + 1):
        if j + v_ <= v_max:
            dp[i+1][j+v_] = min(dp[i][j] + w_, dp[i][j + v_])
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])


ans = 0
for i in range(v_max + 1):
    w_ = dp[n][i]
    if w_ <= w:
        ans = i
print(ans)


Measured memory_bytes: 171376
n=input()
print(n+': ',end='')
n=int(n)
x = 2
ans = []
while x * x <= n:
    while n % x == 0:
        n //= x
        ans.append(x)
    x = x + 1
if n > 1:
    ans.append(n)
print(" ".join(list(map(str, ans))))


Measured memory_bytes: 5600
#include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

int prim(){
    int u, minv;
    int d[MAX], p[MAX], color[MAX];
    
    for(int i = 0; i < n; i++){
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    
    while(1){
        minv = INFTY;
        u = -1;
        for(int i = 0; i < n; i++){
            if((minv > d[i]) && (color[i] != BLACK)){
                u = i;
                minv = d[i];
            }
        }
        if(u == -1) break;
        color[u] = BLACK;
        for(int v = 0; v < n; v++){
            if((color[v] != BLACK) && (M[u][v] != INFTY)){
                if(d[v] > M[u][v]){
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    int sum = 0;
    for(int i = 0; i < n; i++){
        if(p[i] != -1) sum += M[i][p[i]];
    }
    
    return sum;
}

int main(){
    cin >> n;
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            int e;
            cin >> e;
            M[i][j] = (e == -1) ? INFTY : e;
        }
    }
    
    cout << prim() << endl;
    
    return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
using namespace std;
typedef long long int ll;
ll gcd(ll a, ll b) {
  if (a < b)
    return gcd(b, a); 
  if (b == 0)
    return a;
  return gcd(b, a % b);
}


ll ceil(ll a, ll b) {
  return (a + b - 1) /b;
}

int main() {
  ll T;
  cin >> T;
  while (T--) {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    if (A < B) { cout << "No" << endl; continue; }
    if (D < B) { cout << "No" << endl; continue; }
    if (C >= B) { cout << "Yes" << endl; continue; }
    ll g = gcd(B, D);
    ll a = A % g;
    ll m = a + ceil(C + 1 - a, g) * g;
    if (C < m && m < B && m < D) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,total=0;
    cin>>n;
    int a[n]={};
    for(int i=0;i<n;i++)
        {
            cin>>a[i];
            total+=a[i];
        }
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int p,x,ans;
        cin>>p>>x;
        ans = total - a[p-1] + x;
        cout<<ans<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ac(n), wa(n);
  rep(i, m) {
    string s;
    int p;
    cin >> p >> s;
    p--;
    if(ac[p]) continue;
    if(s == "AC") {
      ac[p] = 1;
    }else {
      wa[p]++;
    }
  }
  int a, b;
  a = b =0;
  rep(i, n) {
    a += ac[i];
    if(ac[i]) b+= wa[i];
  }
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/rope>

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i, n) for (int i=0; i<(n); i++)
#define rep1(i, n) for (int i=1; i<=(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
template<typename _def> using ordered_set=tree<_def, null_type, less<_def>, rb_tree_tag, tree_order_statistics_node_update>;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;

int n;
vector<vector<pii>> adj;

const ll INF=1e18;
ll dijkstra(int src, int dest) {
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq; //i hate this
    ll dist[n]; rep(i, n) dist[i]=INF;
    dist[src]=0; pq.push({0, src});
    while(!pq.empty()) {
        int u=pq.top().se; pq.pop();
        for(auto it: adj[u]) {
            int v=it.fi, w=it.se;
            if(dist[v]>dist[u]+w) {
                dist[v]=dist[u]+w;
                pq.push({dist[v], v});
            }
        }
    }
    return dist[dest];
}

int32_t main() {
    fastio;
    int m; cin>>n>>m; adj.resize(n);
    rep1(i, n-1) adj[i].emplace_back(i-1, 0);
    rep(i, m) {
        int u, v, w; cin>>u>>v>>w;
        adj[--u].emplace_back(--v, w);
    }
    ll ans=dijkstra(0, n-1);
    cout<<(ans==INF?-1:ans)<<endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

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

    string left = "", right = "";
    bool rev = false;
    int t, f;
    char c;
    for (int i = 0; i < q; ++i) {
        cin >> t;
        if (t == 1){
            rev = !rev;
        } else{
            cin >> f >> c;
            if (f == 1){
                if (rev) right += c;
                else left += c;
            } else{
                if (rev) left += c;
                else right += c;
            }
        }
    }
    if (rev){
        reverse(all(right));
        reverse(all(s));
        cout << right + s + left << endl;
    } else{
        reverse(all(left));
        cout << left + s + right << endl;
    }
}

Measured memory_bytes: 4300
while true
	x,y = gets.split.map {|i| i.to_i }
	if x == 0 && y == 0
				break
	elsif	x < y
		puts "#{x} #{y}"
	elsif	x > y
		puts "#{y} #{x}"
	elsif x == y
		puts "#{x} #{y}"
	end
end

Measured memory_bytes: 6100
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <list>
using namespace std;

#define is_uruu leapyear
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(a);i>(b);--i)
#define REP(i,a) for(int i=0;i<(a);++i)
    

int main() {
	stack<int> S;
	int H, W, N, a[10000];
	cin >> H >> W >> N;
	FOR(i, 1, N+1) cin >> a[i];
	
	FOR(i, 1, N+1){
		FOR(j, 0, a[i]) S.push(i);
	}
	
	int HW[100][100];
	FOR(i, 0, H){
		if(i%2 == 0){
			FOR(j, 0, W) {
				HW[i][j] = S.top(); 
				S.pop();
			}
		} else {
			ROF(j, W-1, -1) {
				HW[i][j] = S.top(); 
				S.pop();
			}
		}
	}
	
	FOR(i, 0, H) FOR(j, 0, W) printf("%d%c", HW[i][j], (j==W-1)?'\n':' ');
	
    return 0;
}

Measured memory_bytes: 384
n,m=map(int,input().split())
ab=[ [0,0] for _ in range(n)]
for i in range(n):
    ab[i] = tuple( map(int,input().split()) )
ab.sort()

from collections import deque
import heapq
ab=deque(ab)
cand=[]
heapq.heapify(cand)

ans=[0]*m
for i in range(m):
    while len(ab)>0:
        c=ab.popleft()
        if c[0]==i+1:
            heapq.heappush(cand,-c[1])
        else:
            ab.appendleft(c)
            break
    if len(cand)>0:
        ma = -heapq.heappop(cand)
        ans[i]=ma
print(sum(ans))

Measured memory_bytes: 84512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
int main(){
  long long int n,d=1;
  cin >> n;
  vector <int>v;
  while(1){
    if(n==0) break;
    d=n%2;
    if(d<0) d+=2;
    n=(n-d)/(-2);
    v.push_back(d);
  }
  if(v.size()==0) cout << 0<<endl;
  else{
  reverse(v.begin(),v.end());
  for(int i=0;i<v.size();i++) cout << v[i];
  cout << endl;
}
}


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

using namespace std;
const long long mod =1e9+7; 
int main(){
	int n;
	cin>>n;
	long long a[n];
	long long sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	long long s=0;
	for(int i=n-1;i>=0;i--){
		sum-=a[i];
		s=(s+((a[i]%mod)*(sum%mod))%mod)%mod;
	}
	cout<<s<<"\n";
}

Measured memory_bytes: 5164
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int toppings[100];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int N, A, B, C;
    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; ++i) {
        cin >> toppings[i];
    }
    sort(toppings, toppings+N, greater<int>());

    int total_cal = C, total_cost = A;
    int best = total_cal / total_cost;
    for(int i = 0; i < N; ++i) {
        total_cal += toppings[i];
        total_cost += B;
        best = max(best, total_cal / total_cost);
    }
    cout << best << endl;
    return 0;
}

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

using namespace std;

int d[4];
string s;

int calc(int a, int op, int b){
	if(op == 0) return a+b;
	else return a-b;
}

int calcall(int a, int op1, int b, int op2, int c, int op3, int d){
	return calc(calc(calc(a, op1, b), op2, c), op3, d);
}

string repl(string t){
	for(int i = 1; i < t.size(); i += 2){
		if(t[i] == '0') t[i] = '+';
		else t[i] = '-';
	}
	return t;
}

int main(){
	cin >> s;
	for(int i = 0; i < 4; ++i) d[i] = s[i]-'0';

	for(int i = 0; i < 2; ++i) for(int j = 0; j < 2; ++j) for(int k = 0; k < 2; ++k){
		if(calcall(d[0], i, d[1], j, d[2], k, d[3]) == 7){
			cout << repl(to_string(d[0])+to_string(i)+to_string(d[1])+to_string(j)+to_string(d[2])+to_string(k)+to_string(d[3]))+"=7" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int x = sc.nextInt();

		String ans;
		if(a > x)
			ans = "NO";
		else if((x-a) <= b) 
			ans = "YES";
		else
			ans = "NO";	
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 22100
#include <iostream>

using namespace std;
static const int N=100;
int main()
{
    int M[N][N];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            M[i][j]=0;
    for(int i=0;i<n;i++)
    {
        int j,num;
        cin>>j>>num;
        for(int a=0;a<num;a++)
        {
            int k;
            cin>>k;
            M[j-1][k-1]=1;
        }
    }
    //print
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cout<<M[i][j];
            if(j==n-1) cout<<endl;
            else cout<<" ";
        }
    }

}

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

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

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

    sort(h.begin(), h.end());

    ll ans = h.back() - h.front();
    for (int i = 0; i <= n-k; i++) {
        ll hdiff = h[i+k-1] - h[i];
        ans = min(ans, hdiff);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
if n>=m:
    print(0)
    exit()
l.sort() 
diff=[l[i]-l[i-1] for i in range(1,m)]
diff.sort() 
for i in range(n-1):
    diff.pop()
print(sum(diff))

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

int main(){
  int a,b[120];
    cin>>a;
  for(int i=0;i<a;i++)
  cin >>b[i];
  
  sort(b ,b+a,greater<int>());
  int c =0;
  int d =0;
    for(int i=0;i<a;i++){

   if(i%2 ==0){
     c += b[i];
   }
      else{
        d+=b[i];
      }
    }
    cout << c-d << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int a, b, c;
cin >> a >> b >>c;
int t=a+b+c;
cout << (t == 2*a ||t==2*b ||t==2*c ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n,d = readline() |> split |> parseMap
	x = Array{Int}(d,n)
	for i in 1:n
		x[:,i] = readline() |> split |> parseMap
	end
	l = 0
	for i in 1:n-1
		for j in i+1:n
			s = 0
			for k in 1:d
				s += (x[k,i]-x[k,j])^2
			end
			t = 0
			while t < sqrt(s)
				t += 1
			end
			if t^2==s
				l += 1
			end
		end
	end
	println(l)
end

main()

Measured memory_bytes: 115484
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int l = sc.nextInt();
		int r = sc.nextInt();

		// 計算
		int result = Integer.MAX_VALUE;
		for(int i = l; i < min(l + 2019, r + 1); i++){
		    for(int j = i + 1; j < min(l + 2019, r + 1); j++){
		        result = min(result, ((i%2019)*(j%2019))%2019);
		    }
		}

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


Measured memory_bytes: 23636
import sys
input = sys.stdin.readline

N, K, Q = map(int, input().split())
A = list(map(int, input().split()))
ans = float('inf')
for lb in sorted(A):
    tmp = []
    use = []
    for a in A + [-1]:
        if a >= lb:
            tmp.append(a)
        else:
            if len(tmp) >= K:
                use += sorted(tmp)[:len(tmp)-K+1]
            tmp = []
    if len(use) < Q:
        break
    ans = min(ans, sorted(use)[Q-1] - lb)
print(ans)

Measured memory_bytes: 44252
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>N>>K>>S;
    rep(i,26){
        if(S.at(K-1) == ALPHA.at(i)) S.at(K-1) = alpha.at(i);
    }
    cout<<S<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<pair<UL, UL>> A(N), B(N);
		rep(i, N) { cin >> A[i].first; A[i].second = i; }
		rep(i, N) { cin >> B[i].first; B[i].second = i; }
		sort(A.begin(), A.end());
		sort(B.begin(), B.end());
		rep(i, N) if (A[i].first > B[i].first) {
			cout << "No" << endl; return;
		}
		rep(i, N) {
			if (A[i].second == B[i].second) {
				cout << "Yes" << endl; return;
			}
		}
		rep(i, N - 1) {
			if (A[i + 1].first <= B[i].first) {
				cout << "Yes" << endl; return;
			}
		}
		vector<UL> G(N);
		rep(i, N) G[B[i].second] = A[i].second;
		{
			UL p = 0;
			rep(j, N - 1) {
				p = G[p];
				if (p == 0) {
					cout << "Yes" << endl; return;
				}
			}
		}
		cout << "No" << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  int counter = 0;
  
  for(int i = 0; i < vec.size();i++) cin >> vec.at(i);
  
  vector<int> mochi(*max_element(vec.begin(),vec.end()));
  
  for (int i = 0; i < vec.size(); i++){
    mochi.at(vec.at(i)-1)++;
  }
  
  for(int i = 0; i < mochi.size(); i++){
    if(mochi.at(i) > 0){
      counter++;
    }
  }
  
  cout << counter << endl;
}

Measured memory_bytes: 256
N,T = map(int, input().split())
c_t = []
for i in range(N):
    c_t.append(list(map(int,input().split())))

c_t = sorted(c_t, key=lambda x:x[1])
if c_t[0][1]>T:
    print('TLE')
    import sys
    sys.exit()
ans = c_t[0][0]
for i in range(N):
    if c_t[i][1]>T:
        break
    if ans>c_t[i][0]:
        ans = c_t[i][0]
print(ans)

Measured memory_bytes: 3064
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool is_prime(int n) {
  for(int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int main()
{
  int n;
  cin >> n;
  map<int, int> mp;
  vector<int> primes;
  primes.push_back(2);
  ll r = 1e9+7;
  for (int i = 2; i <= n; i++) {
    if (is_prime(i)) primes.push_back(i);
  }
  for (int i = 2; i <= n; i++) {
    int x = i;
    rep(j, (int)primes.size()) {
      while(x % primes[j] == 0) {
        x /= primes[j];
        mp[primes[j]]++;
      }
    }
  }
  ll ans = 1;
  for (auto m = mp.begin(); m != mp.end(); m++) {
    ans *= (m->second + 1);
    ans %= r;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", B: "List[int]"):
    count = 0
    for i in range(N-1, -1, -1):
        if A[i+1] > B[i]:
            count += B[i]
        else:
            count += A[i+1]
            B[i] = B[i] - A[i+1]
            count += min(A[i], B[i])
            A[i] = max(A[i] - B[i], 0)
    print(count)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N+1) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 19452
#include <bits/stdc++.h>
using namespace std;
int n, a[11000][11000], t = 0;
bool flag[11000], fl = 0;
bool judge() {
  for (int i = 1; i <= n; ++i)
    if (a[i][0] != n)
      return 0;
  return 1;
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j < n; ++j)
      cin >> a[i][j];
    a[i][0] = 1;
  }
  while (1) {
    if (judge()) {
      printf("%d\n", t);
      return 0;
    }
    fl = 0;
    memset(flag, 0, sizeof(flag));
    ++t;
    for (int i = 1; i <= n; ++i) {
      if (flag[i] || a[i][0] == n)
        continue;
      int x = a[i][a[i][0]], y = a[x][a[x][0]];
      if (!flag[x] && !flag[i] && i == y) {
        fl = 1;
        flag[x] = 1;
        flag[i] = 1;
        ++a[i][0];
        ++a[x][0];
      }
    }
    if (!fl) {
      printf("-1\n");
      return 0;
    }
  }
  return 0;
}


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

int main()
{
    std::string s;
    std::cin >> s;
    unsigned int a{}, z{s.size() - 1};
    while (s[a] != 'A') a++;
    while (s[z] != 'Z') z--;
    printf("%d\n", z - a + 1);

    return 0; 
}

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

int main(){
  int N;
  cin>>N;
  
  vector<int>A(N);
  
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  
  sort(A.begin(),A.end());
  
  int res=0;
  
  for(int i=0;i<N;i++){
    int count=1;
    
    for(int j=i+1;j<N;j++){
      if(A.at(i)==A.at(j)){
        count++;
        i=j;
      }
      
      else
        break;
    }
    
    if(count%2==1){
      res++;
      //cout<<A.at(i);
    }
    //cout<<A.at(i);
  }
  
  
  
  cout<<res;
}

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

int gcd(int &a, int &b){
  if(b == 0) return a;
  return gcd(b,(a%b));
}

int main(){
  int64_t n,aa,sum=0;
  vector<int64_t> tmp(3);
  cin >> n;
  n++;
  for(int i=1;i<n;i++){
    for(int j=1;j<n;j++){
      for(int k=1;k<n;k++){
        tmp.at(0) = i; tmp.at(1) = j; tmp.at(2) = k;
        sort(tmp.begin(),tmp.end());
        aa = gcd(tmp.at(2),tmp.at(1));
        if(aa <= tmp.at(0)){
          sum += gcd(tmp.at(0),aa);
        }else{
          sum += gcd(aa,tmp.at(0));
        }
      }
    }
  }
  cout << sum << endl;
        
          
  
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
      int char1,char2;
      cin>>char1>>char2;
      int strength[]={2,3,4,5,6,7,8,9,10,11,12,13,1};
      int alice=0;
      int bob=0;
      for(int i=0 ; i<13 ; ++i)
      {
      	if(char1==strength[i])
        alice=i;
        if(char2==strength[i])
        bob=i;
      }
      if(alice>bob)
      cout<<"Alice";
      else if(alice<bob)
      cout<<"Bob";
      else
      cout<<"Draw";
      cout<<endl;
      return 0;
    }

Measured memory_bytes: 256
class DisjointSet:
    def __init__(self,size):
        self.rank = [None]*size
        self.size = [None]*size
        self.p = [None]*size
        for i in range(size):
            self.make_set(i)
        return
    
    def make_set(self,x):
        self.p[x] = x
        self.rank[x] = 0
        self.size[x] = 1
        return
    
    def same(self,x,y):
        return self.find_set(x) == self.find_set(y)
        
    def unite(self,x,y):
        self.link(self.find_set(x),self.find_set(y))
        return
    
    def link(self,x,y):
        if self.rank[x]>self.rank[y]:
            self.p[y] = x
            self.size[x] += self.size[y]
        else:
            self.p[x] = y
            self.size[y] += self.size[x]
            if self.rank[x]==self.rank[y]:
                self.rank[y] += 1
                
    def find_set(self,x):
        if x != self.p[x]:
            self.p[x] = self.find_set(self.p[x])
        return self.p[x]
    

n,m = map(int,input().split())
djs = DisjointSet(n)

for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    if not djs.same(a,b):
        djs.unite(a,b)

print(max(djs.size))

Measured memory_bytes: 89796
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>

using namespace std;
struct edge
{
	int f;
	int t;
	int c;
};

const int S = 2505;
const int inf = 1e9;
int n, m, p, a, b, c, d[S * 4];
vector<pair<int, int> > G[S];

int main()
{
	
	cin >> n >> m >> p;
	
	for (int i = 0; i < m; i++)
	{
		cin >> a >> b >> c;
		a--; b--; c -= p;
		G[a].push_back(make_pair(b, -c));
	}
	
	fill(d, d + m * 2, inf);
	d[0] = 0;
	
	for (int i = 0; i < n * 2 + 10; i++)
	{
		for (int j = 0; j < n; j ++) for (auto t : G[j])
		{
			if (d[j] != inf && d[t.first] > d[j] + t.second)
			{
				d[t.first] = d[j] + t.second;
				if (i >= n - 1 && t.first == n - 1) return 0 * puts("-1");
			}
		}
	}
	cout <<  max(0, -d[n - 1]);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(c>b||a>d)	cout<<0<<'\n';
	else cout<<min(b,d)-max(a,c)<<'\n';
	return 0;
}

Measured memory_bytes: 256
X, N = map(int, input().split())
*p, = map(int, input().split())
s = set()
for i in range(-150, 150):
    if i in p:continue
    s.add(i)
l = sorted(s)

b = 10**20
ans = 0

for i in l:
    if b>abs(i-X):
        b = abs(i-X)
        ans = i

print(ans)


Measured memory_bytes: 9188
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        char[][] a = new char[h][w];
        for(int i = 0; i < h; i++){
            a[i] = sc.next().toCharArray();
        }
        
        boolean[] bh = new boolean[h];
        boolean[] bw = new boolean[w];
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(a[i][j] == '#'){
                    bh[i] = true;
                    bw[j] = true;
                }
            }
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < h; i++){
            boolean b = false;
            for(int j = 0; j < w; j++){
                if(bh[i] && bw[j]){
                    sb.append(a[i][j]);
                    b = true;
                }
            }
            if(b) sb.append(System.lineSeparator());
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int n, d;

bool f(vector<double> a, vector<double> b) {
	double num = 0.0;
	rep(i, 0, d) {
		double len = a[i] - b[i];
		len *= len;
		num += len;
	}
	num = sqrt(num);
	if (ceil(num) == double(num)) return true;
	else return false;
}

int main() {
	cin >> n >> d;
	vector<vector<double>> x(n, vector<double>(d));
	rep(i, 0, n) {
		rep(j, 0, d) {
			cin >> x[i][j];
		}
	}

	int count = 0;
	rep(i, 0, n - 1) {
		rep(j, i + 1, n) {
			if (f(x[i], x[j])) count++;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long LL;
#define M(a,b) memset(a,b,sizeof(a))
#define pb push_back
const int maxn = 100000+5;
const LL mod = 1000000007;
LL qp(LL a,LL p) {
    LL res=1;
    while(p) {
        if (p&1) {
            res=res*a%mod;
        }
        a=a*a%mod;
        p>>=1;
    }
    return res;
}
int d[maxn];
int cnt[maxn]={0};
int main() {

    int n;
    scanf("%d",&n);
    for (int i=1;i<=n;++i) {
        scanf("%d",d+i);
        ++cnt[d[i]];
    }
    if (n&1) {

        int flag=0;
        if (cnt[0]!=1) {
            flag=1;
        }
        for (int i=1;i<=n&&!flag;++i) {
            if (i&1) {
                if (cnt[i]) {
                    flag=1;
                    break;
                }
            }
            else {
                if (cnt[i]!=2) {
                    flag=1;
                    break;
                }
            }
        }
        if (!flag) {
            printf("%lld\n",qp(2,(n-1)>>1));
        }
        else {
            puts("0");
        }
    }
    else {
        int flag=0;
        if (cnt[0]) {
            flag=1;
        }
        for (int i=1;i<=n&&!flag;++i) {
            if (i&1) {
                if (cnt[i]!=2) {
                    flag=1;
                    break;
                }
            }
            else {
                if (cnt[i]) {
                    flag=1;
                    break;
                }
            }
        }
        if (!flag) {
            printf("%lld\n",qp(2,n>>1));
        }
        else {
            puts("0");
        }
    }
    return 0;
}

Measured memory_bytes: 1024
N = str(input())

hyaku = 0
flg = 0
for index, i in enumerate(N):
    if index == 0:
        hyaku = int(i)
    else:
        if hyaku >= int(i):
            pass
        else:
            flg = 1
            break
if flg:
    for _ in range(3):
        print(hyaku + 1, end='')
else:
    for _ in range(3):
        print(hyaku, end='')

Measured memory_bytes: 3060
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    a, b = list(map(int,ipti().split()))
    a, b = (a+11)%13, (b+11)%13

    if a == b:
        print("Draw")
    elif a > b:
        print("Alice")
    else:
        print("Bob")

if __name__ == '__main__':
    main()

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
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; }
//template end

int n,m,cnt[100010]={}; ll X[100010]={};

template<class Abel> struct UnionFind {
    vector<int> par,rank;
    vector<Abel> diff_weight;
    UnionFind(int n=1,Abel SUM_UNITY=0){init(n, SUM_UNITY);}
    void init(int n=1,Abel SUM_UNITY=0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        rep(i,0,n)par[i]=-1,rank[i]=0,diff_weight[i]=SUM_UNITY;
    }
    int root(int x){
        if(par[x]<0)return x;
        int r=root(par[x]); diff_weight[x]+=diff_weight[par[x]];
        return par[x]=r;
    }
    int size(int x){ return -par[root(x)]; }
    Abel weight(int x){root(x); return diff_weight[x];}
    bool issame(int x, int y){return root(x)==root(y);}
    bool merge(int x,int y,Abel w){
        w+=weight(x)-weight(y); x=root(x); y=root(y);
        if(x==y){cnt[x]++;return false;}
        if(rank[x]<rank[y])swap(x,y),w=-w;
        if(rank[x]==rank[y])++rank[x];
        cnt[x]+=cnt[y]+1; X[x]+=X[y]; 
        par[x]+=par[y]; par[y]=x; diff_weight[y]=w; return true;
    }
    Abel diff(int x,int y){return weight(y)-weight(x);}
};

typedef pair<int,pair<int,int>> T;

int main(){
    scanf("%d%d",&n,&m);
    rep(i,0,n)scanf("%lld",&X[i]);
    vector<T> es(m);
    rep(i,0,m){
        scanf("%d%d%d",&es[i].second.first,&es[i].second.second,&es[i].first);
        es[i].second.first--; es[i].second.second--;
    }
    sort(ALL(es));
    int dec=0; UnionFind<int> uni(n);
    rep(i,0,m){
        int u=es[i].second.first,
        v=es[i].second.second,w=es[i].first;
        uni.merge(u,v,1); u=uni.root(u);
        if(X[u]>=w)dec+=cnt[u],cnt[u]=0;
    }
    printf("%d\n",m-dec);
    return 0;
}

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

using Lint=long long;

int main()
{
   string s,t; cin>>s>>t;
   int N=s.size(),M=t.size();
   s=' '+s;
   t=' '+t;
   vector<vector<int>> dp(N+1,vector<int>(M+1));
   for(int i=1;i<=N;i++) for(int j=1;j<=M;j++){
      if(s[i]==t[j]){ dp[i][j]=dp[i-1][j-1]+1; }
      else{ dp[i][j]=max(dp[i-1][j],dp[i][j-1]); }
   }
   string ans;
   int i=N,j=M;
   while(dp[i][j]>0){
      if(s[i]==t[j]){
         ans=s[i]+ans;
         i--; j--;
      }else{
         if(dp[i-1][j]>=dp[i][j-1]) i--;
         else j--;
      }
   }
   cout<<ans<<endl;
   return 0;
}


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

using namespace std;

#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
#define ll long long

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

	string s;
	cin >> s;
	set<char> se;
	for(int i = 0; i < s.size(); i++) {
		se.insert(s[i]);
	}
	if(se.size() == 2) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}


Measured memory_bytes: 256
def solve(STR):
    CNT, tmp = 0, list(s)
    while len(set(tmp)) > 1:
        CNT += 1
        for i in range(len(tmp) - 1):
            if STR in tmp[i:i+2]:
                tmp[i] = STR
        tmp.pop()
    return CNT


s = input()

ans = 100
for lttr in set(s):
    ans = min(ans, solve(lttr))
print(ans)


Measured memory_bytes: 68036
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, l;
  cin >> n >> l;

  int sum = n * (2 * l + n - 1) / 2;
  if (l > 0)
  {
    cout << sum - l << endl;
  }
  else if (l + n - 1 < 0)
  {
    cout << sum - (l + n - 1) << endl;
  }
  else
  {
    cout << sum << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
ll mygcd(ll a, ll b)
{
    if (b == 0)
    {
        return a;
    }
    else
    {
        return mygcd(b, a % b);
    }
}
int main(){
    ll n;cin>>n;
    cout<<n*2/mygcd(n,2)<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
	
	int s[13],h[13],c[13],d[13];
	int n,i,j,num;
	char sort;
	for(i=0;i<13;i++){
		s[i]=i+1;
		h[i]=i+1;
		c[i]=i+1;
		d[i]=i+1;
	}
	scanf("%d",&n);
	for(i=0;i<n*2;i++){
		scanf("%c %d",&sort,&num);
		switch(sort){
		case 'S':s[num-1]=0;
			break;
		case 'H':h[num-1]=0;
			break;
		case 'C':c[num-1]=0;
			break;
		case 'D':d[num-1]=0;
			break;
		}
	}
	for(i=0;i<13;i++){
		if(s[i]==0)continue;
		printf("S %d\n",s[i]);
	}
	for(i=0;i<13;i++){
		if(h[i]==0)continue;
		printf("H %d\n",h[i]);
	}
	for(i=0;i<13;i++){
		if(c[i]==0)continue;
		printf("C %d\n",c[i]);
	}
	for(i=0;i<13;i++){
		if(d[i]==0)continue;
		printf("D %d\n",d[i]);
	}
	return 0;
}


Measured memory_bytes: 2028
#include<iostream>
using namespace std;
int main(){
  while(true){
    int n;
    cin >>n;
    if(n==0)
      break;
    char c[100];
    for(int i=0;i<n;i++){
      cin>>c[i];
    }
    int cnt[26]={0};
    for(int i=0;i<n;i++){
      cnt[(int)(c[i]-'A')]++;
      int max1=-1;
      int max2=-1;
      for(int j=0;j<26;j++){
        if(cnt[j]>max1){
          max2=max1;
          max1=cnt[j];
        }else if(cnt[j]>max2){
          max2=cnt[j];
        }
      }
      if(max1-max2>n-(i+1)){
        for(int j=0;j<26;j++){
          if(cnt[j]==max1){
            cout<<(char)(j+'A')<<' ';
            break;
          }
        }
        cout<<(i+1)<<endl;
        break;
      }
      if(i==n-1){
        cout<<"TIE"<<endl;
        break;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e9+7;
const ll mod= 1e9 + 7;


int N;
string S, T;

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


	cin >> S >> T;
	if (S.substr(0, S.length()) == T.substr(0, S.length()) && T.length() == S.length() + 1) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;


	return 0;
}

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

long long mod(long long a, long long m) {
	a %= m;
	return a >= 0 ? a : a+m;
}

struct P
{
	using T = long long;
	T x, y;
	P(T x=0, T y=0) : x(x), y(y) {}

	friend ostream &operator<<(ostream &os, const P &a) {
		return os << '(' << a.x << ',' << a.y << ')';
	}

	int quadrant() const {
		if (x > 0 && y >= 0) return 0;
		else if (x <= 0 && y > 0) return 1;
		else if (x < 0 && y <= 0) return 2;
		else if (x >= 0 && y < 0) return 3;
		else return 4;
	}
};

long long cross_product(const P &a, const P &b) {
	return (long long)a.x * b.y - (long long)a.y * b.x;
}

bool comp_argument_sort(const P &a, const P &b) {
	int a_quad = a.quadrant(), b_quad = b.quadrant();
	if (a_quad != b_quad) return a_quad < b_quad;
	else return cross_product(a, b) > 0;
}

int main() {
	int n;
	cin >> n;
	vector<P> v;
	for (int i = 0; i < n; i++) {
		long long x, y;
		cin >> x >> y;
		if (x == 0 && y == 0) continue;
		v.emplace_back(x, y);
	}
	if (v.size() == 0) {
		cout << 0 << endl;
		return 0;
	}
	n = v.size();
	sort(v.begin(), v.end(), comp_argument_sort);
	long long ans2 = 0;
	for (int i = 0; i < n; i++) {
		long long X = 0, Y = 0;
		for (int j = 0; j < n; j++) {
			int idx = mod(i+j, n);
			X += v[idx].x, Y += v[idx].y;
			long long now = X*X + Y*Y;
			ans2 = max(ans2, now);
		}
	}
	double ans = sqrt(ans2);
	cout << fixed << setprecision(20) << ans << endl;
	return 0;
}

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

vector<int> mm;
int fib(int n){
  if (n == 0)
    return 0;
  else if (n == 1)
    return 1;
  else if (mm[n])
    return mm[n];
  else  {
    mm[n] = fib(n-1)+fib(n-2);
    return mm[n];
    }
}

int main(){
  int n;
  cin >> n;
  mm.assign(n+2,0);

  cout << fib(n+1) << "\n";
}


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

int main(void){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> sw(m);
    for (int i = 0; i < m; i++) {
        int k;
        cin >> k;
        vector<int> s(k);
        for (int j = 0; j < k; j++)
            cin >> s[j];
        sw[i] = s;
    }
    vector<int> p(m);
    for (int i = 0; i < m; i++)
        cin >> p[i];
    
    int ans = 0;
    for (int i = 0; i < pow(2, n); i++) {
        bool flag = true;
        for (int j = 0; j < m; j++) {
            int count = 0;
            for (int k = 0; k < sw[j].size(); k++) {
                count += bitset<10>(i)[sw[j][k]-1];
            }
            if (count % 2 != p[j]) {
                flag = false;
                break;
            }
        }
        
        if (flag)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){

	int n,a[10000],b[10000],k,t,i,l,m;
	
	scanf("%d %d",&n,&m);
	for(t=0;t<2*n;t++){
		a[t]=t+1;
	}
	
	for(i=0;i<m;i++){
		scanf("%d",&k);
		if(k==0){
			for(t=0;t<n;t++){
				b[2*t]=a[t];
			}
			for(t=n;t<2*n;t++){
				b[2*(t-n)+1]=a[t];
			}
			for(t=0;t<2*n;t++){
				a[t]=b[t];
			}
		}
		else{
			for(t=0;t<k;t++){
				b[2*n-k+t]=a[t];
			}
			for(t=0;t<2*n-k;t++){
				b[t]=a[t+k];
			}
			for(t=0;t<2*n;t++){
				a[t]=b[t];
			}
		}
	}
	
	for(t=0;t<2*n;t++){
		printf("%d\n",a[t]);
	}
	
	return 0;
}

Measured memory_bytes: 612