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

int main() {
	int H , W ;
  	cin >> H >> W ;
  	for(int i = 0; i < W + 2; i++){
    	cout << "#";
    }
  	cout << endl;
  	string s;
  	char a;
  	for(int i = 0; i < H; i++){
      	cin >> s;
      	cout << "#";
    	for(int j = 0; j < W; j++){
          	a = s.at(j);
        	cout << a;
        }
        cout << "#" << endl;
    }
    for(int i = 0; i < W + 2; i++){
    	cout << "#";
    }
  	cout << endl;
}

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

typedef pair<int,int> P;
int MAX=1000000007;

int main() {
  int n;
  while(cin >> n && n) {
    P a[n];
    for(int i=0; i<n; i++) cin >> a[i].first >> a[i].second; 
    int dp[n+1][4];
    fill(dp[0],dp[n+1],MAX);
    if(a[0].first<=a[0].second) dp[1][1]=a[0].first;

    int px=a[0].first,pt=a[0].second;
    for(int i=1; i<n; i++) {
      int x=a[i].first,t=a[i].second;
      int T=t-pt;
      for(int j=1; j<4; j++) {
	if(dp[i][j]==MAX) continue;
	if(px*(j+1)+x<=T) dp[i+1][1]=min(dp[i+1][1],dp[i][j]+px+x);
	if(j<3 && abs(px-x)*(j+1)<=T) dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+abs(px-x));
      }
      px=x;
      pt=t;
    }

    int ans=MAX;
    bool ck=true;
    for(int i=1; i<=n; i++) {
      bool ck2=false;
      for(int j=1; j<4; j++) {
	if(dp[i][j]!=MAX) ck2=true;
	if(i==n) ans=min(ans,dp[i][j]+px);
      }
      if(!ck2) {
	ck=false;
	ans=i;
	break;
      }
    }
    if(!ck) cout << "NG " << ans << endl;
    else cout << "OK " << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<string.h>
int main(void)
{
	int cnt,len,i;
	char s[20000000],t[2000000];
	scanf("%s",s);
	scanf("%s",t);
	len=0; cnt=0;
	len=strlen(s);
	for(i=0;i<len;i++){
		if(s[i]!=t[i]){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (true) {
      int n = sc.nextInt();
      int x = sc.nextInt();
      int ans = 0;
      if (n == 0 && x == 0) break;
      for (int i = 1; i < n+1; i++) {
        for (int j = i+1; j < n+1; j++) {
          for (int k = j+1; k < n+1; k++) {
            if (i+j+k == x) ans++;
          }
        }
      }
      System.out.println(ans);
    }
  }
}



Measured memory_bytes: 26868
import java.io.IOException;
import java.util.Scanner;

public class Main {

	// 10*10のマス目からはみ出る場合を考慮し14*14のサイズを持つ
	private static int[][] square = new int[14][14];
	private static int SMALL_INK = 1;
	private static int LARGE_INK = 3;
	private static int ALIGNMENT = 2;

	/**
	 * 標準入力された値を受け取り、インクのサイズによって滲む範囲を切り分ける。
	 * すべての入力が終了した後にまだインクが滲んでいないマスの数と、最も濃いマスを判定し、出力する。
	 *
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		int mostDeep = 0;
		int whiteTiles = 0;

		String[] inputString;
		String readLine = "";

		Scanner input = new Scanner(System.in);

		while (input.hasNext()) {

			readLine = input.next();

			// 受け取った一行をカンマ毎に区切る
			inputString = readLine.split(",", 0);

			inkPoint(Integer.parseInt(inputString[0]) + ALIGNMENT,
					Integer.parseInt(inputString[1]) + ALIGNMENT,
					Integer.parseInt(inputString[2]));

		}

		// 10*10のマス目を走査し、色がついていないマス数と最も濃いマスの濃さを調べる
		for (int i = 2; i < 12; i++) {
			for (int j = 2; j < 12; j++) {
				if (square[i][j] == 0) {
					whiteTiles++;
				} else {
					if (square[i][j] > mostDeep) {
						mostDeep = square[i][j];
					}
				}
			}
		}
		System.out.println(whiteTiles + "\r\n" + mostDeep);
	}

	/**
	 * squareの2?12マスにインクを落とす
	 *
	 * @param x
	 * @param y
	 * @param inkSize
	 */
	static void inkPoint(int x, int y, int inkSize) {

		square[x][y - 1]++;
		square[x - 1][y]++;
		square[x][y]++;
		square[x + 1][y]++;
		square[x][y + 1]++;

		if (inkSize != SMALL_INK) {
			square[x - 1][y - 1]++;
			square[x + 1][y - 1]++;
			square[x - 1][y + 1]++;
			square[x + 1][y + 1]++;
		}

		if (inkSize == LARGE_INK) {
			square[x][y - 2]++;
			square[x - 2][y]++;
			square[x + 2][y]++;
			square[x][y + 2]++;
		}
	}
}

Measured memory_bytes: 17168
import java.util.Scanner;

public class Main {

	static String solve(String n) {

		int num = 0;
		char[] cha = n.toCharArray();
		for (int i = 0; i < cha.length; i++) {
			num += cha[i] - 48;
		}
		if (num % 9 == 0)
			return "Yes";
		else
			return "No";
	}

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String n = stdIn.next();
		String result = solve(n);
		System.out.println(result);

		stdIn.close();
	}
}


Measured memory_bytes: 31464
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int a, b;
    cin >> a >> b;
    cout << max(max(a+b,a-b), a*b) << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * C - /\/\/\/
 * https://atcoder.jp/contests/abc111/tasks/arc103_a
 **/
#include<iostream>
#include<vector>

using namespace std;

const int MAX_N = 100000;

int main() {
    int n;
    cin >> n;
    vector<int> o(MAX_N+1, 0), e(MAX_N+1, 0);
    for(int i=0; i<n; ++i) {
        int tmp;
        cin >> tmp;
        if(i%2) {
            o[tmp] += 1;
        } else {
            e[tmp] += 1;
        }
    }

    int o1=MAX_N, o2=MAX_N, e1=MAX_N, e2=MAX_N;
    for(int i=0; i<MAX_N; i++) {
        if(o[i]>o[o2]) {
            if(o[i]>o[o1]) {
                o2 = o1;
                o1 = i;
            } else {
                o2 = i;
            }
        }
        if(e[i]>e[e2]) {
            if(e[i]>e[e1]) {
                e2 = e1;
                e1 = i;
            } else {
                e2 = i;
            }
        }
    }
    int ans = 0;
    if(o1!=e1) {
        ans = n - o[o1] - e[e1];
    } else {
        if(o[o2]+e[e1]>o[o1]+e[e2]) {
            ans = n - o[o2] - e[e1];
        } else {
            ans = n - o[o1] - e[e2];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int f[4][4];
int main()
{
    int a,b,c;
    scanf("%d%d%d",&f[1][1],&f[1][2],&f[2][2]);//先把位置都放好
    a=f[2][2]*3;//a记录行，列，斜线的和。我们知道，这种3*3的方格填数每一行，每一列，每一斜线的和都等于中间数的3倍
    f[1][3]=a-f[1][1]-f[1][2];
    f[3][1]=a-f[1][3]-f[2][2];
    f[3][3]=a-f[1][1]-f[2][2];
    f[2][1]=a-f[1][1]-f[3][1];
    f[2][3]=a-f[2][1]-f[2][2];
    f[3][2]=a-f[1][2]-f[2][2];//这一大段是计算，顺序很重要
    for(int i=1;i<=3;i++)
    {
        for(int j=1;j<=3;j++)
        {
            printf("%d ",f[i][j]);//矩阵输出
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
ac = [0, 0]
for i in range(len(S) - 1):
  if S[i] == "A" and S[i + 1] == "C":
    ac.append(ac[-1] + 1)
  else:
    ac.append(ac[-1])
for _ in range(Q):
  l, r = map(int, input().split())
  print(ac[r] - ac[l])

Measured memory_bytes: 6096
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

ll f2[110000],f3[110000];

int main(){
    string L;
    cin>>L;
    f2[0]=1; f3[0]=1;
    ll ans=0;
    int count=0;
    for(int i=0;i<(int)L.size();i++){
        if(L[i]=='1') count++;
    }
    for(int i=1;i<110000;i++){
        f2[i]=f2[i-1]*2;
        f3[i]=f3[i-1]*3;
        f2[i]%=MOD; f3[i]%=MOD;
    }
    int N=(int)L.size();
    ans+=f3[N-1];
    ans+=f2[count];
    ans%=MOD;
    count=1;
    for(int i=1;i<N;i++){
        if(L[i]=='1'){
            ans+=f3[N-i-1]*f2[count];
            count++;
        } 
        ans%=MOD;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 2240
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
         int a[]=new int[n];
         int b[]=new int[n];
         int c[]=new int[n];
         for(int i=0;i<n;i++)
         {
             a[i]=sc.nextInt();
             b[i]=sc.nextInt();
             c[i]=sc.nextInt();
         }
         int d[][]=new int[n][3];
         d[0][0]=a[0];
         d[0][1]=b[0];
         d[0][2]=c[0];
         
         for(int i=1;i<n;i++)
         {
             d[i][0]=Math.max(d[i-1][1],d[i-1][2] )+a[i];
             d[i][1]=Math.max(d[i-1][0], d[i-1][2])+b[i];
             d[i][2]=Math.max(d[i-1][0], d[i-1][1])+c[i];
         }
         int max=Math.max(d[n-1][0], Math.max(d[n-1][1], d[n-1][2]));
         System.out.println(max);
    }
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll x,y; cin>>x>>y;
  ll pm[2]={-1,1};
  ll ans=100000000000;
  rep(i,2){
    rep(j,2){
      ll mx=x*pm[i];
      ll my=y*pm[j];
      if(mx<=my){
      	ans=min(ans,my-mx+(pm[i]==-1?1:0)+(pm[j]==-1?1:0));
      }
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	vector<int> num(3);
	for (int i = 0; i < num.size(); ++i) cin >> num[i];
	sort(num.rbegin(), num.rend());
	cout << max((num[0] * 10 + num[1]) + num[2], num[0] + (num[1] * 10 + num[2])) << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
  unsigned long long int a,b,c,n,ans;
  cin>>n>>a>>b;
  c=n/(a+b);
  ans=c*a;
  n%=(a+b);
  ans+=min(a,n);
  cout<<ans<<endl;
  return 0;
}
  

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
m = [int(i) for i in input().split()]

ok = [[0 for i in range(2001)] for j in range(21)]
ok[0][0] = 1

for i in range(n):
    for j in range(2001):
        if j+a[i] > 2000:
            ok[i+1][j] = max(ok[i][j], ok[i+1][j])
        else:
            ok[i+1][j] = max(ok[i][j], ok[i+1][j])
            ok[i+1][j+a[i]] = max(ok[i][j], ok[i+1][j+a[i]])

for i in m:
    print('yes' if ok[n][i] else 'no')


Measured memory_bytes: 5968
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int N,A[100],ans;
    cin >> N;

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

    sort(A,A+N);

    ans = A[N-1] - A[0];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a,b;
	int x, y,z;
	scanf("%d %d", &a, &b);
	x=a+b;
	y=a-b;
	z=a*b;
	
	if(x>=y && x>=z ){
		printf("%d", x);
	}
	else if(y>=x && y>=z ){
		printf("%d", y);
	}
	else if(z>=y && z>=x ){
		printf("%d", z);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	string S, T;
	cin >> S >> T;
	int sz = S.size(), tz = T.size();
	int ans = INT_MAX;
	for(int i = 0;i <= sz - tz;i++)
	{
		int mis = 0;
		for(int j = 0;j < tz;j++)
			mis += (S[i + j] != T[j]);
		ans = min(mis,ans);
	}
	cout << ans;
}


Measured memory_bytes: 3536
#include<stdio.h>
main()


{
    int n,k,i,j,a,b,x;
    scanf("%d%d",&n,&k);
    int arr[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(arr[i]>arr[j])
            {
                a=arr[i];
                arr[i]=arr[j];
                arr[j]=a;
            }
        }
    }
    b=n-k;
    x=0;
    for(i=b;i<n;i++)
    {
        x=x+arr[i];
    }
    printf("%d",x);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

int main(void){
    string str;
    cin >> str;
    
    string month = str.substr(5, 2);

    int res = atoi(month.c_str());
    if(res <= 4){
        cout << "Heisei" << endl;        
    } else {
        cout << "TBD" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=1e4+10;
int main() {
	int k,a,b;
	cin>>k>>a>>b;
	int flag=0;
	for(int i=a;i<=b;i++){
	    if(i%k==0){
	        cout<<"OK";
	        flag=1;
	        break;
	    }
	}
	if(flag==0) cout<<"NG";
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(void){
  long long int num;
  long long int bingo[3][3]={0};
  for(int i=0;i<3;i++){
  	for(int j=0;j<3;j++){
  		int tmp;
  		cin>>tmp;
  		bingo[i][j]=tmp;
  	}
  }

  cin>>num;
  for(int l=0;l<num;l++){
  	int tmp2;
  	cin>>tmp2;
  	for(int i=0;i<3;i++){
  	  for(int j=0;j<3;j++){
  	  	if(tmp2==bingo[i][j]){
  	  		bingo[i][j]=0;
  	  	}
  	  }
  	}
  }

  if(bingo[0][0]==0&&bingo[0][1]==0&&bingo[0][2]==0
  	||bingo[1][0]==0&&bingo[1][1]==0&&bingo[1][2]==0
  	||bingo[2][0]==0&&bingo[2][1]==0&&bingo[2][2]==0
  	||bingo[0][0]==0&&bingo[1][0]==0&&bingo[2][0]==0
  	||bingo[0][1]==0&&bingo[1][1]==0&&bingo[2][1]==0
  	||bingo[0][2]==0&&bingo[1][2]==0&&bingo[2][2]==0
  	||bingo[0][0]==0&&bingo[1][1]==0&&bingo[2][2]==0
  	||bingo[0][2]==0&&bingo[1][1]==0&&bingo[2][0]==0){
  	cout<<"Yes"<<endl;
  }else{
  	cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int A,B;

	scanf("%d%d",&A,&B);

	if(A==1&&B==2 || A==2&&B==1)
        printf("3\n");
    if(A==2&&B==3 || A==3&&B==2)
        printf("1\n");
    if(A==1&&B==3 || A==3&&B==1)
        printf("2\n");

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main(){
    int N,X,Y;
    cin >> N >> X >> Y;
    vector<int>a(N),b(N),c(N);
    int mxa = 0,mxb = 0;
    for(int i = 0; i < N; i++) {
        cin >> a[i] >> b[i] >> c[i];
        mxa += a[i];
        mxb += b[i];
    }
    map<P,int>Mp;
    Mp[{0,0}] = 0;
    for(int bit = 0; bit < (1 << (N/2)); bit++) {
        int x = 0,y = 0,z = 0;
        for(int i = 0; i < N/2; i++) {
            if(1 & (bit >> i)) {
                x+=a[i];y+=b[i];z+=c[i];
            }
        }
        if(Mp.count({x,y})) {
            Mp[{x,y}] = min(Mp[{x,y}],z);
        }
        else {
            Mp[{x,y}] = z;
        }
    }
    map<P,int>Mp2;
    for(int bit = 0; bit < (1 << (N+1)/2); bit++) {
        int x = 0,y = 0,z = 0;
        for(int i = 0; i < (N+1)/2; i++) {
            if(1 & (bit >> i)) {
                x+=a[i+N/2];y+=b[i+N/2];z+=c[i+N/2];
            }
        }
        if(Mp2.count({x,y})) {
            Mp2[{x,y}] = min(Mp2[{x,y}],z);
        }
        else {
            Mp2[{x,y}] = z;
        }
    }
    int ans = INF;
    for(pair<P,int> x:Mp) {
        for(int i = 1; X*i <= mxa && Y*i <= mxb && (X+Y)*i <= mxa+mxb; i++) {
            if(Mp2.count({X*i-x.first.first,Y*i-x.first.second})) {
                ans = min(ans,x.second+Mp2[{X*i-x.first.first,Y*i-x.first.second}]);
            }
        }
    }
    if(ans == INF) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4156
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
int a,s,d[100],f,g,h,i,j;
scanf("%d %d",&a,&s);
for(i=1;i<=a;i++)	d[i]=0;
for(i=0;i<s;i++){
scanf("%d %d",&f,&g);
d[f]++;
d[g]++;
f=0;
g=0;
}
for(i=1;i<=a;i++)	printf("%d\n",d[i]);
return 0;
}

Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <unordered_map>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define inf 2248012
#define mp make_pair
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> ii;

const int MAXN = 1e5+3; //AREGLAAAAAAAAR!!!!

int main(){
	SYNC;
	pair<string,int> ls[] = {{"ABC",1200},{"ARC",2800},{"AGC",500000}};
	int r;
	cin>>r;
	FOR(i,0,3){
		if(r<ls[i].S){
			cout<<ls[i].F<<endl;
			break;
		}
	}
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	cin >> A;
	auto B = A;
	reverse(ALL(B));
	map<int, int> cnt;
	int diff = 0;
	vector<int> ret;
	for (int i : range(N)) {
		if (cnt[A[i]] == 0)diff++;
		cnt[A[i]]++;
		if (cnt[A[i]] == 0)diff--;
		if (cnt[B[i]] == 0)diff++;
		cnt[B[i]]--;
		if (cnt[B[i]] == 0)diff--;
		if (diff == 0)ret.push_back(i + 1);
	}
	int K = ret.size();
	for (int i : range(K)) {
		cout << " " + (!i) << ret[i];
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 6024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <boost/multiprecision/cpp_int.hpp>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void){
    ll N, count=0;
    cin>>N;
    ll L[100];
    rep(i, N) cin>>L[i];
    rep(i, N-2) reps(j, i+1, N-1) reps(k, j+1, N){
        //cout<<L[i]<<sp<<L[j]<<sp<<L[k]<<sp<<count<<endl;
        if(L[i]+L[j]>L[k] && L[j]+L[k]>L[i] && L[k]+L[i]>L[j] && L[i]!=L[j] && L[j]!=L[k] && L[i]!=L[k])
            count++;
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

const int MAXN = 2e5;
ll low[MAXN], ans[MAXN], MOD, p[MAXN];
vector<ll> g[MAXN], pl[MAXN],pr[MAXN];

ll dfs(int pos, int par){
  low[pos] = 1;
  p[pos] = par;
  for(auto x : g[pos]) if(x != par) low[pos] = low[pos]*dfs(x,pos)%MOD;
  return (low[pos]+1)%MOD;
}

ll dfs2(int pos, int par, ll acum){
  ans[pos] = acum*low[pos]%MOD;
  fore(i,0,SZ(g[pos])){
    if(g[pos][i] == p[pos]) continue;
    ll now = (i?pl[pos][i-1]:1)*(i+1<SZ(g[pos])?pr[pos][i+1]:1)%MOD;
    dfs2(g[pos][i],pos,(now*acum%MOD+1)%MOD);
  }
}

int main(){FIN;
  int n,x,y; cin >> n >> MOD;
  fore(i,0,n-1) cin >> x >> y, g[x-1].pb(y-1), g[y-1].pb(x-1);
  fore(i,0,n) pr[i].resize(SZ(g[i]),1), pl[i].resize(SZ(g[i]),1);
  dfs(0,-1);
  fore(i,0,n){
    fore(j,0,SZ(g[i])){
      pl[i][j] = (g[i][j]==p[i]?1:low[g[i][j]]+1)*(j?pl[i][j-1]:1)%MOD;
    }
    for(int j = SZ(g[i])-1; j >= 0; j--){
      pr[i][j] = (g[i][j]==p[i]?1:low[g[i][j]]+1)*(j+1<SZ(g[i])?pr[i][j+1]:1)%MOD;
    }
  }
  dfs2(0,-1,1);
  fore(i,0,n) cout << ans[i] << "\n";
}

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> array;
    array.resize(N + 1);
    for(int i = 0 ; i < N + 1 ; i++){
        array[i].resize(3);
    }
    array[0][0] = array[0][1] = array[0][2] = 0;
    for(int i = 0 ; i < N ; i++){
        cin >> array[i+1][0] >> array[i+1][1] >> array[i+1][2];
    }
    
    sort(array.begin(),array.end(),[](const vector<int> &array_a,const vector<int> &array_b){
        return array_a[0] < array_b[0];
    });

    // for(int i = 0 ; i < array.size();i++){
    //     for(int j = 0 ; j < 3 ; j++){
    //         cout << array[i][j];
    //     }
    //     cout << "\n";
    // }

    bool flag = false;

    for(int i = 0; i < array.size() - 1 ; i++){
        int distanceX = 0 ;
        int distanceY = 0,distance,time;
        distanceX = array[i+1][1] - array[i][1];
        distanceY = array[i+1][2] - array[i][2];
        time = array[i+1][0] - array[i][0];

        distance = abs(distanceX) + abs(distanceY);

        if(time < distance){
            flag = false;
            break;
        }else if(distance % 2 == time % 2){
            flag = true;
        }else{
            flag = false;
            // cout << distanceX << distanceY << "\n";
            // cout << time;
            // cout << i;
            break;
        }
    }

    if(flag){
        cout << "Yes";
    }else{
        cout << "No";
    }
    
}

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

const int mod = 1e9+7;

long long int dp[3001][3002];
int sum[3001];
char s[3001];
int r[3001];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>s[i];
		sum[i]=s[i]-'0';
		sum[i]+=sum[i-1];
	}
	for(int i=1;i<=n;i++)
		r[i]=i;
	for(int i=1,x,y;i<=m;i++){
		cin>>x>>y;
		r[x]=max(r[x],y);
	}
	dp[0][0]=1;
	int now=0;
	for(int i=0;i<n;i++){
		int tnow=max(now,r[i+1]);
		for(int j=0;j<=3000;j++){
			int ones,zeros;
			if(r[i+1]>now)
				ones=j+sum[tnow]-sum[now];
			else
				ones=j;
			zeros=tnow-ones-i;
			if(ones)
				dp[i+1][ones-1]=(dp[i+1][ones-1]+dp[i][j])%mod;
			if(zeros)
				dp[i+1][ones]=(dp[i+1][ones]+dp[i][j])%mod;
		}
		now=tnow;	
	}
	cout<<dp[n][0]<<endl;
}


Measured memory_bytes: 70656
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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;
}

const int BITS_LEN = 62;

vector<ll> a;
vector<ll> sums;

void calc_sums(const ll N) {
    vector<ll> part_sums(N + 1, 0);
    for (int i = 0; i < N; i++) {
        part_sums[i + 1] = part_sums[i] + a[i];
    }

    int ind = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            sums[ind] = part_sums[j + 1] - part_sums[i];
            ind++;
        }
    }
}

int main(void) {
    ll N, K;
    cin >> N >> K;

    a.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    ll sums_len = N * (N + 1) / 2;
    sums.resize(sums_len);
    calc_sums(N);

    // for (int i = 0; i < sums_len; i++) {
    //     cout << sums[i] << endl;
    // }
    // // sort by descending order
    // sort(sums.begin(), sums.end(), [](const ll &a, const ll &b) {
    //         return a > b;
    //         });

    ll cur = 0;
    for (int i = 40; i >= 0; i--) {
        ll ncur = cur + (1LL << i);
        int ok = 0;
        for (int j = 0; j < sums_len; j++) {
            if ((ncur & sums[j]) == ncur) ok++;
        }
        if (ok >= K) cur = ncur;
    }

    cout << cur << endl;

    return 0;
}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define Cin(x) cin >> x
#define Cin2(x,y) cin >> x >> y
#define Cin3(x,y,z) cin >> x >> y >> z
#define Cin4(w,x,y,z) cin >> w >> x >> y >> z
#define Cout(x) cout << x << "\n"
#define Cout2(x,y) cout << x << y << "\n"
#define Cout3(x,y,z) cout << x << y << z << "\n"
#define Cout4(w,x,y,z) cout << w << x << y << z << "\n"
#define Kaigyou cout << "\n"
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define Size(n) (n).size()
#define All(v) (v).begin(), (v).end()

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

    ll a,b; Cin2(a,b);
    if(b%a==0){
        Cout(a+b);
    }else{
        Cout(b-a);
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

    int N;
    scanf("%d", &N);

    int h[N];
    for (int i = 0; i < N; i++){
        scanf("%d", &h[i]);
    }

    int highest = 0;

    for (int i = 0; i < N; i++){

        if(highest < h[i]){
            highest = h[i];
        }
    }

    int ans = 0;

    for (int i = 0; i < highest; i++){

        int judge;

        if(h[0] > 0){
            judge = 1;
        }else{
            judge = 0;
        }

        for (int n = 0; n < N - 1; n++){

            if((h[n]<=0)&&(h[n+1]>0)){
                judge += 1;
            }
        }

        for (int n = 0; n < N; n++){
            h[n] -= 1;
        }

        ans += judge;
    }

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<tuple>
using namespace std;

int n, m;
string s;

typedef pair<int, int> P;
typedef vector<int> VI;
typedef tuple<string, int, int> TU;

bool comp(const TU& a, const TU&b) {
	if (get<0>(a)< get<0>(b))
	{
		return 1;
	}
	else if (get<0>(a) > get<0>(b)) {
		return 0;
	}
	else {
		return get<1>(a) > get<1>(b);
	}
}


int main() {
	cin >> n>>m;
	VI k(m);
	vector<int> s[11];
	VI p(m);
	int a;
	for (int i = 0; i < m; i++)
	{
		cin >> k[i];
		for (int j = 0; j < k[i]; j++)
		{
			cin >> a;
			s[i].push_back( a - 1);
		}
	}
	for (int i = 0; i < m; i++)
	{
		cin >> p[i];
	}
	int ans = 0;
	for (int i = 0; i < (1<<n); i++)
	{
		int temp = 0;
		for (int j = 0; j < m; j++)
		{
			int cnt = 0;
			for (int l = 0; l < k[j]; l++)
			{
				if (i&(1<<s[j][l]))
				{
					cnt++;
				}
			}
			if ((cnt+p[j])%2==0)
			{
				temp++;
			}
		}
		if (temp==m)
		{
			ans++;
		}
	}
	cout << ans << endl;
}

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

// BE CAREFUL WITH HASH TABLE & UNORDERED MAP
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define MOD 998244353
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = (b-1); i >= (a); i--)
#define RF0(i,b) RFO(i,0,b)
#define lli long long int
#define pii pair<int,int>
#define add(a,b) ((int) (((lli) (a) + (b))%MOD))
#define mul(a,b) ((int) (((lli) (a) * (b))%MOD))
#define PB emplace_back
#define F first
#define S second

// ifstream cin ("cinput.in");
// ofstream cout ("coutput.out");

int N, a;
lli dp [200000][2]; // best with i picked. 0: floor((i+1)/2); 1: ceil((i+1)/2)
// transition cands: i-2, i-3

// Helper Functions

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    lli ans = -__LONG_LONG_MAX__;
    cin >> a;
    dp[0][0] = 0; dp[0][1] = a;
    if (N <= 3) ans = max(ans, (lli) a);
    cin >> a;
    dp[1][0] = a; dp[1][1] = a;
    if (N <= 3) ans = max(ans, (lli) a);

    FOR(i,2,N) {
        cin >> a;
        dp[i][0] = dp[i-2][0];
        dp[i][1] = dp[i-2][1];
        // skip 2 cells
        if (i-3 >= 0) {
            if ((i+1)&1 == 0) dp[i][1] = max(dp[i][1], dp[i-3][1]);
            dp[i][0] = max(dp[i][0], dp[i-3][1]);
        }
        // skip 3 cells
        if (i-4 >= 0 && (i-2)/2 + 1 == (i+1)/2) dp[i][0] = max(dp[i][0], dp[i-4][1]);
        dp[i][0] += a;
        dp[i][1] += a;
        if (i&1) {
            lli mx = max(dp[i][0], dp[i][1]);
            dp[i][0] = mx;
            dp[i][1] = mx;
        }
        // cout << i+1 << '\n';
        // cout << dp[i][0] << "   " << dp[i][1] << '\n';
        if ((i+1)/2 == N/2) ans = max(ans, dp[i][0]);
        if ((i+2)/2 == N/2) ans = max(ans, dp[i][1]);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 6776
#include <cassert>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

constexpr int BACKET_SIZE = 5000;

unsigned long long x;

inline void init(int x0) {
	x = x0;
}

inline long long generate() {
	long long res = static_cast<long long>(x);
	x ^= x << 13;
	x ^= x >> 7;
	x ^= x << 17;
	return res;
}

inline int get_idx(long long x) {
	static constexpr int HALF = BACKET_SIZE / 2;
	static constexpr double backet_hash = static_cast<double>((HALF - 1)) / LLONG_MAX;
	int res = HALF;
	if(x < 0) {
		x += LLONG_MAX;
		res = 0;
	}

	res += static_cast<int>(x * backet_hash);
	return res;
}

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

	int n, k, x0;
	cin >> n >> k >> x0;

	if(x0 == 0) {
		cout << 0 << endl;
		return EXIT_SUCCESS;
	}

	vector<int> cnt(BACKET_SIZE + 1, 0);

	init(x0);
	for(int i = 0; i < n; ++i) {
		const long long value = generate();
		++cnt[get_idx(value)];
	}

	int idx;
	for(int i = 0; i < BACKET_SIZE; ++i) {
		if(k <= cnt[i]) {
			idx = i;
			break;
		}
		else {
			k -= cnt[i];
		}
	}

	vector<long long> a;
	a.reserve(cnt[idx]);

	init(x0);
	for(int i = 0; i < n; ++i) {
		const long long value = generate();
		if(get_idx(value) == idx) {
			a.emplace_back(value);
		}
	}

	sort(a.begin(), a.end());
	cout << a[k - 1] << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N, M;
    cin >> N >> M;
    vector<int> v(N);
    REP(i,M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a]++;
        v[b]--;
    }

    bool ans = true;
    REP(i,N) if (v[i] % 2 != 0) {
        ans = false;
        break;
    }

    CFYN(ans)

    return 0;
}

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

int main() {
	int cards[4][13];
	for(int i=0; i<4; i++){
		for(int j=0; j<13 ;j++){
			cards[i][j]=0;
		}
	}
	int n;
	cin >> n ;
	for(int h=0; h<n ;h++){
		int num ;
		char mar ;
		cin>> mar >> num ;
		if(mar == 'S'){
			cards[0][num-1]=1;
		}
		if(mar == 'H'){
			cards[1][num-1]=1;
		}
		if(mar == 'C'){
			cards[2][num-1]=1;
		}
		if(mar == 'D'){
			cards[3][num-1]=1;
		}
	}
	for (int i=0; i<4 ; i++){
		for (int j=0 ; j<13 ; j++){
			if(cards[i][j] == 0){
				if(i == 0){cout<< "S " <<j+1 <<endl;}
				if(i == 1){cout<< "H " <<j+1 <<endl;}
				if(i == 2){cout<< "C " <<j+1 <<endl;}
				if(i == 3){cout<< "D " <<j+1 <<endl;}
			}
		}
	}
    return 0;
    }



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

int main(){
    char c[6];
    for(int i=0;i<6;i++)cin>>c[i];
    if(c[0]==c[5]&&c[1]==c[4]&&c[2]==c[3])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main(void){
  int x;
  vector<int> v;

  for(int i=0; i<5; i++){
    cin >> x;
    v.push_back(x);
  }

  sort(v.begin(), v.end(), greater<int>());

  for(int i=0; i<4; i++){
    cout << v[i] << " ";
  }
  cout << v[4] << endl;

  return 0;
}

Measured memory_bytes: 1220
extern crate core;

use std::fmt;
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
fn search(lower: f64, upper: f64, target: f64, eps: f64, k: i32, fail: f64) -> f64 {
    if lower > target + eps || upper < target - eps {
        0_f64
    }else if target - eps <= lower && upper <= target + eps {
        1_f64
    }else if k == 0 {
        let mid = (lower + upper) / 2_f64;
        if target - eps <= mid && mid <= target + eps {
            1_f64
        }else {
            0_f64
        }
    }else{
        let mid = (lower + upper) / 2_f64;
        if mid >= target {
            (1_f64 - fail) * search(lower, mid, target, eps, k - 1, fail) + fail * search(mid, upper, target, eps, k - 1, fail)
        }else {
            (1_f64 - fail) * search(mid, upper, target, eps, k - 1, fail) + fail * search(lower, mid, target, eps, k - 1, fail)
        }
    }
}
fn main(){
    let_all!(k: i32, lower: f64, upper: f64);
    let_all!(p: f64);
    let_all!(eps: f64);
    let_all!(target: f64);
    println!("{:.*}", 10, search(lower, upper, target, eps, k, p));
}



Measured memory_bytes: 5060
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
 
 
 
int main(){
	fast;
	string s;
	cin>>s;
	if(s[2]==s[3] && s[5]==s[4]) cout<<"Yes";
	else cout<<"No";
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int N = 1e5+10;
const ll INF = 1e15;

using namespace std;

vector<pair<int,ll>> Graph[N];
vector<ll> dist;

void dijkstra (int k, int n)
{
    dist.assign(n+1,INF);
    dist[k]=0;
    set<pair<ll,int>> q;
    q.insert({0LL,k});
    while (!q.empty())
    {
        int v=q.begin()->ss;
        q.erase(q.begin());
        for (auto e: Graph[v])
        {
            int to=e.ff;
            ll len=e.ss;
            if (dist[to]>dist[v]+len)
            {
                dist[to]=dist[v]+len;
                q.insert(mp(dist[to],to));
            }
        }
    }
}

main()
{
    fast;
    int n,a,b,q,k,i;
    ll c;
    cin>>n;
    for (i=0;i<n-1;i++)
    {
        cin>>a>>b>>c;
        Graph[a].pb(mp(b,c));
        Graph[b].pb(mp(a,c));
    }
    cin>>q>>k;
    dijkstra(k,n);
    int x,y;
    while (q--)
    {
        cin>>x>>y;
        cout<<dist[x]+dist[y]<<endl;
    }
}

Measured memory_bytes: 15344
use std::io::*;
use std::str::FromStr;

fn main() {
    let mut a: Vec<usize> = (0..4).map(|_| read::<usize>()).collect();
    a.sort();
    if a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9 {
        println!("YES");
    } else {
        println!("NO");
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
 
const int A = 26;
int ct[A];

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

    int n, m;
    cin >> n >> m;

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

        for (const char &c : s) {
            ct[c - 'a']++;
        }
    }

    int req[5] = {0, 0, 0, 0, 0};

    for (int i = 0; i < (n + 1) / 2; i++) {
        for (int j = 0; j < (m + 1) / 2; j++) {
            req[(i * 2 == n - 1 ? 1 : 2) 
                * (j * 2 == m - 1 ? 1 : 2)]++;
        }
    }

    if (req[1]) {
        for (int i = 0; i < A; i++) {
            if (ct[i] & 1) {
                ct[i]--;
                break;
            }
        }
    }

    for (int i = 0; i < A; i++) {
        if (ct[i] & 1) {
            cout << "No\n";
            return 0;
        }
    }

    for (int i = 0; i < A; i++) {
        if ((ct[i] & 3)) {
            if (req[2] == 0) {
                cout << "No\n";
                return 0;
            }
            req[2]--;
            ct[i] -= 2;
        }
    }

    if (req[2] & 1) {
        cout << "No\n";
    }
    else {
        cout << "Yes\n";
    }    

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <math.h>
using namespace std;

typedef long long ll;

/*
const ll M = 1000000007;
vector<ll> fac(3001);
vector<ll> ifac(3001);
ll mpow(ll x, ll n){
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}
 
ll comb(ll a, ll b){
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0 || b < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
*/


ll lcm(ll a,ll b){
 
  ll r, x, tmp;
  x = a * b;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}

ll gcd(ll a ,ll b){
    if(a==0){return b;}
    else if(b==0){return a;}
    else{
    ll tmp,r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
    }
}

bool sosu(ll p){
    bool ans = true;
    double psqrtd = pow(p, 0.5);
    ll psqrt = psqrtd;
    for(ll i = 2; i <= psqrt; i++){
        if(p%i==0)ans = false;
    }
    if(p==1)ans = false;
    return ans;
}



int main(void){
    string s;
    cin >> s;
    if(s.at(0)=='S')cout << "Cloudy" << endl;
    if(s.at(0)=='C')cout << "Rainy" << endl;
    if(s.at(0)=='R')cout << "Sunny" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <complex>
#include <string>
#define pb push_back
#define pll pair <ll, ll>
#define MOMI using namespace std;
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#pragma optimize("TKACHENKO-GORYACHENKO")
#pragma GCC optimize("O3")
 
//#pragma GCC optimize("unroll-loops")
 
typedef long long ll;
 
typedef long double ld;
 
using namespace std;
 
const ll maxn = 3e6;

ll A[maxn];
 
ll n, m, k;

int main() {
    ll q, w, e, a, b, c;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 1;
    for (q = 1; q < n; q++) {
        if (s[q] != s[q - 1]) {
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 512
N, K = [int(i) for i in input().split(' ')]
A = [0]
A.extend([int(a) for a in input().split(' ')])
check_list = [0] * (N + 1)

town = 1
check_point = 0
initial = -1
interval = -1

for k in range(K):
    if check_list[town] > 0:
        check_point = town
        initial = check_list[town]
        interval = k - initial
        break
    check_list[town] = k
    town = A[town]

if interval == -1:
    print(town)
    exit(0)

remain = K - k

rem = remain % interval

check_list_ = list(map(lambda x: x - initial, check_list))

for i, c in enumerate(check_list_):
    if c == rem:
        print(i)
        exit(0)

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

int main() {
  int N;
  cin >> N;
  double a, b;
  if (N % 2 == 0) {
    cout << "0.5000000000";
  }
  else {
    a = N;
    b = ((a / 2) + 0.5) / a;
    cout << b;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
    int ans = n;
    vector<int> b(m);
    vector<int> p(n);
    while (true) {
        vector<int> c(m);
        if (accumulate(b.begin(), b.end(), 0) >= m - 1) {
            break;
        }
        for (int i = 0; i < n; i++) {
            while (b[a[i][p[i]]]) {
                p[i]++;
            }
            c[a[i][p[i]]]++;
        }
        ans = min(ans, *max_element(c.begin(), c.end()));
        vector<int> t;
        int mx = *max_element(c.begin(), c.end());
        for (int i = 0; i < m; i++) {
            if (c[i] == mx) {
                t.emplace_back(i);
            }
        }
        for (int i : t) {
            b[i] = 1;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3940
n=int(input())
a=list(map(int,input().split()))
for i in range(n-1,-1,-2):
    print(a[i],end=" ")
if n%2==1:
    for i in range(1,n-1,2):
        print(a[i],end=" ")
else:
    for i in range(0,n-1,2):
        print(a[i],end=" ")

Measured memory_bytes: 26180
#include <stdio.h>
int main()
{
    long int a,b,W;
    scanf("%ld%ld%ld",&W,&a,&b);
    printf("%ld\n",((a<=b)&&(b<=a+W)) || ((b<=a)&&(a<=b+W))?0:((b-a-W)>(a-b-W)?(b-a-W):(a-b-W)));
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define m_p make_pair
const int N = 100005;

int ansx;
vector<pair<int, int> > ans;

int t[N];
int solv(vector<int> v)
{
    sort(v.begin(), v.end());
    int i = 0;
    for (int j = 1; j < v.size(); j += 2)
        t[j] = v[i++];
    for (int j = 0; j < v.size(); j += 2)
        t[j] = v[i++];
    ans.push_back(m_p(t[v.size() - 2], t[v.size() - 1]));
    int x = t[v.size() - 2] - t[v.size() - 1];
    for (i = v.size() - 3; i >= 0; --i)
    {
        ans.push_back(m_p(t[i], x));
        x = t[i] - x;
    }
    return x;
}

vector<int> d, b;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        if (x <= 0)
            b.push_back(x);
        else
            d.push_back(x);
    }

    sort(d.begin(), d.end());
    reverse(d.begin(), d.end());
    sort(b.begin(), b.end());

    if (d.empty())
    {
        d.push_back(b.back());
        b.pop_back();
    }
    else if (b.empty())
    {
        b.push_back(d.back());
        d.pop_back();
    }

    while (d.size() > 1)
    {
        ans.push_back(m_p(b.back(), d.back()));
        int x = b.back() - d.back();
        d.pop_back();
        b.pop_back();
        b.push_back(x);
    }
    ansx = d[0];
    for (int i = 0; i < b.size(); ++i)
    {
        ans.push_back(m_p(ansx, b[i]));
        ansx -= b[i];
    }
    cout << ansx << endl;
    for (int i = 0; i < n - 1; ++i)
        cout << ans[i].first << ' ' << ans[i].second << endl;
    return 0;
}


Measured memory_bytes: 5104
#include<stdio.h>


int main(void){

	long x;
	long count;
	int a;
	scanf("%ld",&x);

	count = (x/11)*2;
	a = x%11;

	if(a>0 && a<=6){
		count++;
	}else if(a>6 && a<=11){
		count +=2;
	}else if(a==0){
	}



printf("%ld\n",count);
}	

Measured memory_bytes: 256
mod = 1000000000+7

def product(N, As):
  result = 0
  summer = sum(As)
  for i in range(N-1):
    left = As[i]
    summer = summer - left
    result += left * summer
    
  return result % mod


if __name__ == "__main__":
  N = list(map(int, input().split()))
  As = list(map(int, input().split()))
  print(product(N[0], As))

Measured memory_bytes: 31576
#include<bits/stdc++.h>
using namespace std;
long long int a[100000],temp1=-10000000,temp2=10000000;
int main()
{
long long int n,i,sum=0;
cin>>n;

for(i=0;i<n;i++)
{
    cin>>a[i];
}


 for(i=0;i<n;i++)
{
    sum=sum+a[i];

   if(temp1<a[i])
    temp1=a[i];

   if(temp2>a[i])
    temp2=a[i];


}

cout<<temp2<<" "<<temp1<<" "<<sum<<endl;

}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using ll=long long;
using namespace std;
const long MOD=1e9+7;
template<class T>
T lcm(T a,T b){
    return a/__gcd(a,b)*b;
}
template<class T>
void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}

int main(){
    long n,k,q;
    cin >> n >> k >> q;
    vector<long> a(n+1,0);
    for(int i=0;i<q;i++){
        long j;
        cin >> j;
        a[j]++;
    }
    for(int i=1;i<=n;i++){
        if(q-a[i]>=k){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1408
mod = 10 ** 9 + 7

# permutation: n * (n-1) * …… * (n-k+1) (mod p)
def prm(n, k, p=10**9+7):
    res = 1
    for i in range(k):
        res = res * (n-i) % p
    return res

# note: p must be a prime number
# フェルマーの小定理より
def modinv(a, p):
  return pow( a, p-2, p )
  
# combination: nPk / k! (mod p), note: p must be a prime number
def cmb(n, k, p=10**9+7):
    k = min(k, n - k)
    return prm( n, k ) * modinv( prm(k, k), p ) % p

n, a, b = map(int, input().split())

#何も選ばない1通りを除く
ans = pow(2,n,mod) - 1 - cmb(n,a) - cmb(n,b)
print(ans % mod)

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

using namespace std;

const auto INF = 1e9;

int n, A, B, C;
vector<int> L;

int dfs(int depth, int a, int b, int c) {
    if (depth == n) {
        if (a == 0 or b == 0 or c == 0) {
            return INF;
        } else {
            //1本目は合成コスト30が不要。その分をまとめて引く。
            return abs(a - A) + abs(b - B) + abs(c - C) - 30;
        }
    }

    int res = dfs(depth + 1, a, b, c);// i本目を使わない
    res = min(res, dfs(depth + 1, a + L[depth], b, c) + 10);// Aに使う
    res = min(res, dfs(depth + 1, a, b + L[depth], c) + 10);// Bに使う
    res = min(res, dfs(depth + 1, a, b, c + L[depth]) + 10);// Cに使う
    return res;
}

int main() {
    cin >> n >> A >> B >> C;
    L.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> L[i];
    }

    cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}


Measured memory_bytes: 256