akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  string S, T;
  cin >> S >> T;

  for (int i = 0; i < N; i++) {
    cout << S[i] << T[i];
  }
  cout << '\n';
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>

using namespace std;

bool prime_check(int n)
{
	if (n == 1)
	{
		return false;
	}
	else if (n == 2)
	{
		return true;
	}
	else
	{
		for (int i = 2; i <= sqrt(n); i++)
		{
			if (n % i == 0)
			{
				return false;
			}
		}
	}

	return true;
}

int main()
{
	// --- variable define --- //

	int n, c;


	// --- prime check ( 2 to 999999 ) --- //

	bool isprime[1000000];

	for (int i = 1; i < 1000000; i++)
	{
		if (prime_check(i) == true)
		{
			isprime[i] = true;
		}
		else
		{
			isprime[i] = false;
		}
	}


	// --- main --- //

	while (cin >> n)
	{
		c = 0;

		for (int i = 2; i <= n; i++)
		{
			if (isprime[i] == true)
			{
				c++;
			}
		}

		cout << c << endl;
	}
}

Measured memory_bytes: 2132
#include <iostream>

using namespace std;
using ll = long long;


const int MAX_N = 1;


int a, b, c, x, y;


int solve()
{   
    int sum1 = a * x + b * y;
    int sum2 = c * 2 * max(x, y);
    int sum3;
    if(x > y) sum3 = c * 2 * y + (x - y) * a;
    else sum3 = c * 2 * x + (y - x) * b;

    return min(sum1, min(sum2, sum3));
    
}

int main()
{
    cin >> a >> b >> c >> x >> y;
    
    cout << solve() << endl;


    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
def test():
    n = int(input())
    s = input()
    ans = 0
    for i in range(n):
        set1 = set(s[:i])
        set2 = set(s[i:])
        ans = max(ans,len(set1 & set2))
    print(ans)


if __name__ == "__main__":
    test()


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

int n;
int dig[11];
string res;

bool chec(long long x) {
	char f;
	cout << "? " << x << "\n";
	cout.flush();
	cin >> f;
	if (f == 'Y') return true;
	if (f == 'N') return false;
}

long long p(int n, int k) {
	if (k == 0) return 1ll;
	if (k == 1) return n;
	long long cur = p(n, k/2);
	if (k % 2 == 0) {
		return cur * cur;
	}
	else {
		return cur * cur * n;
	}
}

signed main() {
	if (chec(1000000000)) {
		int res = -1;
		for (int j = 3; j >= 0; j--) {
			if ((1ll<<j) > 10 || res + (1ll<<j) > 10) continue;
			if (!chec(2ll*p(10, (1<<j)+res))) {
				res += (1ll<<j);
			}
		}
		res++;
		cout << "! 1";
		for (int i = 1; i <= res; i++) {
			cout << 0;
		}
	}
	else {
		int res = 0;
		int l = 0;
		for (int j = 3; j >= 0; j--) {
			if ((1<<j) > 10 || l + (1<<j) > 10) continue;
			if (chec(p(10, (1<<j)+l))) {
				l += (1<<j);
			}
		}
		l++;
		//cout << l << endl;
		int ul = p(10, l)-1;
		res = p(10, l-1);
		for (int j = 30; j >= 0; j--) {
			if ((1ll<<j) > ul || res + (1ll<<j) > ul) continue;
			if (!chec(10 * (res + (1ll<<j)))) {
				res += (1ll << j);
			}
		}
		cout << "! " << res+1;
	}
	return 0;
}

Measured memory_bytes: 596
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	fmt.Println(face(n, s))
}

func face(n int, s string) int {
	min := int(3 * math.Pow10(5))
	var ce, cw int
	for _, v := range s {
		if v == 'E' {
			ce++
		}
	}
	for _, v := range s {
		if v == 'E' {
			ce--
		}
		if ce+cw < min {
			min = ce + cw
		}
		if v == 'W' {
			cw++
		}
	}
	return min
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    int MAX = -INF, MIN = INF;
    rep(i, 0, n){
        cin >> a[i];
        chmax(MAX, a[i]);
        chmin(MIN, a[i]);
    }
    vector<P> ans; 
    if(MAX >= abs(MIN)){
        int id = -1;
        rep(i, 0, n) if(a[i] == MAX) id = i;
        rep(i, 0, n) ans.push_back(P(id, i));
        rep(i, 0, n - 1) ans.push_back(P(i, i + 1));
    }else{
        int id = -1;
        rep(i, 0, n) if(a[i] == MIN) id = i;
        rep(i, 0, n) ans.push_back(P(id, i));
        repb(i, n - 1, 1) ans.push_back(P(i, i - 1));
    }
    cout << ans.size() << endl;
    for(int ii = 0; ii < ans.size(); ii++){
        cout << ans[ii].first + 1 << " " << ans[ii].second + 1 << endl; 
    }
}

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  vector<int> p(n + 1);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  int result = 0;
  for (int i = 1; i <= n; i++) {
    if (p[i] == i) {
      result++;
      if (i < n) swap(p[i], p[i + 1]);
      else swap(p[i], p[i - 1]);
    }
  }
  printf("%d\n", result);
  return 0;
}


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

struct C{
  char suit,value;
};

