akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n;
int dp[110][4][4][4];
bool vis[110][4][4][4];
const int A = 0, C = 1, G = 2, T = 3;

int solve(int pos, int c1, int c2, int c3)
{
    if (vis[pos][c1][c2][c3])
        return dp[pos][c1][c2][c3];
    vis[pos][c1][c2][c3] = true;
    if (pos == n)
        return dp[pos][c1][c2][c3] = 1;
    bool use[4];
    rep(i, 4) use[i] = true;
    if (c2 == A && c3 == G)
        use[C] = false;
    if (c2 == G && c3 == A)
        use[C] = false;
    if (c2 == A && c3 == C)
        use[G] = false;
    if (c1 == A && c3 == G)
        use[C] = false;
    if (c1 == A && c2 == G)
        use[C] = false;
    rep(i, 4) if (use[i])(dp[pos][c1][c2][c3] += solve(pos + 1, c2, c3, i)) %= mod;
    return dp[pos][c1][c2][c3];
}

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

    cin >> n;
    cout << solve(0, T, T, T) << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int a, b;
    cin>>a>>b;
    if(a<=8 && b<=8){
        cout<<"Yay!"<<endl;
    }
    else cout<<":("<<endl;
    return 0;
}

Measured memory_bytes: 256
H, W, D = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
Q = int(input())
pos = [None]*(H*W+1)
for i, elem in enumerate(A):
    for j, a in enumerate(elem):
        pos[a] = (i, j)
acc = [[] for _ in range(D+1)]
for i in range(1, D+1):
    tmp = i
    s = 0
    acc[i].append(s)
    while tmp <= H*W-D:
        s += abs(pos[tmp][0]-pos[tmp+D][0])+abs(pos[tmp][1]-pos[tmp+D][1])
        acc[i].append(s)
        tmp += D

for _ in range(Q):
    L, R = map(int, input().split())
    print(acc[(R-1) % D+1][(R-R % D)//D-(R % D == 0)] -
          acc[(R-1) % D+1][(L-L % D)//D-(L % D == 0)])


Measured memory_bytes: 24240
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);

    int n;
    cin >> n;

    double ans;

    if(n % 2 == 0)
        ans = 0.50000000;
    else if(n == 1)
        ans = 1.0000000;
    else
    {
        ans = double(n/2 + 1) / double(n);
    }


    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int n,a[N],tot,head[N],nex[N*10],to[N*10];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
bool vis[N];
int main()
{
    for(int i=2;i<=1000000;i++)
        if(!vis[i])
    {
        for(int j=i;j<=1000000;j+=i)
            vis[j]=true,add(j,i);
    }
    scanf("%d",&n);
    int ans=0;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]),ans=__gcd(a[i],ans);
    if(ans!=1) printf("not coprime\n");
    else
    {
        memset(vis,false,sizeof(vis));
        bool flag=false;
        for(int i=1;i<=n&&!flag;i++)
            for(int j=head[a[i]];j&&!flag;j=nex[j])
        {
            if(vis[to[j]]) flag=true;
            vis[to[j]]=true;
        }
        if(flag) printf("setwise coprime\n");
        else printf("pairwise coprime\n");
    }
}


