akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>

using ll = long long;
const ll inf = 1001001001;

int main(){
 int n, k, r, s, p;
 cin >> n >> k >> r >> s >> p;
 string h;
 cin >> h;
 vector<bool>v(n, true);
 ll ans = 0; 
 rep(i, 0, n){
     if(k <= i && h[i] == h[i-k]){
         if(v[i-k]){
             v[i] =false;
             continue;
         }
         else{
             if(h[i] == 'r')ans += p;
             if(h[i] == 's')ans += r;
             if(h[i] == 'p')ans += s;
             continue;
         }
     }
     if(h[i] == 'r')ans += p;
     if(h[i] == 's')ans += r;
     if(h[i] == 'p')ans += s;
 }
 cout << ans << endl;
}

Measured memory_bytes: 512
k=int(input())
anss=[i for i in range(1,10)]

for i in range(12):
  if len(anss)>k:
    print(anss[k-1])
    break
  new_anss=[]
  for ans in anss:
    if ans%10 != 0:
      new_anss.append(ans*10+ans%10-1)
    new_anss.append(ans*10+ans%10)
    if ans%10 != 9:
      new_anss.append(ans*10+ans%10+1)
  k -= len(anss)
  anss = new_anss

Measured memory_bytes: 10748
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var set = new HashSet<int>();
            for (int i = 0; i < n; i++)
            {
                var val = int.Parse(Console.ReadLine());
                if (set.Contains(val))
                {
                    set.Remove(val);
                }
                else
                {
                    set.Add(val);
                }
            }
            Console.WriteLine(set.Count());
        }
    }
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  int dy[] = {1,1,1,0,0,-1,-1,-1};
  int dx[] = {1,0,-1,1,-1,1,0,-1};
  int a,b;
  cin >> a >> b;
  a--,b--;
  vector<string> s(100);
  rep(i,50)s[i] = string(100,'#');
  rep(i,50)s[99-i] = string(100,'.');
  rep(i,50)rep(j,100){
    if(a == 0)break;
    bool is = true;
    rep(k,8){
      int ny = i+dy[k],nx = j+dx[k];
      if(ny < 0 || nx < 0 || nx >= 100)continue;
      if(s[ny][nx] == '.')is = false;
    }
    if(is){
      s[i][j] = '.';
      a--;
    }
  }
  for(int i = 50;i < 100;i++)rep(j,100){
    if(b == 0)break;
    bool is = true;
    rep(k,8){
      int ny = i+dy[k],nx = j+dx[k];
      if(ny >= 100 || nx < 0 || nx >= 100)continue;
      if(s[ny][nx] == '#')is = false;
    }
    if(is){
      s[i][j] = '#';
      b--;
    }
  }
  cout << "100 100\n";
  rep(i,100)cout << s[i] << endl;





  


  return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    double xa, ya, ra, xb, yb, rb;
    int n;
    cin >> n;
    rep(i, n){
        int ans = 0;
        cin >> xa >> ya >> ra >> xb >> yb >> rb;
        if(sqrt(pow(abs(xa-xb), 2)+pow(abs(ya-yb), 2))+rb < ra) ans = 2;
        else if(sqrt(pow(abs(xa-xb), 2)+pow(abs(ya-yb), 2))+ra < rb) ans = -2;
        else if(sqrt(pow(abs(xa-xb), 2)+pow(abs(ya-yb), 2)) <= ra+rb) ans = 1;
        else ans = 0;
        cout << ans << endl;
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
int n;
vector<int> v;

int main(){
  cin>>n;
  REP(i,n){
    int temp;
    cin>>temp;
    v.push_back(temp);
  }
  sort(v.begin(),v.end());
  int count=0;
  for(int i=v[n/2-1]+1;i<=v[n/2];i++){
    count++;
  }
  //int k=v[n/2];
  cout<<count<<endl;

}


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

const long long MOD = 998244353;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  int N, K;
  cin >> N >> K;
  long long ans = 0;
  vector<pair<int, int>> kukan;
  for(int i = 0; i < K; i++){  
    int l, r;
    cin >> l >> r;
    kukan.emplace_back(l, r);
  }
  sort(kukan.begin(), kukan.end());
  vector<long long> ruisekiwa(N+1);
  ruisekiwa[0] = 0;
  ruisekiwa[1] = 1;
  for(int i = 2; i <= N; i++){  
    long long tmp = 0;
    for(auto p: kukan){  
      int l = p.first, r = p.second;
      if(i - l > 0){  
        if(i - r <= 0){  
          tmp += ruisekiwa[i - l]; 
        } else{  
          long long tmp2 = (ruisekiwa[i - l] - ruisekiwa[i - r - 1] + MOD) % MOD;
          tmp += tmp2;
        }
        tmp %= MOD;
      }
    }
    //cout << "ttt " << tmp <<endl;
    ruisekiwa[i] = (ruisekiwa[i-1] + tmp + MOD) % MOD; 
    //cout << i << " " << ruisekiwa[i] <<endl;
    ruisekiwa[i] %= MOD;
  }
  cout << (ruisekiwa[N] - ruisekiwa[N-1] + MOD) % MOD <<endl;
}