void bubble(struct C A[],int N){
  for(int i=0;i<N;i++){
    for(int j=N-1;j>=i+1;j--){
      if(A[j].value < A[j-1].value){
	C t=A[j];
	A[j] = A[j-1];
	A[j-1] = t;
      }
    }
  }
}

void selection(struct C A[],int N){
  for(int i=0;i<N;i++){
    int minj = i;
    for(int j=i;j<N;j++){
      if(A[j].value < A[minj].value)minj = j;
    }
    C t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void print(struct C A[],int N){
  for(int i=0;i<N;i++){
    if(i>0)cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout << endl;
}

bool isStable(struct C C1[],struct C C2[],int N){
  for(int i=0;i<N;i++){
    if(C1[i].suit != C2[i].suit)return false;
  }
  return true;
}

int main(){
  C C1[100],C2[100];
  int N;
  char ch;

  cin >> N;
  for(int i=0;i<N;i++){
    cin >> C1[i].suit >> C1[i].value;
  }

  for(int i=0;i<N;i++){
    C2[i] = C1[i];
  }

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  cout << "Stable" << endl;
  print(C2,N);
  if(isStable(C1,C2,N)){
    cout << "Stable" << endl;
  }else{
    cout << "Not stable" << endl;
  }

  return 0;
}



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

#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,l,r) for(int i = l; i <= r; i++)
#define TR(e,x) for(auto e = x.begin(); e != x.end(); e++)
#define DEBUG(x) cout << #x << "=" << x << endl;
#define SHOW1(A,n) { REP(i,n-1) printf("%d ", A[i]); printf("%d\n", A[n-1]); }
#define SHOW2(A,m,n) { REP(i,m) { REP(j,n-1) printf("%d ", A[i][j]); printf("%d\n", A[i][n-1]); } }
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)((x).size())
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN  = 50, INF = ~0U>>1, MOD = ~0U>>1;

int n, m, a[MAXN][MAXN];

int main()
{
#ifdef LOCAL
    //freopen("i.txt", "r", stdin);
    //freopen("o.txt", "w", stdout);
#endif //LOCAL

    while (scanf("%d", &n), n) {
        m = 0;
        REP(i,50)REP(j,50) a[i][j] = i==j ? 0:1e9;
        REP(i,n) {
            int x,y,z; scanf("%d%d%d", &x,&y,&z);
            a[x][y] = a[y][x] = z;
            m = max(m, x); m = max(m, y);
        }
        m++;
        REP(k,m)REP(i,m)REP(j,m) a[i][j] = min(a[i][j], a[i][k]+a[k][j]);
        int ans = 0, sum = INF;
        REP(i,m) {
            int cnt = 0;
            REP(j,m) cnt += a[i][j];
            if (cnt < sum) sum = cnt, ans = i;
        }
        printf("%d %d\n", ans, sum);
    }

    return 0;
}














































































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

int max(int a, int b)
{
  return (a>b)? a : b ;
}
int main()
{
 int n, x, y, a[5001];
 while(cin>>n, n)
 {
  for(int i=0; i<n; i++)
  {
   cin>>a[i];
   }
  x=a[0];
 for(int i=0; i<n; i++)
 {
  int sum=0;
  for(int j=i; j<n; j++)
   {
    sum += a[j];
     x = max( x, sum );
    }
   }
  cout<<x<<endl; 
 }
 }
   

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

#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int n;
int p[5000];
int z[5000];
signed main(){
    while(cin>>n){
        rep(i,n)cin>>p[i];

        int ans=1001001001ll;
        for(int t=0;t<=p[0];t++){
            int cost=t;
            memset(z,0,sizeof(z));
            z[0]=t;
            for(int i=1;i<n;i++){
                cost+=(p[i-1]-z[i-1])*2;
                z[i]+=p[i-1]-z[i-1];
                chmin(z[i],p[i]);
            }
            cost+=p[n-1]-z[n-1];
            chmin(ans,cost);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	unordered_map<int,int>m;
	for(int x=1;x<100;++x){
		for(int y=x;y<100;++y){
			for(int z=y;z<100;++z){
				int sum=x*x+y*y+z*z+x*y+y*z+z*x;
				if(sum>n)break;
				if(x!=y&&y!=z)m[sum]+=6;
				else if(x==y&&y==z)m[sum]+=1;
				else m[sum]+=3;
			}
		}
	}
	for(int i=1;i<=n;++i){
		cout<<m[i]<<"\n"s;
	}
}


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

#define ll long long int
bool cheak(int a,int b,int c)
{
	if(a<b&&b<c)
	{
		return true;
	}
	if(a>b&&b>c)
		return true;
	return false;
}

int main()
{
	
	int n;
	cin>>n;
	int ar[n];
	for(int i=0;i<n;i++)
	{
		cin>>ar[i];
	}
	sort(ar,ar+n);
	cout<<ar[n/2]-ar[n/2-1]<<endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

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

    double ans = B;
    if (A < 6) {
        ans = 0;
    } else if (A < 13) {
        ans /= 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
        int n;
        scanf("%d", &n);

        int m[4][3][10] = {0};
        for(int i=0; i<n; i++){
                int b, f, r, v;
                scanf("%d %d %d %d", &b, &f, &r, &v);
                m[b-1][f-1][r-1] += v;
        }

        for(int i=0; i<4; i++){
                if(i) puts("####################");
                for(int j=0; j<3; j++){
                        for(int k=0; k<10; k++){
                                printf(" %d", m[i][j][k]);
                        }
                        puts("");
                }
        }
        return 0;
}


Measured memory_bytes: 2120
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n,k,q; cin>>n>>k>>q;
  VI c;
  rep(i,n) c.PB(0);
  rep(i,q){
    int a; cin>>a; a--;
    c[a]++;
  }
  rep(i,n){
    if(k-(q-c[i])>0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }




  return 0;
}


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

int G[30][30], n;
ll dp[21][(1 << 22) + 10];

ll recur(int pos, int mask) {
    if(pos == n) {
        if(__builtin_popcount(mask) == n)
            return 1;
        return 0    ;
    }

    ll &ret = dp[pos][mask];
    if(ret != -1)
        return ret;

    ret = 0;
    for(int i = 0; i < n; ++i)
        if(G[pos][i] and not (mask & (1 << i))) {
            ret = ret + recur(pos+1, mask | (1 << i));
            if(ret > MOD)
                ret %= MOD;
        }

    return ret;
}


int main() {
    cin >> n;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            cin >> G[i][j];

    memset(dp, -1, sizeof dp);
    cout << recur(0, 0) << endl;
    return 0;
}

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

def g(n):
    ret = 0
    ret += 1 if (n+1)//2%2==1 else 0
    for i in range(2, 41):
        m = 2**i
        if n%m>=m//2:
            ret += (n%m-m//2+1)%2 * m//2
    return ret

def solve(A: int, B: int):
    print(g(A-1)^g(B))
    return


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

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();  
    long x = a * b;
    long  r = 0;
    
  if(a<b){
    long tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
    
    System.out.println(x/b);
    
  }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://agc008.contest.atcoder.jp/tasks/agc008_b>
問題文============================================================
 N 個のマスが横一列に並んでいます。 左から i 番目のマスには整数 ai が書かれています。
 
 最初、すべてのマスは白色です。 すぬけ君は次の操作を好きな回数だけ繰り返します。
 
 連続する K 個のマスを選び、それらすべてを白く塗るか、それらすべてを黒く塗る。
 このとき、各マスの色は上書きされる。
 すぬけ君が操作を終えた後、黒いマスに書かれた整数の総和がスコアになります。
 考えられるスコアの最大値を求めてください。
=================================================================

解説=============================================================
 
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N,K; cin >> N >> K;
    vector<ll> a(N);
    for(auto &in:a) cin >> in;
    vector<ll> cusum(N+1,0);
    vector<ll> p_cusum(N+1,0);
    for(int i = 0; i < N;i++) {
        cusum[i+1] = cusum[i] + a[i];
        p_cusum[i+1] = p_cusum[i] + max(a[i],0LL);
    }
    ll ans = 0;
    for(int i = 0;i <= N - K;i++){
        ll sec_sum = cusum[i+K] - cusum[i];
        ll l_sum = p_cusum[i];
        ll r_sum = p_cusum[N] - p_cusum[i+K];
        ans = max(ans,max(sec_sum,0LL) + l_sum + r_sum);
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main()
{
    int a,i,j,b=0;
    scanf("%d",&a);
    for(i=2;i<=a;i++)
    {
        if(i%2!=0)
        {
            for(j=i;j<=a;j=j+2)
                b++;
        }
        else
        {
            for(j=i;j<=a;j=j+2)
                b++;
        }
    }
    printf("%d\n",b);


    return 0;
}


Measured memory_bytes: 128
// B.

#include <iostream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
	int ans = 0;
	string s;
	cin >> s;
	for (int i = 2; i < (int)s.length(); i += 2) {
		if (s.substr(0, i / 2) == s.substr(i / 2, i / 2)) {
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}


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


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

int main() {
  int N, X, A;
  cin >> N;
  X=0;
  A=N;
  
  for (int i=0; i<8;i++) {
    X += A%10;
    A /= 10;
  }
  
  if (N%X == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
# listを並び替えて移動距離の最小値を求める

N = int(input())
a = list(map(int, input().split()))

# 降順に並び替える
descending_a = sorted(a, reverse=True)
# print(descending_a)

# 座標の最大値から最小値を引く→移動距離を求める
print(descending_a[0] - descending_a[-1])


Measured memory_bytes: 8988
n, m = map(int, input().split())
ps = [list(input().split()) for _ in range(m)]

wa = [0] * (n + 1)
ac = [0] * (n + 1)

for p, s in ps:
    p = int(p)

    if ac[p]:
        continue

    if s == "WA":
        wa[p] += 1
    else:
        ac[p] = 1

ans = [0, 0]

for a, w in zip(ac, wa):
    if a:
        ans[0] += 1
        ans[1] += w

print(*ans)


Measured memory_bytes: 27448
import java.util.*;
import java.io.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        String b = sc.next();

        if (b.equals("A")) {
            out.printf("T\n");
        } else if (b.equals("T")) {
            out.printf("A\n");
        } else if (b.equals("C")) {
            out.printf("G\n");
        } else if (b.equals("G")) {
            out.printf("C\n");
        }
        out.flush();
    }
}


Measured memory_bytes: 22612
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;

#define m(a,b) memset(a,b,sizeof(a));
typedef long long ll;
const int MAXN=1e5+100;

int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int sum=0;
	for(int i=a;i<=n;i++){
		if (i<10&&i>=a&&i<=b){
			sum+=i;
		}
		else{
			int x=i,s=0;
			while(x){
				s+=x%10;
				x/=10;
			}
			if (s<=b&&s>=a){
				sum+=i;
			}
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
#codeforces1203A_live
gi = lambda : list(map(int,input().split()))
n, = gi()
l = sorted(gi())
ans = l[0]
for k in range(1, n):
	ans = (ans + l[k]) / 2
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <unordered_map>
#include <vector>
#include <set>
#include <string.h>
#include <algorithm>
#define mod 1000000007
#define ll long long
#define pr pair<int,int>
#define all vec.begin(),vec.end()
#define REP(i,a,b) for (int i = a; i < b; i++)
#define fi first
#define se second
#define pushb push_back
#define makep make_pair

using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	string out = (c <= b && c >= a) ? "Yes" : "No";
	cout << out;
	return 0;
}



Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll,ll>
#define pii pair<int,int>
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
 
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b) ;} 

template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}
 

 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 	ll n;
 	cin>>n;
 	string s;
 	cin>>s;
 	vector<int> rind;
 	// int last = -1;
 	int cnt = 0;

 	for(int i=n-1;i>=0;i--){
 		if(s[i]=='R'){
 			rind.pb(i);
 		}
 	}   
 	int j = 0;
 	for(int i=0;i<n;i++){
 		if(s[i]=='W'){
 			if(j<rind.size()){
 				if(rind[j]>i){
 					s[i] = 'R';
 					s[rind[j]] = 'W';
 					cnt++;
 					// cout<<s<<endl;
 					j++;
 				}
 				else{
 					break;
 				}
 			}
 		}
 	}
 	cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 4400
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n;
char k;
set<char>s;

int main(){
    ios::sync_with_stdio(0);
    s.clear();
    cin >> n;
    forn(i,n){
        cin >> k;
        s.insert(k);
    }

    if(s.size() == 3){
        cout << "Three\n";
    }else{
        cout << "Four\n";
    }
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))
a=0
pp=[0]
for i in p:
    a+=i
    pp.append(a)
a=0
for i in range(k,n+1):
    a=max(a,pp[i]-pp[i-k])

print(a/2+k/2)


Measured memory_bytes: 24548
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;

template<class T> inline void chmax(T& a, T b) { if(b > a) a = b; }

int num;
bool done[100];
vector<vector<int> > edge;

inline int convert(unordered_map<int, int>& table, int x) {
	if(table.find(x) == table.end()) table.insert(make_pair(x, num++));
	return table[x];
}

int dfs(int v) {
	if(done[v])
		return 0;

	done[v] = true;

	int res = 1;
	for(int i = 0; i < (int)edge[v].size(); ++i)
		chmax(res, dfs(edge[v][i]) + 1);

	done[v] = false;

	return res;
}

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

	for(int n; cin >> n, n;) {
		num = 0;
		edge.clear();
		edge.resize(100);
		unordered_map<int, int> table;

		for(int i = 0; i < n; ++i) {
			int a, b;
			cin >> a >> b;

			a = convert(table, a);
			b = convert(table, b);

			edge[a].push_back(b);
			edge[b].push_back(a);
		}

		int ans = 0;
		for(int i = 0; i < num; ++i) {
			memset(done, false, sizeof(done));
			chmax(ans, dfs(i));
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1244
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 = sc.nextInt();

        n = n - ((n / 500) * 500);

        if (n <= a) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        

		sc.close();
	}
}


Measured memory_bytes: 21076
#include <iostream>
using namespace std;
int main(){
    char S[4];
    int ch = 0;
    for(int i = 0;i < 4;i++)cin>>S[i];
    for(int i = 0;i < 4;i++){
        for(int j = 0;j < 4;j++){
        if(i != j){
            if(S[i] == S[j])ch++;
            
            }
        }
    }
    
    if(ch == 4){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long ll;
#define print(x) cout<<(x)<<endl


#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


// DONT USE "int", USE "ll" !!!!!!!!!!!!
int main() {
	ll N;
	cin >> N;
	ll out = 1;
	ll lower = 1;
	ll upper = N;
	while (lower + 1 < upper) {
		out = (lower + upper) / 2;
		if (out*out > N)upper = out;
		else if (out*out <= N)lower = out;
	}
	out = lower;

	print(out*out);






	return 0;
}

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

int moji_to_num(char c){
    if('A' <= c && c <= 'Z') c += 'a' - 'A';
    if('a' <= c && c <= 'z') return (c-'a');
    return 27;
}
int main(){
    string str;
    int cnt[26]={0};
    
    while(getline(cin,str)){
        for(int i = 0 ; i < str.size() ; i++){
            cnt[moji_to_num(str[i])]++;
        }
    }
        char c = 'a';
    
    for(int i = 0 ; i < 26 ; i++){
        cout << c++ << ' '  << ':' << ' ' << cnt[i] << endl;
    }
    
    return 0;
}

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

typedef struct Bomb{
	int map[8][8];
} BOMB;

void Input(BOMB *);
void explode(BOMB *);

int x_cnt, y_cnt;

int main()
{
	int input_times, input_cnt;
	BOMB Bomb[50];
	int x, y;
	
	scanf("%d", &input_times);
	for(input_cnt = 0; input_cnt < input_times; input_cnt++){
		Input(&Bomb[input_cnt]);
		scanf("%d\n%d", &x, &y);
		Bomb[input_cnt].map[x - 1][y - 1] = 2;
		explode(&Bomb[input_cnt]);
	}
	
	for(input_cnt = 0; input_cnt < input_times; input_cnt++){
		printf("Data %d:\n", input_cnt + 1);
		for(y_cnt = 0; y_cnt < 8; y_cnt++){
			for(x_cnt = 0; x_cnt < 8; x_cnt++)
				printf("%d", Bomb[input_cnt].map[x_cnt][y_cnt]);
			printf("\n");
		}
	}
	
	return 0;
}

void Input(BOMB *bomb)
{
	char dump;
	dump = getchar();
	for(y_cnt = 0; y_cnt < 8; y_cnt++){
		dump = getchar();
		for(x_cnt = 0; x_cnt < 8; x_cnt++)
			bomb->map[x_cnt][y_cnt] = getchar() - 48;
	}
}

void explode(BOMB* bomb_map)
{
	int explode_cnt;
	for(y_cnt = 0; y_cnt < 8; y_cnt++)
		for(x_cnt = 0; x_cnt < 8; x_cnt++)
			/*Find exploded bomb and process*/
			if(bomb_map->map[x_cnt][y_cnt] == 2){
				bomb_map->map[x_cnt][y_cnt] = 0;
				/*Left*/
				explode_cnt = 1;
				while((x_cnt - explode_cnt) >= 0 && explode_cnt <= 3){
				    if((bomb_map->map[x_cnt - explode_cnt][y_cnt]) == 1)
				        (bomb_map->map[x_cnt - explode_cnt][y_cnt]) = 2;
				    explode_cnt++;
				}
				/*Right*/
				explode_cnt = 1;
				while((x_cnt + explode_cnt) <= 7 && explode_cnt <= 3){
				    if((bomb_map->map[x_cnt + explode_cnt][y_cnt]) == 1)
				        (bomb_map->map[x_cnt + explode_cnt][y_cnt]) = 2;
				    explode_cnt++;
				}
				/*Down*/
				explode_cnt = 1;
				while((y_cnt - explode_cnt) >= 0 && explode_cnt <= 3){
				    if((bomb_map->map[x_cnt][y_cnt - explode_cnt]) == 1)
				        (bomb_map->map[x_cnt][y_cnt - explode_cnt]) = 2;
				    explode_cnt++;
				}
				/*Up*/
				explode_cnt = 1;
				while((y_cnt + explode_cnt) <= 7 && explode_cnt <= 3){
				    if((bomb_map->map[x_cnt][y_cnt + explode_cnt]) == 1)
				        (bomb_map->map[x_cnt][y_cnt + explode_cnt]) = 2;
				    explode_cnt++;
				}
				explode(bomb_map);
			}
}

Measured memory_bytes: 612
#include <stdio.h>
#include <string.h>
int main()
{
	char str[10];
	scanf("%s", str);
	int len = strlen(str);
	if(strcmp(str, "SUN")==0)
		printf("7\n");
	else if(strcmp(str, "MON")==0)
		printf("6\n");
	else if(strcmp(str, "TUE")==0)
		printf("5\n");
	else if(strcmp(str, "WED")==0)
		printf("4\n");
	else if(strcmp(str, "THU")==0)
		printf("3\n");
	else if(strcmp(str, "FRI")==0)
		printf("2\n");
	else if(strcmp(str, "SAT")==0)
		printf("1\n");
	return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
	//freopen("t.txt","r",stdin);
	int a;
	cin>>a;
	int sau = a%100, truoc = a/100;
	if ( ( truoc >=1 && truoc <=12 ) && ( sau <1 || sau >12 ) ){
		cout<<"MMYY";
		return 0;
	}
	
	if ( ( sau >=1 && sau <=12 ) && ( truoc <1 || truoc> 12 ) ){
		cout<<"YYMM";
		return 0;
	}
	
	if ( ( truoc >=1 && truoc <=12 ) && ( sau >=1 && sau <=12 )  ){
		cout<< "AMBIGUOUS";
		return 0;
	}
	
	if ( ( truoc <1 || truoc >12 ) && ( sau <1 || sau >12 )  ){
		
		cout<<"NA";
		return 0;
	}
	return 0;
	
}	

Measured memory_bytes: 256
S=input()
T=input()
result = False
j=0
S=''.join(list(reversed(S)))
T=''.join(list(reversed(T)))

for i in range(len(S) - len(T) + 1):
    tmp_s=S
    if(S[i] == T[j] or S[i] == '?'):
        w=0
        for n in range(len(T)):
            if(S[i+n] == T[j+n] or S[i+n] == '?'):
                tmp_s = tmp_s[:i+n] + T[j+n] + tmp_s[i+n+1:]
                w+=1
            else:
                break
        if(w == len(T)):
            result = True
    if(result == True):
        break
    j=0
if(result == True):
    tmp_s=''.join(list(reversed(tmp_s)))
    print(tmp_s.replace('?','a'))
else:
    print('UNRESTORABLE')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define ll long long
using namespace std; 
const int N=1e3+5;
const int mod=1e9+7;
inline ll read(){
	ll x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,m,c1,c2,cnt,f1,f2;
ll k;
struct mat{
	ll m[2][2];
	mat(){memset(m,0,sizeof(m));}
}base;
mat operator*(mat a,mat b){
	mat tmp;
	inc(i,0,1)
		inc(j,0,1)
			inc(k,0,1) (tmp.m[i][j]+=a.m[i][k]*b.m[k][j]%mod)%=mod;
	return tmp;
}
mat qp(mat x,ll k){
	mat res;inc(i,0,1) res.m[i][i]=1;
	while(k){
		if(k&1) res=res*x;
		k>>=1,x=x*x;
	}
	return res;
}
char s[N][N];
ll qp(ll x,ll k){
	ll res=1;
	while(k){
		if(k&1) res=res*x%mod;
		k>>=1,x=x*x%mod;
	}
	return res;
}

int main(){
	n=read(),m=read(),k=read();
	inc(i,1,n) scanf("%s",s[i]+1);
	inc(i,1,n){
		inc(j,1,m){
			if(s[i][j]=='#'){
				cnt++;
				if(s[i][j+1]=='#') c1++;
				if(s[i+1][j]=='#') c2++;	
			}
		}
	}
	inc(i,1,n) if(s[i][1]=='#'&&s[i][m]=='#') f1++;
	inc(i,1,m) if(s[1][i]=='#'&&s[n][i]=='#') f2++;
	if(!f1&&!f2) return printf("%lld",qp(cnt,k-1)),0;
	if(f1&&f2) return puts("1"),0;
	if(!f1) swap(f1,f2),swap(c1,c2);
	base.m[0][0]=cnt,base.m[1][0]=c1,base.m[1][1]=f1;
	base=qp(base,k-1);
	printf("%lld",(base.m[0][0]-base.m[1][0]+mod)%mod);
}

Measured memory_bytes: 4796
/*数组有没有开小
有没有开long long
会不会爆long long
初始化（多组数据，一定要记得把数组清零！！！）
时刻小心数组/容器是否为空
最后容器中剩余是否需要加入答案 
位运算结果的数组，要开2倍。位运算时注意结果的范围可能大于两个数的范围
要考虑边界情况(n=0?n=1?n=最大值?) 
注意变量名(尤其注意:n,n2 i,j)
开bool时注意取值不能为0~2
*/
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

int main()
{
	ri n;string s;
	cin>>n>>s;
	ri l=s.length(),x;
	rep(i,0,l-1){
		x=s[i]-'A';
		x=(x+n)%26;
		cout<<(char)(x+'A');
	}
	return 0; 
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n, q = [int(x) for x in input().split()]
    s = input()
    a = [0] * n
    b = [0] * n
    for i in range(n-1):
        if s[i:i+2] == 'AC':
            a[i] = 1
        b[i] = a[i]
        if i:
            b[i] += b[i-1]
    for _ in range(q):
        l, r = [int(x) for x in input().split()]
        l -= 1
        r -= 1
        ans = b[r-1]
        if l:
            ans -= b[l-1]
        print(ans)
    
    

        
    
t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

R s
S p
P r

"""


Measured memory_bytes: 14288
def D_Derangement(N, p):
    count = 0
    i = 0
    while i < N:
        if p[i] == i + 1: #p_i=iなら
            count += 1
            i += 2
        else:
            i += 1
            continue
    return count
 
N = int(input())
p = [int(i) for i in input().split()]
print(D_Derangement(N, p))

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

#define rep(i, n) for(long long i=0;i<n;i++)
using ll = long long;
const ll INF = (1LL<<60);

int main(){

    ll n, m; cin >> n >> m;

    if(n==m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    for(int i = (int)(N/1.08)-1; i < N/1.08+500; i++){
      if(i*1.08 >= N){
        if((int)(i*1.08) == N)
          System.out.println(i);
        else
          System.out.println(":(");
        break;
      }
    }
  }
}


Measured memory_bytes: 21204
#ABC054A
import sys

n,m=map(int,raw_input().split())
a=[]
b=[]
for i in xrange(n):
 a.append(raw_input())
for i in xrange(m):
 b.append(raw_input())
for i in xrange(m):
 if b[i] not in a[i]:
  print 'No'
  sys.exit()
 else:
  print 'Yes'
  sys.exit()


Measured memory_bytes: 2696
#include<iostream>
using namespace std;
const long long mod=1e9+7;
long long jc[6060606],_jc[6060606];
long long pow(long long n,long long k)
{
	long long ret=1;
	while(k>0)
	{
		if(k&1)
			ret=ret*n%mod;
		n=n*n%mod;
		k/=2;
	}
	return ret;
}
long long C(int n,int m)
{
	return jc[n]*_jc[m]%mod*_jc[n-m]%mod;
}
int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	jc[0]=1;
	_jc[0]=1;
	for(int i=1;i<=n+m+k;i++)
	{
		jc[i]=jc[i-1]*i%mod;
		_jc[i]=pow(jc[i],mod-2);
	}
	long long tmp=1,ans=0;
	for(int i=0;i<=m+k;i++)
	{
		ans=(ans+C(n+i-1,i)*tmp%mod*pow(3,m+k-i)%mod)%mod;
		tmp*=2;
		if(i+1>k)
			tmp-=C(i,i-k); 
		if(i+1>m)
			tmp-=C(i,m);
		tmp+=2*mod;
		tmp%=mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, arr[100001], k;
ll dp[100002];
int main()
{
    IOS
    memset(dp, INF, sizeof dp);
    //freopen("kepler.in", "r", stdin);
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
    }
    dp[0] = 0;
    for (int i = 0; i < n-1; ++i) {
        for (int j = i+1; j <= i+k; ++j) {
            if (j>=n) {
                break;
            }
            dp[j] = min(dp[j], dp[i]+abs(arr[j]-arr[i]));
        }
    }
    cout << dp[n-1] << endl;;

    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int n,k,c,a,b;
vector<int>v1,v2;
string s;
int main()
{
	cin>>n>>k>>c>>s;
	a=-1e9,b=1e9;
	for(int i=0;i<n;++i)
	{
		 if(s[i]=='o'&&a+c<i)
		 {
		 	a=i;
		 	v1.push_back(i);
		 }
		 if(v1.size()==k) break;
	}
	for(int i=n-1;i>=0;--i)
	{
		if(s[i]=='o'&&b>=c)
		{
			b=0;
			v2.push_back(i);
		}
		else ++b;
		if(v2.size()==k) break;
	}
	reverse(v2.begin(),v2.end());
	for(int i=0;i<k;++i)
	 if(v1[i]==v2[i])
	  cout<<v1[i]+1<<endl;
	return 0;
}

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

int main(){
    int P,Q,R,maxim;
    cin >> P;
    maxim = P;
    cin >> Q;
    maxim = max(maxim, Q);
    cin >> R;
    maxim = max(maxim, R);
    cout << P + Q + R - maxim << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace std;
#define int long long
#define double long double
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> new_data_set;
bool isprime(int n)
	{
    	if(n==1) return true;
    	for(int i = 2;i*i<=n;i++){
    		if(n%i==0) return false;
		}
		return true;
	}
int lcm(int a,int b){
	return (a*b)/__gcd(a,b);
}
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
unsigned int factorial(unsigned int n) 
{ 
    if (n == 0) 
    return 1; 
    return n * factorial(n - 1); 
} 
const int inf=1e17+7;
//const int N=2e5+5;
bool visited[100005] = {false};
signed main(){
	FAST
	int n,k,temp=INT_MAX;
	cin>>n>>k;
	int arr[n];
	vector<int> b(n,inf);
	for(int i = 0;i<n;i++) cin>>arr[i];
	b[0]=0;
	for(int i = 0;i<n;i++){
		for(int j = i+1;j<=i+k;j++){
			if(j<n){
				b[j] = min(b[j],b[i]+abs(arr[i]-arr[j]));
			}
		}
	}
	//cout<<b[n-1];
	cout<<b[n-1];
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n;
    ll k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll dp[50][2];
    fill(dp[0],dp[50],-1e18);
    dp[0][0]=0;
    for(int i=0;i<49;i++){
        int d=(k>>(48-i))&1;
        int cnt=0;
        for(int j=0;j<n;j++){
            cnt+=(a[j]>>(48-i))&1;
        }
        for(int j=0;j<2;j++){
            for(int l=0;l<=(j?1:d);l++){
                if(l==0){
                    dp[i+1][j||l<d]=max(dp[i+1][j||l<d],2*dp[i][j]+cnt);
                }
                else{
                    dp[i+1][j||l<d]=max(dp[i+1][j||l<d],2*dp[i][j]+n-cnt);
                }
            }
        }
    }
    cout<<max(dp[49][0],dp[49][1])<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;


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

vector<int> vis, path;

void dfs(int at) {
	for (int c : adj[at]) if (!vis[c]) {
		vis[c] = 1;
		path.push_back(c);
		dfs(c);
		return;
	}
}

int main() {
	cin >> N >> M;
	adj.resize(N);
	for (int i = 0; i < M; ++i) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	vis.resize(N);
	path.push_back(0);
	vis[0] = 1;
	dfs(0);
	reverse(path.begin(), path.end());
	dfs(0);
	cout << path.size() << endl;
	for (int p : path) {
		cout << p+1 << " ";
	}
	cout << endl;
	cin >> ws;
}

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


vector<int> a,w;
set<int> can;
void dfs(int idx,int left_w,int right_w){
    if(idx==w.size()){
        can.insert(abs(left_w-right_w));
        return;
    }
    dfs(idx+1,left_w+w[idx],right_w); // 右に乗せる
    dfs(idx+1,left_w,right_w+w[idx]); // 左に乗せる
    dfs(idx+1,left_w,right_w); // 使わない
    return;
}

signed main(){
    int n,m;
    while(cin>>n>>m){
        if(n+m==0)break;
        a.resize(n);
        w.resize(m);
        for(int i=0;i<n;i++)cin>>a[i];
        for(int i=0;i<m;i++)cin>>w[i];
        can.clear();
        dfs(0,0,0);
        
        for(int i=0;i<a.size();i++){
            if(can.find(a[i])!=can.end()){
                a.erase(a.begin()+i);
                i--;
            }
        }

        if(a.size()==0){
            cout<<0<<endl;
            continue;
        }

        vector<set<int>> v(a.size());
        for(int i=0;i<a.size();i++){
            for(auto s:can){
                v[i].insert(abs(a[i]-s));
                v[i].insert(abs(a[i]+s));
            }
        }

        auto intersection=[&](set<int>& A, set<int>& B){
            set<int> ret;
            for(auto a:A){
                if(B.find(a)!=B.end()){
                    ret.insert(a);
                }
            }
            return ret;
        };
        set<int> res=v[0];
        for(int i=1;i<v.size();i++){
            res=intersection(res,v[i]);
        }
        if(res.size()==0)cout<<-1<<endl;
        else cout<<*(res.begin())<<endl;
    }
}



Measured memory_bytes: 236836
#include <bits/stdc++.h>
#include <stdio.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 inputLongArray(a,N) long 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++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N, X, Y; cin >> N >> X >> Y; X--; Y--;

  //main
  map<ll,ll> mp;
  
  for(int i=0; i<N; i++){
    vll d(N,1e9+7); d[i] = 0;
    queue<ll> q; q.push(i);
    
    while(!q.empty()){
      ll now = q.front(); q.pop();
      set<ll> s;
      if(now!=0){
        s.insert(now-1);
      }
      if(now!=N-1){
        s.insert(now+1);
      }
      if(now==X || now==Y){
        s.insert(now^(X^Y));
      }
      
      for(ll j : s){
        if(d[j]>d[now]+1){
          d[j] = d[now]+1;
          q.push(j);
        }
      }
    }
    
    for(int j=0; j<N; j++){
      //cout << d[j] << " ";
      mp[d[j]] ++;
    }
    //cout << endl;
  }
  
  // output
  for(int i=1; i<N; i++){
    ll ans = mp[i]/2;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;
constexpr int INF = 1e18;

using namespace std;

vector<int> dijkstra(int i,int n, vector<vector<pair<int, int>>> graph) {
  vector<int> d(n, INF);
  d[i] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
  q.push(make_pair(0, i));
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto x : graph[v]) {
      if (d[x.first] > d[v] + x.second) {
        d[x.first] = d[v] + x.second;
        q.push(pair<int, int>(d[x.first], x.first));
      }
    }
  }
  return d;
}


/* vector<int> dijkstra(int s, int n, vector<vector<pair<int, int>>>& graph){ */
/*   vector<int> dist(n,INF); */
/*   dist[s] = 0; */
/*   priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>> > que; */
/*   que.push(pair<int, int>(0,s)); */

/*   while(!que.empty()){ */
/*     pair<int, int> p = que.top(); */
/*     que.pop(); */
/*     int v = p.second; */
/*     if(dist[v] < p.first){ */
/*       continue; */
/*     } */
/*     for(int i=0;i < (int)graph[v].size();i++){ */
/*       pair<int, int> e = graph[v][i]; */
/*       if(dist[e.first] > dist[v] + e.second){ */
/*         dist[e.first] = dist[v] + e.second; */
/*         que.push(pair<int, int>(dist[e.first],e.first)); */
/*       } */
/*     } */
/*   } */
/*   return dist; */
/* } */

signed main() {
  int N, M;
  cin >> N >> M;

  vector<vector<pair<int, int>>> graph(N);

  int a, b, c;
  REP(i, M){
    cin >> a >> b >> c;
    a--; b--;
    graph[a].push_back(make_pair(b, c));
    graph[b].push_back(make_pair(a, c));
  }

  vector<vector<int>> dist(N, vector<int>(N));
  REP(i, N) REP(j, N) dist[i][j] = (i == j)? 0 : INF;
  REP(i, N) dist[i] = dijkstra(i, N, graph);

  int ans = 0;
  REP(i, N){
    REP(j, graph[i].size()){
      bool shortest = false;
      REP(k, N) if(dist[k][i]+graph[i][j].second == dist[k][graph[i][j].first]) shortest = true;
      if(shortest) ans++;
    }
  }

  cout << M-ans/2 << endl;

  return 0;
}

Measured memory_bytes: 384
// Author : heyuhhh
// Created Time : 2020/08/22 20:00:39
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;
void run() {
    int n, x, t;
    cin >> n >> x >> t;
    int ans = (n + x - 1) / x * t;
    cout << ans << '\n';
}
int main() {
#ifdef Local
    freopen("input.in", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

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

int main() {
  int a, b;
  while (true) {
    cin >> a >> b;
    if (a == 0 && b == 0) return 0;
    if (a < b) cout << a << ' ' << b << endl;
    else cout << b << ' ' << a << endl;
  }
}

Measured memory_bytes: 1160
N,K=map(int,input().split())
MOD=998244353
S=[]
for _ in range(K):
    L,R=map(int,input().split())
    S.append((L,R))
S.sort()
dp=[0]*(N+1)
dp[1]=1
ans=[0]*(K+1)
for i in range(2,N+1):
    for j in range(K):
        L,R=S[j][0],S[j][1]
        if L>=i:
            break
        l=max(0,i-R)
        r=min(i-1,i-L)
        ans[j]+=dp[r]-dp[l-1]
    dp[i]+=sum(ans)
    dp[i]%=MOD
print(dp[N]%MOD)

Measured memory_bytes: 75992
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const int mod = 1000000007;
const ll inf = 1e18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
bitset<2020*2020> x;
int main() { //DINIC ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, t;
	cin >> n;
	x.set(0);
	while(n--) {
		cin >> t;
		x|=x<<t;
	}
	int cnt = x.count()/2;
	int a = 0;
	while(cnt) {
		cnt -= x.test(++a);
	}
	cout << a;
}



Measured memory_bytes: 1792