Measured memory_bytes: 34668
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin>>n;
    vector<int>L(n*2);
    for(int i=0;i<n*2;i++){
        cin>>L[i];
    }
    sort(L.begin(),L.end());
    int ans=0;
    for(int i=0;i<n*2;i++){
        if(i%2==0){
            ans+=L[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, c;
    cin >> a >> b >> c;
    
    if ((a == b) && (b == c)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>//aoj642
using namespace std;
int main(void)
{
	int i,n,a,x=0,y=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a;
		if(a==0) x=0;
		if(a==1) x=x+1;
		if(y<x) y=x;
	}
	y=y+1;
	cout<<y<<endl;
	return 0;
}


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

int main() {
  int s;
  cin >> s;
  int count = 4;
  int a = s;
  if(s!=1 && s!= 2 && s!= 4){
   for(count = 5; count < 10000000; count ++){
      if(a%2==0) a=a/2;
      else a=3*a+1;
     
     if(a==4)break;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdlib>
#include <istream>
#include <set>
#define rep0(i,n) for (long long int i = 0; i <= (n); ++i)
#define rep1(i,n) for (long long int i = 1; i <= (n); ++i)
#define REP(a,b) for (long long int i = a; i <= (b); ++i) 
#define MOD 100000007
#define ps push_back 
using namespace std;
typedef long long ll;
int main() {
	int a, b, k;
	cin >> a >> b >> k;
	vector<int>as(1000);
	REP(1, 100) {
		if(a % i == 0)
			if (b % i == 0) {
				as.push_back(i);
			}
	}
	sort(as.rbegin(), as.rend());
	cout << as[k - 1] << endl;
	return 0;
}

Measured memory_bytes: 888
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N, K;
    cin >> N >> K;
    if (K % 2 == 1) {
        print((ll)pow(N / K, 3));
    } else {
        ll cnt = 0;
        rep(i, N) {
            if ((i + 1) % K == K / 2) cnt++;
        }
        print((ll)pow(N / K, 3) + (ll)pow(cnt, 3));
    }
    return 0;
}

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

using namespace std;

int n,m;

int main(){
	cin>>n>>m;
	if ((n>=0&&m>=0)||(n<=0&&m<=0)){
		if (n<=m) cout<<m-n;
		else cout<<n-m+2-(!m)-(!n);
	} else{
		cout<<abs(m+n)+1;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long ll;
#define N 100005
//week_9_A
void relocate(ll a[], int len)
{
    int fath = 0;
    ll val;
    while(1)
    {
        int son = fath*2+1;
        val = a[fath];
        if(son+1 < len && a[son] < a[son+1])
            son++;
        if( val < a[son] )
        {
            a[fath] = a[son];
            a[son] = val;
            fath = son;
        }
        else if (val >= a[son])
            break;
    }
}
void shiftdown(ll a[], int fath, int len)
{
    int ffath = fath;
    ll val = a[fath];
    int son = ffath*2 + 1;
    while(son < len)
    {
        if(son+1 < len && a[son] < a[son+1])
            son++;
        if(val < a[son])
        {
            a[ffath] = a[son];
            a[son] = val;
            ffath = son;
        }
        else
            break;
        son = ffath*2+1;
    }
}

void week_9_A()
{
    static ll a[100005];
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int fath = (n-2)/2; fath >= 0; fath--)
        shiftdown(a, fath, n);
//    for (int i = 0; i < n ; i++)
//        cout << a[i] << " ";
    for (int i = 0; i < m; i++)
    {
        a[0] /= 2;
        shiftdown(a, 0, n);
    }
    ll ans = 0;
    for (int i = 0; i < n; i ++)
        ans += a[i];
    cout << ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    week_9_A();
}

Measured memory_bytes: 1024
import math
N,D=map(int,input().split())
X=[list(map(int,input().split())) for _ in range(N)]

cnt=0
for i in range(N):
    if math.sqrt(X[i][0]*X[i][0]+X[i][1]*X[i][1])<=D:
        cnt+=1

print(cnt)

Measured memory_bytes: 45464
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;


int main(){
    int K,X;
    cin>>K>>X;

    for(int i=X-K+1;i<=X+K-2;i++){
        cout<<i<<" ";
    }
    cout<<X+K-1<<endl;

    return 0;
}

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

string replaceAll(string s, string f, string t) {
  string r;
  for (int p = 0; (p = s.find(f)) != s.npos; ) {
    r += s.substr(0, p) + t;
    s = s.substr(p + f.size());
  }
  return r + s;
}

int main(){
  string s;
  int n;
  cin>>n;
  getline(cin,s);
  while(n--){
    getline(cin,s);
    cout<<replaceAll(s,string("Hoshino"),string("Hoshina"))<<endl;
  }
}

Measured memory_bytes: 0
import collections
n = int(raw_input())
def g( a, b , n):
	count = 0
	## CASE 1
	if a == b and a <=n : 
		count +=1
	## CASE 2
	if a *10 + b <= n:
		count +=1
	
	if len(str(n)) <=2:
		return count

	## CASE 3
	s = str(n)
	if len(s) - 3 >= 1:
		count += 10 ** (len(s) - 3)

	## CASE 4

	s = str(n)
	if a == int(s[0]):
		m = s[1:-1]

		if m != '':

			#0,m-1
			count += int(m)
			if b <= int(s[-1]):
				count +=1
	elif a < int(s[0]):
		count += 10 ** (len(s) - 2)

	return count


h = collections.Counter()
for k in range(1, n+1):
	ks = str(k)
	a,b = int(ks[0]), int(ks[-1])
	h[(a,b)] +=1
s= 0
for a in range(1,10):
	for b in range(1,10):
		s += h[(a,b)] * h[(b,a)]

print s


Measured memory_bytes: 32796
#include <stdio.h>

int main(void)
{
        int a[3],s,i;

        for(i=0;i<3;i++)
                scanf("%d",&a[i]);

        if(a[0]>=a[1] && a[0]>=a[2]) printf("%d\n",a[0]*10+a[1]+a[2]);
        else if(a[0]<=a[1] && a[1]>=a[2]) printf("%d\n",a[1]*10+a[0]+a[2]);
        else printf("%d\n",a[2]*10+a[0]+a[1]);
        return 0;
}


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

int main() {
  int N;
  cin >> N;
  priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t>>, greater<pair<int64_t, int64_t>>> data;
  for(int i = 0; i < N; i++) {
    int64_t a, b;
    cin >> a >> b;
    data.push(make_pair(b, a));
  }
  int64_t sum = 0;
  for(int i = 0; i < N; i++) {
    int64_t B = data.top().first;
    int64_t A = data.top().second;
    sum += A;
    data.pop();
    if(B < sum) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 7436
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
#define INF 114514
using namespace std;



int main(){
	while (1) {
		int i, j, count = -1, k;
		cin >> i >> j;
		if (i == 0 && j == 0) return 0;
		for (k = 1; k <= i - 1; k++) {
			if (k == 4 || k == 6 || k == 9 || k == 11) count += 30;
			else if (k == 2) count += 29;
			else count += 31;
		}
		count += j;
		count = count % 7;
		switch (count) {
		case 0:
			cout << "Thursday" << endl;
			break;
		case 1:
			cout << "Friday" << endl;
			break;
		case 2:
			cout << "Saturday" << endl;
			break;
		case 3:
			cout << "Sunday" << endl;
			break;
		case 4:
			cout << "Monday" << endl;
			break;
		case 5:
			cout << "Tuesday" << endl;
			break;
		case 6:
			cout << "Wednesday" << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3076
import java.util.Scanner;


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 result[] = new int[N];
		int sum = 0;
		for (int i=0;i<N;i++) {
			A[i] =sc.nextInt();
			sum +=A[i];
		}
		int temp =0;
		for (int i=1;i<N;i+=2) {
			temp +=A[i];
		}
		result[0] = sum -temp*2;
		for (int i=1;i<N;i++) {
			result[i] = A[i-1]*2-result[i-1];
		}
		for (int i=0;i<N;i++) {
			System.out.println(result[i]);
		}
	}
}

Measured memory_bytes: 70428
import java.util.Scanner

object Main {
  def solve(N: Int, A: Array[Int]): Long = {
    var s = 0
    var t = 0
    var res: Long = 0
    var sum: Long = A(0)
    var xor: Long = A(0)

    while(s < N) {
      while(t < N && sum == xor) {
        t += 1
        if (t < N) {
          sum += A(t)
          xor ^= A(t)
        }
      }
      res += t - s
      sum -= A(s)
      xor ^= A(s)
      s += 1
    }
    res
  }

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val A = Array.fill(N)(sc.nextInt())
    println(solve(N, A))
  }
}


Measured memory_bytes: 72592
import sys
 
N = int(input())
 
A =[ [0 for i in range(2)]for i in range(20)]
 
if N < 20:
    for i in range(N):

        print(i)
        print("", flush=True)
    
    S = input()
    if S == 'Vacant':
        sys.exit()
 
else:
    nS = 0
    nE = N - 1
    
    nQ = 0 
    print(nQ)
    print("", flush=True) 
    S = input()
    if S == 'Vacant':
        sys.exit()
 
 
    nQ = N - 1
    print(nQ)
    print("", flush=True)
    E = input()
    if E == 'Vacant':
        sys.exit()
 
    for i in range(20):
        nQ = ( nS + nE ) // 2
        print(nQ)
        print("", flush=True)
    
        S1 = input()
        if S1 == 'Vacant':
            sys.exit()
 
        nT2 = (nQ - nS) % 2
 
        if ( nT2 != 0 ) and ( S ==S1 ):
            E = S1
            nE = nQ
        elif ( nT2 == 0 ) and ( S !=S1 ):
            E = S1
            nE = nQ
        elif ( nT2 != 0 ) and ( S !=S1 ):
            S = S1
            nS = nQ
        elif ( nT2 == 0 ) and ( S ==S1 ):
            S = S1
            nS = nQ


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
//#define lb lower_bound
//#define ub upper_bound
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>
#define mvl map<lli, vl>
#define vt vector<pair<ll, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
int main()
{
 //	ios::sync_with_stdio(0);
 //   cin.tie(0);
    vl a;
    a.pb(0);a.pb(0);a.pb(0);a.pb(0);
    for(lli i=0;i<3;i++){
    	lli x,y;
    	cin>>x>>y;
    	a[x-1]++;a[y-1]++;
	}
    sort(a.begin(),a.end());
    bool ans=false;
   if(a[0]==1 && a[1]==1 && a[2]==2 && a[3]==2)ans=true;
    if(ans)cout<<"YES";else cout<<"NO";
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
#define MAX_N 100
#define INF 1e8
 
int main(){
  int N,i,j,k,l,q,r[MAX_N],c[MAX_N],p[MAX_N+1];
  int dp[MAX_N+1][MAX_N+1];
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d%d",&r[i],&c[i]);
  }
  p[0] = r[0];
  for(i = 1 ; i <= N ; i++){
    p[i] = c[i-1];
  }
  N++;
  for(i = 0 ; i < N ; i++){
    dp[i][i] = 0;
  }
  for(l = 2 ; l < N ; l++){
    for(i = 1 ; i < N-l+1 ; i++){
      j = i + l - 1;
      dp[i][j] = INF;
      for(k = i ; k <= j-1 ; k++){
        q = dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j];
        if(q < dp[i][j]){
          dp[i][j] = q;
        }
      }
    }
  }
  printf("%d\n",dp[1][N-1]);
  return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,x[100005],ans,sub[100000],sum;
main(){
    cin>>n>>m;
    if(n>=m){
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<m;i++)cin>>x[i];
    sort(x,x+m);
    for(int i=0;i<m-1;i++){
        sub[i]=x[i+1]-x[i];
        sum+=sub[i];
    }
    sort(sub,sub+m-1);
    for(int i=0;i<n-1;i++){
        ans+=sub[m-2-i];
    }
    cout<<sum-ans<<endl;
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
using namespace std;

int main(){
  int n,h,w,at,bt;
  cin >> n >> h >> w;
  vector<int> a,b;
  int ans = 0;
  REP(c, n){
    cin >> at >> bt;
    a.pb(at);
    b.pb(bt);
    }
  int s = a.size();
  REP(i, s){
      if(a[i] >= h && b[i] >= w) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
///not today

#include<bits/stdc++.h>
using namespace std;

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int> >

const int maxn = 1000* 100 + 5;
vector <int> aj[maxn];
int mrk[maxn], mrk_a[maxn],
a[maxn],
n,
m,
cm = 1;

void dfs(int v){
    mrk[v] = cm;
    mrk_a[a[v]] = cm;
    for(int i = 0; i < SZ(aj[v]); i ++){
        int u = aj[v][i];
        if(mrk[u] == 0){
            dfs(u);
        }
    }
}

int32_t main(){
    ios_base::sync_with_stdio;
    cin >>n >>m;
    for(int i = 0; i < n; i ++){
        cin >>a[i];
        a[i] --;
    }
    for(int i = 0; i < m; i ++){
        int x, y;
        cin >>x >>y;
        x --; y --;
        aj[x].pb(y); aj[y].pb(x);
    }
    for(int i = 0; i < n; i ++){
        if(mrk[i] == 0){
            dfs(i);
            cm ++;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i ++){
        if(mrk_a[i] == mrk[i])
            ans ++;
    }
    cout <<ans <<endl;
    return false;
}


Measured memory_bytes: 10112
#include <stdio.h>
#include <stdlib.h>
struct sta{
  int where;
  char array[1000];
};
typedef struct sta stack;
void startstack(stack *st){
  st->where=0;
  st->array[0]=0;

}
void push(stack *st,char a){
 
  st->array[++st->where]=a;
}
char top(stack *st){
  return st->array[st->where];
}
void pop(stack *st){
  st->where--;
}
void clear(char* tmp){
  int j;
  do{
    for(j=0;tmp[j];j++);
    if(tmp[--j]=='.') break;
  }while(gets(tmp));

}
int main(){
  int i,j;
  stack st;
  char tmp[1000];
  startstack(&st);
  gets(tmp);
  while(tmp[0]!='.'||tmp[1]!=0){

    for(i=0;tmp[i];i++){
    
      if(tmp[i]=='('||tmp[i]=='['){
	push(&st,tmp[i]);
   
      }
      if(tmp[i]==']'){
	if(top(&st)=='[') pop(&st);
	else {startstack(&st);
	  
	  printf("no\n");
	 clear(tmp);
	  break;}
      }
      if(tmp[i]==')'){
	if(top(&st)=='(') pop(&st);
	else {startstack(&st);
	  clear(tmp);
	  printf("no\n");
	  break;
	}
      }
      if(tmp[i]=='.'){
	if(top(&st)==0) {printf("yes\n");
	  startstack(&st);}
	else {
	     printf("no\n");
	     startstack(&st);
	     break;}
      }
      
    }
    gets(tmp);
  }
      return 0;
}

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int max_n = Math.max(a, b);
		int min_n = Math.min(a, b);
		if (c >= max_n) {
			System.out.println(min_n + " " + max_n + " " + c);
		} else if (c <= min_n) {
			System.out.println(c + " " + min_n + " " + max_n);
		} else {
			System.out.println(min_n + " " + c + " " + max_n);
		}
		sc.close();
	}

}



Measured memory_bytes: 26164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
 
namespace Sample
{
  static class Sample
  {
    static void Main()
    {
      long[] num = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
      long ans = num[0]*num[2];
      for(int i = 0; i < 2; i++){
        for(int j = 2; j < 4; j++){
          if(ans < (num[i]*num[j])){
            ans = num[i]*num[j];
          }
        }
      }
      Console.WriteLine(ans);
    }
  }
}

Measured memory_bytes: 28124
def findnum(b):
    for i in range(len(Aone)):
        if(Aone[i] == b):
            Aone[i] = 0
    for i in range(len(Atwo)):
        if(Atwo[i] == b):
            Atwo[i] = 0
    for i in range(len(Athree)):
        if(Athree[i] == b):
            Athree[i] = 0

Aone = [int(a) for a in input().split()]
Atwo = [int(a) for a in input().split()]
Athree = [int(a) for a in input().split()]
N = int(input())

for i in range(N):
    b = int(input())
    findnum(b)

if(sum(Aone)*sum(Atwo)*sum(Athree)==0):
    print("Yes")
    exit()
for i in range(3):
    if(Aone[i]+Atwo[i]+Athree[i] == 0):
        print("Yes")
        exit()
if((Aone[0]+Atwo[1]+Athree[2])*(Aone[2]+Atwo[1]+Athree[0]) == 0):
    print("Yes")
    exit()

print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

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

    // v,count
    map<int,int> mp;
    REP(_,N) {
        int A;
        cin >> A;
        if(mp.count(A) == 0) mp[A] = 0;
        mp[A]++;
    }

    vector<int> v;
    for(const auto &p: mp) v.push_back(p.second);

    sort(ALL(v));

    int types = v.size();
    int cnt = 0;
    int ind = 0;

    while (types > K) {
        cnt += v[ind];
        types--;
        ind ++;
    }

    cout << cnt << endl;

}

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

Measured memory_bytes: 13684
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int n, W; cin >> n >> W;
    vll dp(100005,inf_l);
    dp[0] = 0;
    REP(i,n+1) {
        int w, v; cin >> w >> v;
        vll dp_tmp = dp;
        rep(j,100005) {
            if (j-v >= 0) chmin(dp_tmp[j],dp[j-v]+w);
        }
        swap(dp,dp_tmp);
    }
    for (int v = 100004; v >= 0; v--) {
        if (dp[v] <= W) {
            cout << v << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto e : s) os << e; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += b % mod) %= mod; if (a < 0) a += mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

void solve() {
  int n; ll k;
  cin >> n >> k;
  vector<ll> a(n);
  cin >> a;
  vector<int> f(n);
  cin >> f;
  sort(all(a));
  sort(all(f), greater<>());
  auto binary_search = [&](ll ok, ll ng) {
    auto check = [&](ll x) {
      ll cnt = 0;
      rep(i, n) {
        if (a[i] * f[i] <= x) continue;
        ll a2 = x / f[i];
        cnt += a[i] - a2;
      }
      if (cnt <= k) return 1;
      return 0;
    };
    int d = 1;
    while (abs(ng - ok) > d) {
      ll mid = (ng + ok) / 2;
      (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
  };
  binary_search(1000000000000, -1LL);
}


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

#define int long long
#define REP(i, l, r) REPEAT(i,l,r,true) // [l, r)
#define rep(i, n) REP(i,0,n)           // [0, n)
#define REPEAT(i, l, r, condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n, l, r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...) true
#define showlr(n,l,r) true
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int, int>;

struct io {
    io() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.tie(0);
        cout << fixed << setprecision(20);
    }
} io;

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &e:v)is >> e;
    return is;
}

template<class T>
ostream &operator<<(ostream &os, vector<T> v) {
    os << "{";
    for (T &e:v)os << e << (v.size() - (int) (&e - &v[0]) > 1 ? ", " : "");
    os << "}";
    return os;
}

void _DEBUG() {}

template<typename H, typename... T>
void _DEBUG(H a, T...b) {
    cerr << a << (sizeof...(b) ? "," : "\n");
    _DEBUG(b...);
}

inline void in() {}

template<typename H, typename... T>
void in(H &a, T &... b) {
    cin >> a;
    in(b...);
}

inline void out() {}

template<typename H, typename... T>
void out(H a, T... b) {
    cout << a << (sizeof...(b) ? " " : "\n");
    out(b...);
}

template<class T>
void resz(int n, T &v) { v.resize(n); }

template<class H, class... T>
void resz(int n, H &a, T &... b) {
    a.resize(n);
    resz(n, b...);
}

template<typename V, typename H>
void resize(vector<V> &v, const H a) { v.resize(a); }

template<typename V, typename H, typename... T>
void resize(vector<V> &v, const H &a, const T... b) {
    v.resize(a);
    for (auto &v:v) resize(v, b...);
}

const int INF = 1LL << 55;
const int MOD = 1000000007;
const double EPS = 1e-8;

/*------------end of definitions------------*/

string S;
int ans = 1;

signed main() {

    in(S);
    string preview = S.substr(0, 1);
    int i = 1;
    for (; i < S.size(); i++) {
        string current = S.substr(i, 1);
        show(preview, current);
        if (preview == current) {
            current = S.substr(i, 2);
            i++;
        }
        preview = current;
        ans++;
    }
    if (i > S.size()) ans--;
    out(ans);

    return 0;
}


Measured memory_bytes: 720
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main (){

  string w,t;
  int a=0;
  cin >>w;

  while(1){
    cin >>t;

    if(t == "END_OF_TEXT")break;
    
    for(int i=0; i <t.size();i++){
   
	t[i]=tolower(t[i]);
     
    }
    
    if(w == t)
      a++;
  }
    
  cout <<a<<endl;

  return 0;
}

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

int main(){

  int N,D;
  
  cin>>N>>D;
  
  int x[N];
  int y[N];
  
  for(int i=0;i<N;i++){
    cin>>x[i];
    cin>>y[i];
  }
  
  int count=0;
  
  for(int i=0;i<N;i++){
    
    long long int d=pow(x[i],2)+pow(y[i],2);
    double dis= sqrt(d);
    if(dis<=D) count++;
    
    
    
  }
  
  cout<<count<<endl;


}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
int n,a[1<<17],i;
string s;
int main(){
  cin>>n>>s;
  for(int b:{0,1}){
    for(int c:{0,1}){
      a[1]=b;
      a[2]=c;
      a[0]=(s[1]=='o')^b^c;
      for(i=3;i<n;i++)a[i]=(s[i-1]=='o')^a[i-1]^a[i-2];
      if((s[n-1]=='o')^a[n-1]==a[0]^a[n-2]&&(s[0]=='o')^a[0]==a[n-1]^a[1]){
        for(i=0;i<n;i++)cout<<(a[i]==1?'S':'W');
        cout<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<endl;
}


Measured memory_bytes: 4168
import sys
# sys.setrecursionlimit(100000)
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, c = input_int_list()
    grid = []
    discomfort = []

    for _ in range(c):
        discomfort.append(input_int_list())

    for _ in range(n):
        grid.append(input_int_list())

    c0 = []
    c1 = []
    c2 = []

    # 色を揃えるマスを1次配列に振り分け
    for i in range(n):
        for j in range(n):
            if (i + j + 2) % 3 == 0:
                c0.append(grid[i][j])
            elif (i + j + 2) % 3 == 1:
                c1.append(grid[i][j])
            else:
                c2.append(grid[i][j])

    # それぞれを集計
    c0 = Counter(c0)
    c1 = Counter(c1)
    c2 = Counter(c2)

    ans = float("inf")

    # 塗り分けを全パターン試す
    for x in range(1, c + 1):
        for y in range(1, c + 1):
            for z in range(1, c + 1):
                if x == y or y == z or z == x:
                    continue
                tmp = 0
                for k, v in c0.items():
                    if k == x:
                        continue
                    else:
                        tmp += discomfort[k - 1][x - 1] * v

                for k, v in c1.items():
                    if k == y:
                        continue
                    else:
                        tmp += discomfort[k - 1][y - 1] * v

                for k, v in c2.items():
                    if k == z:
                        continue
                    else:
                        tmp += discomfort[k - 1][z - 1] * v

                ans = min(ans, tmp)

    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 92260
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    ll a,b; cin>>a>>b;
    cout<<a*b;
}

Measured memory_bytes: 3644
#include <cstdio>
using namespace std;
int main() {
	int a,b,n,x,y;
	while (scanf("%d %d",&a,&b)) {
		if (a==0&&b==0) break;
		scanf("%d",&n);
		int map[a][b];
		for (int i=0; i<a; i++) for (int j=0; j<b; j++) map[i][j]=-1;
		for (int i=0; i<n; i++) {
			scanf("%d %d",&x,&y);
			map[x-1][y-1]=0;
		}
		for (int i=0; i<a; i++) {
			for (int j=0; j<b; j++) {
				if (i==0&&j==0) {
					map[i][j]=1;
				} else if (map[i][j]==-1) {
					map[i][j]=0;
					if (i-1>=0) map[i][j]+=map[i-1][j];
					if (j-1>=0) map[i][j]+=map[i][j-1];
				}
			}
		}
		printf("%d\n",map[a-1][b-1]);
	}
}

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

using namespace std;

const long long MAXN = 2e5 + 10;
const long long MOD = 1e9 + 7;

vector<vector<long long>> adjList(MAXN);

vector<long long> fact(MAXN);
vector<long long> dp(MAXN), sz(MAXN);

void makef()
{
  fact[0] = 1;
  for(long long i = 1; i < MAXN; i++)
  {
    fact[i] = (fact[i - 1] * i) % MOD;
  }
}

long long gcde(long long a, long long b, long long *x, long long *y)
{
    if(a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }
    long long x1, y1;
    long long gcd = gcde(b % a, a, &x1, &y1);
    *x = y1 - (b / a) * x1;
    *y = x1;
    return gcd;
}

long long inv(long long a)
{
  long long x, y;
  long long g = gcde(a, MOD, &x, &y);
  assert(g == 1);
  long long res = (x % MOD + MOD) % MOD;
  return res;
}

void dfs0(long long nd, long long p)
{
  long long tsz = 1;
  for(long long cd : adjList[nd])
  {
    if(cd != p)
    {
      dfs0(cd, nd);
      tsz += sz[cd];
    }
  }
  sz[nd] = tsz;
  dp[nd] = fact[sz[nd] - 1];
  for(long long cd : adjList[nd])
  {
    if(cd != p)
    {
      (dp[nd] *= dp[cd]) %= MOD;
      (dp[nd] *= inv(fact[sz[cd]])) %= MOD;
    }
  }
}

void dfs1(long long nd, long long p, long long n)
{
  if(p != -1)
  {
    dp[nd] = (dp[p] * sz[nd]) % MOD;
    (dp[nd] *= inv(n - sz[nd])) %= MOD;
  }
  for(long long cd : adjList[nd])
  {
    if(cd != p)
    {
      dfs1(cd, nd, n);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  makef();
  long long n;
  cin >> n;
  for(long long i = 0; i < n - 1; i++)
  {
    long long u, v;
    cin >> u >> v;
    adjList[u].push_back(v);
    adjList[v].push_back(u);
  }
  dfs0(1, -1);
  dfs1(1, -1, n);
  for(long long i = 1; i <= n; i++)
  {
    cout << dp[i] << endl;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 19584
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


namespace atc
{

    class Program
    {
        static T Read<T>()
        {
            Func<string, T> convFunc = null;
            if (typeof(T) == typeof(int)) convFunc = (_) => { return (T)(object)(int.Parse(_)); };
            else if (typeof(T) == typeof(Int16)) convFunc = (_) => { return (T)(object)(Int16.Parse(_)); };
            else if (typeof(T) == typeof(UInt16)) convFunc = (_) => { return (T)(object)(UInt16.Parse(_)); };
            else if (typeof(T) == typeof(Int32)) convFunc = (_) => { return (T)(object)(Int32.Parse(_)); };
            else if (typeof(T) == typeof(UInt32)) convFunc = (_) => { return (T)(object)(UInt32.Parse(_)); };
            else if (typeof(T) == typeof(Int64)) convFunc = (_) => { return (T)(object)(Int64.Parse(_)); };
            else if (typeof(T) == typeof(UInt64)) convFunc = (_) => { return (T)(object)(UInt64.Parse(_)); };
            else if (typeof(T) == typeof(float)) convFunc = (_) => { return (T)(object)(float.Parse(_)); };
            else if (typeof(T) == typeof(double)) convFunc = (_) => { return (T)(object)(double.Parse(_)); };
            return convFunc(Console.ReadLine());
        }

        static List<T> ReadVec<T>()
        {
            Func<string, T> convFunc = null;
            if (typeof(T) == typeof(int)) convFunc = (_) => { return (T)(object)(int.Parse(_)); };
            else if (typeof(T) == typeof(Int16)) convFunc = (_) => { return (T)(object)(Int16.Parse(_)); };
            else if (typeof(T) == typeof(UInt16)) convFunc = (_) => { return (T)(object)(UInt16.Parse(_)); };
            else if (typeof(T) == typeof(Int32)) convFunc = (_) => { return (T)(object)(Int32.Parse(_)); };
            else if (typeof(T) == typeof(UInt32)) convFunc = (_) => { return (T)(object)(UInt32.Parse(_)); };
            else if (typeof(T) == typeof(Int64)) convFunc = (_) => { return (T)(object)(Int64.Parse(_)); };
            else if (typeof(T) == typeof(UInt64)) convFunc = (_) => { return (T)(object)(UInt64.Parse(_)); };
            else if (typeof(T) == typeof(float)) convFunc = (_) => { return (T)(object)(float.Parse(_)); };
            else if (typeof(T) == typeof(double)) convFunc = (_) => { return (T)(object)(double.Parse(_)); };
            return Console.ReadLine().Split(' ').Select(s => (T)convFunc(s)).ToList();
        }

        static void Main(string[] args)
        {
            var l = Read<Int16>();
            Console.WriteLine(l + l*l + l*l*l);
        }
    }
}


Measured memory_bytes: 27508
import math
n=int(input())
lim=int(math.sqrt(n))
cnt=0
if lim**2==n:
    for i in range(1,lim):
        if n%i==0:
            cnt+=n//i-1
    print(cnt)
else:
    for i in range(1,lim+1):
        if n%i==0:
            cnt+=n//i-1
        a=int(math.sqrt(n))
    if a*(a+1)==n:
        cnt-=a 
    print(cnt)
    

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

typedef pair<int,int> P;
typedef pair<int,P> PP;
typedef priority_queue<PP, vector<PP>, greater<PP>> QUE;

int d[501][501][4];

int main() {
    int W, H, N;
    cin >> W >> H >> N;

    int x1, y1, x2, y2;
    cin >> y1 >> x1 >> y2 >> x2;

    map<char,int> dx, dy;
    dx['U'] = -1, dy['U'] = 0;
    dx['D'] = 1, dy['D'] = 0;
    dx['L'] = 0, dy['L'] = -1;
    dx['R'] = 0, dy['R'] = 1;


    for(int i = 0; i < N; i++) {
        int sx, sy;
        cin >> sy >> sx;
        int times; cin >> times;
        string code; cin >> code;
        for (int time = 0; time < times; time++) {
            for (int j = 0; j < code.size(); j++) {
                int nx = sx + dx[code[j]];
                int ny = sy + dy[code[j]];
                if (!(0 <= nx && nx < H && 0 <= ny && ny < W)) continue;
                if (code[j] == 'R') {
                    d[nx][ny][1] += 1;
                    d[nx + 1][ny][3] += 1;
                } else if (code[j] == 'L') {
                    d[sx][sy][1] += 1;
                    d[sx + 1][sy][3] += 1;
                } else if (code[j] == 'U') {
                    d[sx][sy][0] += 1;
                    d[sx][sy + 1][2] += 1;
                } else {
                    d[nx][ny][0] += 1;
                    d[nx][ny + 1][2] += 1;
                }
                sx = nx;
                sy = ny;
            }
        }
    }

    QUE que;
    que.push(PP(0, P(x1,y1)));
    int D[501][501];
    int res = 1 << 28;

    for (int i = 0; i <= H; i++)
        for (int j = 0; j <= W; j++)
            D[i][j] = 1 << 28;

    while(que.size()) {
        PP pp = que.top(); que.pop();
        int cost = pp.first;
        int x = pp.second.first;
        int y = pp.second.second;

        if (x == x2 && y == y2) res = min(res, cost);
        if (D[x][y] < cost) continue;

        int ddx[] = {0, 1, 0, -1};
        int ddy[] = {1, 0, -1, 0};
        for (int i = 0; i < 4; i++) {
            int nx = x + ddx[i];
            int ny = y + ddy[i];
            int cost_ = cost + d[x][y][i];

            if (0 <= nx && nx <= H && 0 <= ny && ny <= W && D[nx][ny] > cost_) {
                D[nx][ny] = cost_;
                que.push(PP(cost_, P(nx,ny)));
            }
        }
    }

    cout << res << endl;

    return 0;
}

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

#define rep(i, a) for (int i = 0; i < (a); i++ )

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

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

    int r,w;
    r = w = 0;
    rep(i,N) {
        if (S[i]=='W') w++;
    }
    int ans = INF;

    ans = min(ans, w);

    rep(i,N) {
        if (S[N-1-i]=='R') {
            r++;
        }
        else {
            w--;
        }
        int tmp = min(r,w);
        int t = r+w-tmp*2;
        ans = min(ans,t+tmp);
        //cout << w << " " << r << " " << t << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3744
def all_positive(values):
  m = []
  x = values[0]

  for v in values[1:-1]:
    m.append((x, v))
    x = x - v

  m.append((values[-1], x))
  x = values[-1] - x

  return x, m


def all_negative(values):
  m = []
  x = values[-1]

  for v in values[:-1]:
    m.append((x, v))
    x = x - v

  return x, m


def run(values):
  m = []
  x1 = values[0]
  x2 = values[-1]

  for v in values[-2::-1]:
    if v < 0:
      break

    m.append((x1, v))
    x1 = x1 - v

  for v in values[1:]:
    if v >= 0:
      break

    m.append((x2, v))
    x2 = x2 - v

  m.append((x2, x1))

  return x2 - x1, m


def main():
  input()
  values = list(map(int, input().split()))
  values.sort()

  if values[1] >= 0:
    x, m = all_positive(values)
  elif values[-2] <= 0:
    x, m = all_negative(values)
  else:
    x, m = run(values)

  print(x)
  for v in m:
    print('{} {}'.format(*v))


if __name__ == '__main__':
  main()


Measured memory_bytes: 20380
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq

stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]
S = [list(read_str().split())[0] for _ in range(N)]

def solve():
    return len(set(S))

if __name__ == "__main__":
    print(solve())

Measured memory_bytes: 36488
X, Y = map(int, input().split())
MOD = 10 ** 9 + 7

def modpow(x, n):
    ret = 1
    while n > 0:
        if n & 1:
            ret = ret * x % MOD
        x = x * x % MOD
        n >>= 1
    return ret

def modinv(x):
    return modpow(x, MOD - 2)

def modf(x):
    ret = 1
    for i in range(2, x + 1):
        ret *= i
        ret %= MOD
    return ret

ans = 0
if (X + Y) % 3 == 0:
    m = (2 * X - Y) // 3
    n = (2 * Y - X) // 3
    if m >= 0 and n >= 0:
        ans = modf(m + n) * modinv(modf(n) * modf(m))
        ans %= MOD
print(ans)

Measured memory_bytes: 9184
#入力（1次元）
N, X = list(map(int, input().split()))
L = list(map(int, input().split()))
D = [0] * 200
count = 1

for i in range(2,N+2):
    D[i] = D[i - 1] + L[i - 2]
    if(D[i] <= X):
        count += 1

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
//template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

void chmax(P &a,P b){
    vector<ll> s{a.first,a.second,b.first,b.second};
    RSORT(s);
    a.first = s[1];
    a.second = s[0];
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<P> dp(1<<n);
    ll a;
    rep(i,(1<<n)){
        cin >> a;
        dp[i] = P(0,a);
    }
    rep(i,n){
        rep(bit,(1<<n)){
            if (bit&(1<<i)){
                chmax(dp[bit],dp[bit^(1<<i)]);
            }
        }
    }
    ll ans = 0;
    rep(bit,(1<<n)){
        //cout << dp[bit].first << " " << dp[bit].second << endl;
        ans = max(ans,dp[bit].first+dp[bit].second);
        if (bit) PRINT(ans);
    }
}


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

using namespace std;

#define MOD 1000000007
#define ll long long int

const int maxn = 2020;

ll dp[maxn][maxn];

void pre() {
    for (int i = 0; i < maxn; i++) dp[i][0] = 1;
    for (int i = 1; i < maxn; i++) {
        for (int j = 1; j < maxn; j++) {
            dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;
        }
    }
}

int main() {
  pre();
  int n, k;
  scanf("%d %d", &n, &k);
  for(int i = 1; i <= k; i++) {
    long long x = dp[n - k + 1][i];
    long long y = dp[k - 1][i - 1];
    cout << (x * y) % MOD << '\n';
  }
}


Measured memory_bytes: 32256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int N,M;cin>>N>>M;
    if(N==1&&M==1)cout<<1<<endl;
    else{
        if(N==1||M==1)cout<<N*M-2<<endl;
        else cout<<(N-2)*(M-2)<<endl;
    }
}

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

#全＋、全ー、
L=[]
for i in range(N):
    x,y,z=map(int, input().split())
    a1=x+y+z
    a2=-x+y+z
    a3=-x-y+z
    a4=-x-y-z
    a5=x-y+z
    a6=x-y-z
    a7=x+y-z
    a8=-x+y-z
    L.append([x,y,z,a1,a2,a3,a4,a5,a6,a7,a8])

ans=0
for i in range(3,11):
    L=sorted(L, key=lambda x: x[i], reverse=True)
    sub=0
    for j in range(M):
        t=L[j]
        sub+=t[i]
    ans=max(ans, sub)
print(ans)


Measured memory_bytes: 3572