Measured memory_bytes: 4776
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    int i,cnt=0; 
    cin >> a >> b >> c;
    for(i=a; i<b+1; i++){
        if(c%i==0){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1164
//解説あり

#include <iostream>
#include <cstring>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

char s[100005];

int main(void) {

    scanf("%s", s);

    int c0 = 0, c1;

    REP(i, 0, strlen(s)) if (s[i] == '0') c0++;

    c1 = strlen(s) - c0;

    int ans = 2 * min(c0, c1);

    printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>

int main(void) {
	char S[16];
	char mizuhasu[4];
	int i;
	int asumikana = 999999;
	if (scanf("%15s", S) != 1) return 1;
	for (i = 2; S[i] != '\0'; i++) {
		int tomatu;
		mizuhasu[0] = S[i - 2];
		mizuhasu[1] = S[i - 1];
		mizuhasu[2] = S[i];
		mizuhasu[3] = '\0';
		tomatu = abs(atoi(mizuhasu) - 753);
		if (tomatu < asumikana) asumikana = tomatu;
	}
	printf("%d\n", asumikana);
	return 0;
}


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

ll x, y, a, b, c;
vector<ll> p, q, r;

int main(){
    cin >> x >> y >> a >> b >> c;
    p.resize(a);
    REP(i, a){
        cin >> p.at(i);
    }
    q.resize(b);
    REP(i, b){
        cin >> q.at(i);
    }
    r.resize(c);
    REP(i, c){
        cin >> r.at(i);
    }

    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());

    REP(i, x){
        r.push_back(p.at(i));
    }
    REP(i, y){
        r.push_back(q.at(i));
    }

    sort(r.rbegin(), r.rend());
    ll ans = 0;
    REP(i, x + y){
        ans += r.at(i);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6256
#include <stdio.h>
int main(void){
    int a,b,i;
    char op;
    for(i=1;i>0;i++){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+'){
            printf("%d\n",a+b);
        }
        else if(op=='-'){
            printf("%d\n",a-b);
        }
        else if(op=='*'){
            printf("%d\n",a*b);
        }
        else if(op=='/'){
            printf("%d\n",a/b);
        }
        else if(op=='?'){
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626

typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int>	vi;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;
typedef vector<double> vd;


const int mod = 100000007;
const int inf = 100000005;
const int N = 200005, M = N;
ll i,j,idx;

void solve() {
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;

    ll cnt = 0;
    fo(i,0,n-1) {
        if(s[i] == s[i+1]) cnt++;
    }
    int f = 0;
    char c = (s[0] == 'L') ? 'R' : 'L';
    
    for(int i=0;i<n;) {
      if(!k) break;

      int ii = i;
      while(s[ii] == c && ii<n) ii++;
      if(ii != i) {
        if(ii!=n) {
            cnt+=2;
            k--;
        }
        else {
           cnt = n - 1;
           break;
        }
        i = ii;
      }
      else i++;
    }
    cout<<cnt<<"\n";
}

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

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}




Measured memory_bytes: 3688
#include<iostream>
#include<cstring>
#include<cstdio>
#define N (301010)
using namespace std;
int n,m,T[N],A[N],C[N];
int main(){
	scanf("%d %d",&n,&m);
	for (int i=1;i<=n;i++){
		int x; scanf("%d",&x);
		A[x]++; C[i]=x;
	}
	int Cur=0;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=min(A[i],i);j++)
			T[i-j+1]++;
	for (int i=1;i<=n;i++) if (!T[i]) Cur++;
	
	while (m--){
		int pos,c1,c2; 
		scanf("%d %d",&pos,&c2);
		c1=C[pos];
		
		if (A[c1]<=c1){
			T[c1-A[c1]+1]--; 
			if (!T[c1-A[c1]+1]) Cur++; 
		}
		A[c1]--;
		if (A[c2]<c2){
			T[c2-A[c2]]++;
			if (T[c2-A[c2]]==1) Cur--;
		}
		A[c2]++;  C[pos]=c2;
		printf("%d\n",Cur);
	}
}

Measured memory_bytes: 3712
#define rep(i,x) for (int i = 0; i < x; i++)
#define mod 1000000007
#define MOD 998244353
#define INF (1<<31)-1
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;


int main() {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	vector<int> ac;
	rep(i, s.size()-1) {
		if (s[i] == 'A'&&s[i + 1] == 'C') {
			ac.push_back(i+1);
		}
	}
	vector<int> ans(b);
	rep(i, b) {
		int p1, p2;
		cin >> p1 >> p2;
		int ite1 = lower_bound(ac.begin(), ac.end(), p1) - ac.begin();
		int ite2 = lower_bound(ac.begin(), ac.end(), p2) - ac.begin();
		ans[i] = ite2 - ite1;
	}
	rep(i, b) {
		cout << ans[i] << endl;
	}
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int64_t> a(n);
    for (auto &x : a) {
        cin >> x;
    }

    int odd = 0;

    for (auto x : a) {
        if (x % 2 == 1) {
            odd++;
        }
    }
    if (odd % 2 == 0) {
        cout << "YES" << endl;
    }

    else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        ArrayList<Integer> row = new ArrayList<>();
        ArrayList<Integer> col = new ArrayList<>();

        Scanner inp = new Scanner(System.in);

        int total = 0;

        int end = 1;
        while (end != 0) {
            int num1 = inp.nextInt();
            int num2 = inp.nextInt();

            if (num1 == 0 && num2 == 0) {
                end = 0;
            } else {
                row.add(num1);
                col.add(num2);

                total++;
            }
        }

        for (int i = 0; i < total; i++) {
            int ro = row.get(i);
            int co = col.get(i);

            for (int r = 0; r < ro; r++) {
                for (int c = 0; c < co; c++) {
                    System.out.print("#");
                }

                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }

}



Measured memory_bytes: 38156
#include<stdio.h>
int main(void)
{
  int r,D,x;
  int i;
  
  scanf("%d%d%d",&r,&D,&x);
  
  int array[200]={x};
  if((2<=r && r<=5) && (1<=D && D <=100) && (D<x && x<=200)){ 
  	for(i=0;i<10;i++){
      array[i+1]=r*array[i]-D;
      printf("%d ",array[i+1]);
  	}
  }
  return 0;
}

Measured memory_bytes: 128
#include<string.h>
#include<iostream>
#include<stdio.h>

int main(){
	
	int a[5],i,k;
	scanf("%d%d%d",&a[0],&a[1],&k);
	for(i=0;i<k;i++){
		a[i&1]>>=1;
		a[(i&1)^1]+=a[i&1];
	}
	printf("%d %d",a[0],a[1]);
	return 0;
}
	

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
typedef long long LL;
LL A,B,C;
LL x,y;
int main() {
    cin>>A>>B>>C>>x>>y;

    LL m=min(x,y);
    LL r=0;
    r += min(2L*C*m, (A+B)*m);

    if (x > y) {
        r += min((x-y)*A, (x-y)*2L*C);
    }
    if (y > x) {
        r += min((y-x)*B, (y-x)*2L*C);
    }
    cout << r << endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }

const int maxn = 1e6 + 11;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int x, y;
    cin >> x >> y;

    for (int i = 0; i <= x; i++) {
        int j = x-i;
        int val = i*2 + j*4;
        if (val == y) out("Yes");
    }

    out("No");
    
    
    return 0;
}


Measured memory_bytes: 3688
#include "bits/stdc++.h"
using namespace std;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int x = sx, y = sy;
    while (y != ty) {
        putchar('U');
        y++;
    }
    while (x != tx) {
        x++;
        putchar('R');
    }
    y++;
    putchar('U');
    while (x != sx - 1) {
        x--;
        putchar('L');
    }

    while (y != sy) {
        y--;
        putchar('D');
    }

    while (x != tx) {
        putchar('R');
        x++;
    }

    while(y != ty) {
        y++;
        putchar('U');
    }

    putchar('R');
    x++;
    while(y != sy - 1) {
        y--;
        putchar('D');
    }
    while(x != sx) {
        x--;
        putchar('L');
    }

    putchar('U');
    y++;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
ll n;
ll a[3005];
ll dp[3005][3005][2];
ll getans(ll find,ll flast,ll play)
{
if(find>flast)
{
	return 0;
}
if(dp[find][flast][play]!=-1)
{
	return dp[find][flast][play];
}
ll ans=0;
if(play==0)
{
ans=max(a[find]+getans(find+1,flast,1),a[flast]+getans(find,flast-1,1));
}
else
{
ans=min(-a[find]+getans(find+1,flast,0),-a[flast]+getans(find,flast-1,0));
}
return dp[find][flast][play]=ans;
}
int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
memset(dp,-1,sizeof(dp));
cin>>n;
for(int i=0;i<n;i++)
{
	cin>>a[i];
}
cout<<getans(0,n-1,0)<<endl;
}





Measured memory_bytes: 144944
#include <bits/stdc++.h>
//#define TAM 1
using namespace std;

typedef pair<int,int> pii;
const int mx = 605;

int mark[mx][mx];

vector<pii> adj[2];
vector<pii> P[4];

int D[2];
int n;

inline int dis(pii u, pii v){
    return (u.first - v.first) * (u.first - v.first) + (u.second - v.second) * (u.second - v.second);
}
void init(){
    #ifndef TAM
    cin >> n >> D[0] >> D[1];
    #endif // TAM
    #ifdef TAM
    srand((unsigned int)time(0));
    n = rand() % 300 + 1;
    D[0] = rand() * rand() % 200000 + 1;
    D[1] = rand() * rand() % 200000 + 1;
    printf("n = %d, D[0] = %d, D[1] = %d\n",n,D[0],D[1]);
    #endif // TAM
    for(int i = 0; i < 2 * n; i++) fill(mark[i],mark[i] + 2*n, -1);

    for(int b = 0; b < 2; b++){
        for(int i = (int)(sqrt(D[b])+1e-9); i >= 0; i--){
            for(int j = i; j >= 0; j--){
                if(i * i + j * j == D[b]){
                    adj[b].emplace_back(i,j);
                    adj[b].emplace_back(j,i);
                    adj[b].emplace_back(-i,j);
                    adj[b].emplace_back(j,-i);
                    adj[b].emplace_back(i,-j);
                    adj[b].emplace_back(-j,i);
                    adj[b].emplace_back(-i,-j);
                    adj[b].emplace_back(-j,-i);

                    break;
                }
            }
        }

        sort(adj[b].begin(),adj[b].end());
        adj[b].erase(unique(adj[b].begin(),adj[b].end()),adj[b].end());
/*
        for(pii &p : adj[b]){
            cout << p.first << ' ' << p.second << '\n';
        }
        cout << "-----------\n";
*/
    }
}

void dfs(int r, int c, int ty, int v, int tog, int bv){
    mark[r][c] = v;
    P[v].emplace_back(r,c);
    int nr, nc;
    for(pii &p : adj[ty]){
        nr = r + p.first;
        nc = c + p.second;
        if(nr < 0 || nr >= 2 * n || nc < 0 || nc >= 2 * n) continue;
        if(mark[nr][nc] != bv) continue;
        dfs(nr,nc,ty,tog,v,bv);
    }
}

void pro(){
    for(int i = 0; i < 2*n; i++){
        for(int j = 0; j < 2*n; j++){
            if(mark[i][j] != -1) continue;
            dfs(i,j,0,0,1,-1);
        }
    }
    int dom = (P[1].size() >= P[0].size() ? 1 : 0);
    for(pii &p : P[dom]){
        if(mark[p.first][p.second] != dom) continue;
        dfs(p.first,p.second,1,2,3,dom);
    }
    int ddom = (P[3].size() >= P[2].size() ? 3 : 2);

    assert(P[ddom].size() >= n * n);
    int C = n * n;
#ifdef TAM
    for(int i = 0; i < C; i++){
        for(int j = i+1; j < C; j++){
            int T = dis(P[ddom][i], P[ddom][j]);
            assert(T != D[0] && T != D[1]);
        }
    }
#endif
#ifndef TAM
    for(int i = 0; i < C; i++){
        cout << P[ddom][i].first << ' ' << P[ddom][i].second << '\n';
    }
#endif // TAM
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    init();
    pro();
}


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

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  int N;
  while(cin >> N,N){
	vector<string> vs(N);
	VI top(N);
	REP(i,N) cin>>vs[i];
	for(int y=0;y<N;++y){
	  for(int x=0;x<SZ(vs[y]);++x){
		if(vs[y][x] != '.'){
		  if(x != 0) vs[y][x-1] = '+';
		  top[y] = x-1;
		  break;
		}
		vs[y][x] = ' ';
	  }
	}
	for(int y=1;y<N;++y){
	  int x = top[y];
	  for(int ty=y+1;ty<N;++ty){
		if(SZ(vs[ty]) <= x) break;
		if(vs[ty][x] == '+'){
		  for(--ty;y<ty;--ty)
			vs[ty][x] = '|';
		  break;
		}
		if(vs[ty][x] != ' ') break;
	  }
	}

	REP(i,N)
	  cout << vs[i] << endl;
  }  

  return 0;
}

Measured memory_bytes: 1788
n, m = map(int, input().split())
price = list(map(int, input().split()))

#dp[i][j]をi番目まででj支払える最小枚数
dp = [[float("inf")] * (n+1) for _ in range(m+1)]

for _ in range(m+1):
    dp[_][0] = 0

for i in range(1,m+1):
    for j in range(1,n+1):
        if j >= price[i-1]:
            dp[i][j] = min(dp[i-1][j], dp[i][j-price[i-1]]+1)
        else:
            dp[i][j] = dp[i-1][j]
print(dp[m][n])



Measured memory_bytes: 43740
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>
#include<cmath>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

int main(){

    int A,B;
    cin>>A>>B;
    vector <int> v;
    rep(i,0,100000){
        if(int(i*1.08)-i == A){
            v.PB(i);
        }
    }
    rep(i,0,100000){
        if(int(i*1.1)-i == B){
            rep(j,0,v.size()){
                if(v[j] == i){
                cout<<i;
                return 0;
                }
            }
        }
    }
    cout<<-1;

    return 0;
}

Measured memory_bytes: 256
def ceil(n, c)
  r = n % c
  n -= r
  n += c if r > 0
  n.to_i
end

def forecast(week)
  loan = 10_0000.0
  
  week.times do
    loan = ceil(loan * 1.05, 1000)
  end
  
  loan
end

puts forecast gets.to_i

Measured memory_bytes: 6112
import java.util.Scanner;//入力を取得する(Scanner)

class Main {
        public static void main(String arts[]) {
											 int N;
											 Scanner sc = new Scanner(System.in);
											 N = sc.nextInt();

											 int target;
											 target = (N+1) / 2;// kiriage
											 double n = N;

											 System.out.println(target / n );
               }
		}


Measured memory_bytes: 22996
import java.io.*;
import java.util.*;
public class Main {
   public static void main(String args[]) {
       int n = 0;
       int[][] arr = null;
       try (Scanner scanner = new Scanner(System.in)) {
           n = scanner.nextInt();
        //   k = scanner.nextInt();
           arr = new int[n][3];
           for (int i=0; i < n; i++) {
               for(int j = 0; j < 3; j++) 
                arr[i][j] = scanner.nextInt();
           }
       }
       int[][] dp = new int[n][3];
       dp[0][0] = arr[0][0];
       dp[0][1] = arr[0][1];
       dp[0][2] = arr[0][2];
       for(int i = 1; i < n ; i++) {
           dp[i][0] = Math.max(dp[i-1][0], Math.max(dp[i-1][1], dp[i-1][2]) + arr[i][0]);
           dp[i][1] = Math.max(dp[i-1][1], Math.max(dp[i-1][0], dp[i-1][2]) + arr[i][1]);
           dp[i][2] = Math.max(dp[i-1][2], Math.max(dp[i-1][0], dp[i-1][1]) + arr[i][2]);
       }

    //   System.out.println(Arrays.toString(dp));
        int ret = 0;
        for(int j = 0; j < 3; j++) {
            ret = Math.max(dp[n-1][j], ret);
        }
       System.out.println(ret);
   }
}


Measured memory_bytes: 99024
s = input()
t = input()
length_s = len(s)
length_t = len(t)
count = 0
  
for n in range(length_s):
  if s[n] == t[n]:
      count += 1

if count == length_s and length_s + 1 == length_t:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9116
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
s = 0
m = 1
for i in range(60):
    c = sum(ai & m for ai in a)
    c //= m
    s = (s + m*c*(n-c))%MOD
    m <<= 1
print(s)

Measured memory_bytes: 42156
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, t;
	cin >> n >> t;
	vi a(n);
	rep(i, n) cin >> a[i];
	int cur = 0;
	int mn = 1e9;
	int ans = 0;
	rep(i, n){
		if((a[i] - mn) > cur) ans = 1, cur = a[i] - mn;
		else if((a[i] - mn) == cur) ans++;
		mn = min(mn, a[i]);
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#pragma GCC optimize(3)   
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define rep(i,n) for(int i=0 ; i<n ; i++)
#define llv vector< ll >
#define mp make_pair
#define endl "\n"
#define N (ll)2e5+10
#define M (ll)1e18 
#define matrix vector<vector<ll> >
#define sz(x) (int)x.size()
 

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    // ios::sync_with_stdio(0);
    
    int n ;
    cin >> n ;
    map<string , int > m ;
    string s ;

    for(int i=0 ; i<n ; i++){
          cin >> s ;
          m[s]++ ;
    }
    cout << "AC x " << m["AC"] << endl ;
    cout << "WA x " << m["WA"] << endl ;
    cout << "TLE x " << m["TLE"] << endl ;
    cout << "RE x " << m["RE"] << endl ;  
     return 0 ;
    
    
 }

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

using namespace std;

vector<long long> v, w;
vector<vector<long long>> dp;

int main(void) {
	long n, W;

	cin >> n >> W;

	dp = vector<vector<long long>>(n+1, vector<long long>(W+1));
	w = v = vector<long long>(n);
	for (long i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}
	for (long i = 0; i <= W; i++) {
		dp[0][i] = 0;
	}
	for (long i = 0; i < n; i++) {
		for (long j = 1; j <= W; j++) {
			if (w[i] <= j) {
				dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
			}
			else {
				dp[i + 1][j] = dp[i][j];
			}
		}
	}
	cout << dp[n][W] << endl;
	return 0;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)

int main() {
  
  //input
  inputInt(N);
  inputIntArray(a,N);
  
  //main
  int total = 0;
  vector<int> ans(N,0);
  
  for(int i=N; i>0; i--){
    int counter = 0;
    for(int j=2; i*j<=N; j++) {
      counter += ans[i*j-1];
    }
    if(counter%2 == a[i-1]){
      ans[i-1] = 0;
    }else{
      ans[i-1] = 1;
      total ++;
    }
  }
  
  // 出力
  output(total);
  fN(i,N) if(ans[i] == 1) cout << i+1 << " ";
  cout << endl;
    
  return 0;
}


Measured memory_bytes: 2432
import java.util.*;
public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    String ans = "NO";
    for(int i=0;i<=100;i++){
      if(A*i%B==C){
        ans="YES";
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23508
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(){
    ll x; cin >> x;
    for(ll i=0;i <= x;i++){
        if(i * (i + 1) >= 2 * x){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,x;
	int cnt[200010] = {0};
	cin >> n;
	for(int i = 1; i < n; i++) {
		cin >> x;
		cnt[x]++;
	}
	for(int i = 1; i <= n; i++) {
		cout << cnt[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 4364
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

#include <complex>
typedef complex<double> P;

struct L {
	P a, b;
	L(const P &a, const P &b) : a(a), b(b) { }
};

struct C {
	P p; double r;
	C(const P p, double r) : p(p), r(r) { }
};

double dot(P a, P b) {
	return real(conj(a)*b);
}

double cross(P a, P b) {
	return imag(conj(a)*b);
}

bool LLcross(L l1, L l2) {
	return abs(cross(l1.b-l1.a, l2.b-l2.a)) > EPS || abs(cross(l1.b-l1.a, l2.b-l1.a)) < EPS;
}

double dist(P p1, P p2) {
	return sqrt((p2.real()-p1.real())*(p2.real()-p1.real()) + (p2.imag()-p1.imag())*(p2.imag()-p1.imag()));
}

const int UE	 = 1;
const int MIGI	 = 2;
const int SHITA  = 4;
const int HIDARI = 8;
const int CHECK  = 16;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int dk[] = {UE, MIGI, SHITA, HIDARI};

struct state {
	int x, y, t;
	state(int x, int y, int t) : x(x), y(y), t(t) {};
};

int main() {
	int w, h;

	while(cin >> w >> h, w) {
		vvi field(h, vi(w));
		
		REP(i, w) {
			field[0][i] += UE;
			field[h-1][i] += SHITA;
		}
		
		REP(i, h) {
			field[i][0] += HIDARI;
			field[i][w-1] += MIGI;
		}

		int tmp;
		REP(i, 2*h-1) {
			if(i%2 == 0) {
				REP(j, w-1) {
					cin >> tmp;
					if(tmp) {
						field[i/2][j] += MIGI;
						field[i/2][j+1] += HIDARI;
					}
				}
			} else {
				REP(j, w) {
					cin >> tmp;
					if(tmp) {
						field[i/2][j] += SHITA;
						field[i/2+1][j] += UE;
					}
				}
			}
		}

		queue<state> Q;
		Q.push(state(0, 0, 1));
		field[0][0] += CHECK;

		int ans = 0;
		while(!Q.empty()) {
			state s = Q.front();
			Q.pop();
			if(s.x == h-1 && s.y == w-1) {
				ans = s.t;
				goto out;
			}

			REP(d, 4) {
				if(field[s.x][s.y] & dk[d]) {

				} else {
					if(!(field[s.x+dx[d]][s.y+dy[d]] & CHECK)) {
						Q.push(state(s.x+dx[d], s.y+dy[d], s.t+1));
						field[s.x+dx[d]][s.y+dy[d]] += CHECK;
					}
				}
			}
		}

out:
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1228
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tenka1_2019
{
    class B
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            int k= int.Parse(Console.ReadLine());
            char chr = s[k-1];
            string ans = "";
            for (int i = 0; i < n; i++)
            {
                if (s[i] == chr) { ans += chr; }
                else { ans += "*"; }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
import java.util.Scanner;
public class Main {

  public static void main(String[] args){
    Scanner a = new Scanner(System.in);
    
    int A1 = a.nextInt();
    int A2 = a.nextInt();
    int A3 = a.nextInt();

    if (A1+A2+A3>=22){
      System.out.println("bust");
    }else{
      System.out.println("win");
    }
  }
}


Measured memory_bytes: 20948
L, R = [int(i) for i in input().split()]

c = set()

for i in range(L, R + 1):
  t = i % 2019
  if t in c:
    break
  c.add(t)


m = float('inf')
l = list(c)
for i in range(len(l)):
  for j in range(i + 1, len(l)):
    m = min(m, l[i] * l[j] % 2019)

print(m)


Measured memory_bytes: 9184
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int X = in.nextInt();
		int[] m = new int[N] ;
		for(int i=0;i<N;i++) {
			 m[i] = in.nextInt();
		}
		int min =1001;
		int sum=0;
		for(int i=0;i<N;i++) {
			sum+=m[i];
			min=Math.min(min, m[i]);
		}
		int a=(X-sum)/min;
		int ans=a+N;
		System.out.println(ans);
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define MAXN 25
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(c) (c).begin(), (c).end()
using namespace std;

ll h, w, sol;
char a[MAXN][MAXN];
queue<pair<ll, ll> > pos;
queue <ll> dis;
ll visited[MAXN][MAXN];

int bfs(ll x, ll y) {
	pos.push(mp(x, y)); ll d = 0; dis.push(0);
	while (dis.size()) {
		x = pos.front().F; y = pos.front().S; d = dis.front();
		pos.pop(); dis.pop();
		if (visited[x][y] or a[x][y] == '#') continue;
		visited[x][y] = 1;
		if (x > 1) {pos.push(mp(x - 1, y)); dis.push(d + 1);}
		if (y < w) {pos.push(mp(x, y + 1)); dis.push(d + 1);}
		if (x < h) {pos.push(mp(x + 1, y)); dis.push(d + 1);}
		if (y > 1) {pos.push(mp(x, y - 1)); dis.push(d + 1);}
	}	
	return d - 1;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	
	cin >> h >> w;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; ++j) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; j++) {
			int temp = bfs(i, j);
			if (temp > sol) sol = temp;
			memset(visited, 0, sizeof(visited[0][0]) * MAXN * MAXN);
		}
	cout << sol;	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
 
using namespace std;

int main(){
    int time = 0;
    vector<int> T;
    int mi = 9;

    for(int i = 0; i < 5; i++){
        int t;
        cin >> t;

        if(t%10 < mi && t%10 != 0){
            T.push_back(t);
            mi = t%10;
        }else{
            T.insert(T.begin(), t);
        }
    }

    for(int i = 0; i < 5; i++){
        if(time % 10 != 0){
            time += 10 - time%10;
        }
        time += T[i];
    }

    cout << time << endl;

    return 0;
}

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

using namespace std;

int main() {
	string S;
	cin >> S;
	string ans;

	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'B') {
			if (ans.size()) {
				ans.pop_back();
			}
		}
		else {
			ans += S[i];
		}
	}

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

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

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.length();
  while(n--){
  	char p = s[s.length()-1];
    s.erase(s.length()-1, s.length()-1);
    s = p + s;
	if(s == t){
    	cout << "Yes" << endl;
      	return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    int l, r = N;
    l = max(0, (int)count(A.begin(), A.end(), 1)-1);
    while (r-l > 1) {
        int c = (19*l+r+18)/20;
        map<int, int> mp;
        for (int i = 1; i < N; i++) {
            if (A[i-1] >= A[i]) {
                if (c == 1) {
                    mp[0] = 1;
                    break;
                }
                int t = A[i];
                mp[t]++;
                auto it = mp.upper_bound(t);
                mp.erase(it, mp.end());
                while (t > 0 && mp[t] == c) {
                    mp[t] = 0;
                    mp[t-1]++;
                    t--;
                }
            }
            if (mp[0] > 0) break;
        }
        if (mp[0] == 0) r = c;
        else l = c;
    }
    cout << r << endl;
    return 0;
}


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

int main() {
  int n,d,a;
  cin>>n>>d>>a;
  vector<vector<ll>> x(n,vector<ll>(2));
  rep(i,n) {
    rep(j,2){
      cin >> x.at(i).at(j);
    }
  }
  sort(x.begin(),x.end());
  vector<ll>y(n),z(n);
  rep(i,n){
    y.at(i)=x.at(i).at(0);
    z.at(i)=x.at(i).at(1);
  }
  ll ans=0;
  ll co=0;
  queue<P>q;
  rep(i,n){
    while(q.size()&&q.front().first<y.at(i)){
      co-=q.front().second;
      q.pop();
    }
    z.at(i)-=co;
    if(z.at(i)>0){
      ans+=(z.at(i)+a-1)/a;
      co+=((z.at(i)+a-1)/a)*a;
      q.push(P(y.at(i)+2*d,((z.at(i)+a-1)/a)*a));
    }
  }  
  cout<<ans<<endl;  
}

Measured memory_bytes: 19024
A,B,M = map(int, input().split())
price_A = list(map(int, input().split()))
price_B = list(map(int, input().split()))
discounts = [list(map(int, input().split())) for i in range(M)]
ans_candidate = min(price_A) + min(price_B)

for discount in discounts:
    tmp_ans = price_A[discount[0]-1] + price_B[discount[1]-1] - discount[2]
    if tmp_ans <= ans_candidate:
        ans_candidate = tmp_ans

print(ans_candidate)

Measured memory_bytes: 38488
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n+1)

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}


N, M = map(int, input().split())
Union = UnionFind(N)
bad_value = N*(N-1)//2
bridge = []
for i in range(M):
    a, b = map(int, input().split())
    bridge.append((a, b))
bridge.reverse()
ans = [bad_value]
for a, b in bridge:
    if Union.same(a, b):
        Union.union(a, b)
        ans.append(bad_value)
        continue
    else:
        X = Union.size(a)
        Y = Union.size(b)
        Union.union(a, b)
        bad_value -= X*Y
        ans.append(bad_value)
        continue
ans.reverse()
for i in range(1, M+1):
    print(ans[i])

Measured memory_bytes: 27244
x, y = map(int, input().split())
A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
C = [2]
if x in A and y in A:
    print("Yes")
elif x in B and y in B:
    print("Yes")
elif x in C and y in C:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <cstdio>

const int MAXN = 100;
const char FINISHED = '.';
const int STEP_NUM = 4;
const int STEP[STEP_NUM][STEP_NUM] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

int h, w;
char fruit_map[MAXN + 1][MAXN + 1];

void DFS(int x, int y) {
    char fruit = fruit_map[x][y];
    fruit_map[x][y] = FINISHED;
    for (int i = 0; i < STEP_NUM; i++) {
        int newx = x + STEP[i][0];
        int newy = y + STEP[i][1];
        if (0 <= newx && newx < h && 0 <= newy && newy < w
            && fruit_map[newx][newy] == fruit) {
            DFS(newx, newy);
        }
    }
}

int main() {
    scanf("%d %d", &h, &w);
    while (h * w != 0) {
        int districts = 0;
        for (int i = 0; i < h; i++) {
            scanf("%s", fruit_map[i]);
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (fruit_map[i][j] != FINISHED) {
                    DFS(i, j);
                    districts++;
                }
            }
        }
        printf("%d\n", districts);
        scanf("%d %d", &h, &w);
    }

    return 0;
}

Measured memory_bytes: 3080
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Char

main = do
    n <- readLn :: IO Int
    xs <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    print $ VU.foldl' (\a x -> a + x - 1) 0 xs
     

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

int main()
{
    long long int n;
    cin >> n;
    vector<long long int > v;
    for(long long int i=0;i<n;i++)
    {
        long long int k;
        cin >> k;
        v.push_back(k);
    }
    long long int dp[n+1]={0};
    dp[1]=0;
    dp[2]=abs(v[0]-v[1]);
    for(long long int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(v[i-1]-v[i-2]),dp[i-2]+abs(v[i-1]-v[i-3]));
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1908
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        System.out.print(a*b + " ");
        System.out.println(2*(a+b));
    }
}


Measured memory_bytes: 26084
import java.util.*;
import java.util.Collections;

import org.omg.CORBA.BAD_INV_ORDER;

import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    int[] B = new int[N];
    int[] C = new int[N - 1];
    int total = 0;

    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    for (int i = 0; i < N; i++) {
      total += sc.nextInt();
    }
    for (int i = 0; i < N - 1; i++) {
      C[i] = sc.nextInt();
    }
    for (int i = 1; i < N; i++) {
      if (A[i] - 1 == A[i - 1]) {
        total += C[A[i - 1] - 1];
      }
    }
    System.out.println(total);
  }
}


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

using namespace std;

int main(){
	int n;
	cin>>n;
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			if(i*j == n){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ((A + B) < (C + D)) {
    cout << "Right" << endl;
  }
  else if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll x, y;
    cin>>x>>y;

    ll ans = 0;
    if(x == y){
        ans = 0;
    }else if(x == -y){
        ans += 1;
    }else if(abs(x) > abs(y)){
        ans += abs(x) - abs(y);
        if(x > 0){
            ans++;
        }
        if(y > 0){
            ans++;
        }
    }else{
        ans += abs(abs(x) - abs(y));
        if(x < 0){
            ans++;
        }
        if(y < 0){
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int n,a[100];
cin >> n;
for(int z=0; z<n; z++){
cin >> a[z];
}
for(int z=n-1; z>=0; z--){
if(z!=n-1) cout <<" ";
cout << a[z];
}
cout <<endl;
return 0;
}


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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N;
    std::cin >> N;
    string S;
    std::cin >> S;

    vector<vector<int>> dp(N, vector<int>(10, -1));
    REP(i, S.size()) {
        if(i != 0) {
            REP(j, 10) {
                dp[N - i - 1][j] = dp[N - i][j];
            }
        }
        dp[N - i - 1][(S[N - i - 1] - '0')] = N - i - 1;
    }

    set<string> ans_set;
    REP(i, N - 2) {
        REP(j, 10) {
            if(dp[i + 1][j] == -1 || dp[i + 1][j] <= i) continue;
            REP(k, 10) {
                if(dp[i + 1][j] == N - 1 ||
                   dp[dp[i + 1][j] + 1][k] == -1 ||
                   dp[dp[i + 1][j] + 1][k] <= dp[i + 1][j]) continue;
                char ss = '0' + j;
                char s  = '0' + k;
                ans_set.emplace(string{S[i], ss, s});
           }
        }
    }
    std::cout << ans_set.size() << std::endl;

    return 0;
}


Measured memory_bytes: 2560