akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())	//昇順
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())	//降順
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	mat c(3, vec(3));

	REP(i, 3) {
		REP(j, 3) {
			cin >> c[i][j];
		}
	}

	// vec a(3), b(3);
	bool ans = true;
	REP(i, 3) {
		if (c[i][0] - c[i][1] != c[(i + 1) % 3][0] - c[(i + 1) % 3][1] || c[i][0] - c[i][2] != c[(i + 1) % 3][0] - c[(i + 1) % 3][2] || c[i][2] - c[i][1] != c[(i + 1) % 3][2] - c[(i + 1) % 3][1]) {
			ans = false;
			break;
		}
		else if (c[0][i] - c[1][i] != c[0][(i + 1) % 3] - c[1][(i + 1) % 3] || c[0][i] - c[2][i] != c[0][(i + 1) % 3] - c[2][(i + 1) % 3] || c[2][i] - c[1][i] != c[2][(i + 1) % 3] - c[1][(i + 1) % 3] ) {
			ans = false;
			break;
		}
	}

	if(ans) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,c[200010],x,y,sonn[200010],ans[200010],lst[200010],a[200010],fa[200010];
vector <LL> g[200010],v[200010];

LL dfs_pre(LL pos,LL par)
{
	fa[pos]=par;
	sonn[pos]=1;
	rep(i,g[pos].size()) if(g[pos][i]!=par) sonn[pos]+=dfs_pre(g[pos][i],pos);
	return sonn[pos];
}

void dfs(LL pos,LL par)
{
	if(lst[c[pos]]==0) a[c[pos]]+=sonn[pos];
	else v[lst[c[pos]]].pb(pos);
	LL sv=lst[c[pos]];
	rep(i,g[pos].size()) if(g[pos][i]!=par)
	{
		lst[c[pos]]=g[pos][i];
		dfs(g[pos][i],pos);
	}
	lst[c[pos]]=sv;
}

int main()
{
	cin>>n;
	repn(i,n) scanf("%lld",&c[i]);
	rep(i,n-1)
	{
		scanf("%lld%lld",&x,&y);
		g[x].pb(y);
		g[y].pb(x);
	}
	dfs_pre(1,0);
	dfs(1,0);
	for(int i=2;i<=n;i++)
	{
		LL sum=0;
		rep(j,v[i].size()) sum+=sonn[v[i][j]];
		//cout<<i<<' '<<sum<<' '<<c[fa[i]]<<endl;
		ans[c[fa[i]]]+=(sonn[i]-sum)*(sonn[i]-sum+1)/2;
	}
	//repn(i,n) cout<<ans[i]<<' ';cout<<endl;
	repn(i,n) ans[i]+=(n-a[i])*(n-a[i]+1)/2;
	repn(i,n) printf("%lld\n",n*(n+1)/2-ans[i]);
	return 0;
}

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

const int maxn = 1000 + 5;
int n, m;
int mem[maxn];

bool Input()
{
	cin >> n >> m;
	if(!n && !m) return false;
	for(int i = 0; i < n; i++)
	{
		cin >> mem[i];
	}
	return true;
}

int solve()
{
	sort(mem, mem+n);
	int ans = -1, tmp;
	for(int i = n-1; i >= 0; i--)
		for(int j = i-1; j >= 0; j--)
		{
			//cout << mem[i] << " " << mem[j] << endl;
			tmp = mem[i]+mem[j];
			if(tmp > ans && tmp <= m) ans = tmp;
		}
	if(ans >= 0) return ans;
	return -1;
}

void Init()
{
	memset(mem, 0, sizeof(0));
}

int main()
{
	while(1)
	{
		Init();
		if(!Input()) break;
		int res = solve();
		if(res >= 0) printf("%d\n", res);
		else printf("NONE\n");
	}
}


Measured memory_bytes: 3264
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int N,Y;
  cin>>N>>Y;
  
  long long int ans1,ans2,ans3;
  
  bool flag=false;
  
  for(long long int i=0;i<=N;i++){
if(i*10000<=Y){
  for(long long int j=0;j<=N;j++){
    ans3=(Y-i*10000-j*5000)/1000;
if(i*10000+j*5000+ans3*1000==Y&&i+j+ans3==N&&ans3>=0){
  ans1=i;
  ans2=j;
  flag=true;
  
  
  break;
}
  }
  }
  
if(flag){
  break;
}
  }
  if(flag){
  
  printf("%d %d %d",ans1,ans2,ans3);
  }
  else{
    printf("%d %d %d",-1,-1,-1);
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
char s[15];
int main() {
    //freopen("in.txt","r",stdin);
    scanf("%s",s);
    int n=strlen(s);
    if(n&1) printf("No\n");
    else {
        bool f=true;
        for(int i=0;i<n;i+=2) {
            if(s[i]!='h'||s[i+1]!='i') f=false;
        }
        printf("%s\n",f?"Yes":"No");
    }
    return 0;
}

Measured memory_bytes: 256
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 100005
#define MAX_M 5005
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
char S[MAX_N];
int two_pow[MAX_N];
void init() {
	two_pow[0] = 1;
	for (int i = 1; i < MAX_N; i++) two_pow[i] = two_pow[i - 1] * 2 % MOD;
}
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	init();
	scanf("%*d");
	scanf("%s", S);
	int count[26] = { 0 };
	for (char ch : S) count[ch - 'a']++;
	int res = 1;
	for (int k = 0; k < 26; k++)
		res = 1LL * res * (count[k] + 1) % MOD;
	res--;
	printf("%d\n", res);
	return 0;
}

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

int main() {
    int64_t N, M;
    cin >> N >> M;
    vector<int64_t> p(M);
    vector<string> S(M);
    for (int64_t i = 0; i < M; i++) {
        cin >> p[i] >> S[i];
        p[i]--;
    }

    int64_t ac_num = 0, penalty = 0;
    vector<int64_t> wa_num(N, 0);
    vector<bool> ac(N, false);
    for (int64_t i = 0; i < M; i++) {
        if (S[i] == "AC") {
            //すでにacだったらどうでも良い
            if (ac[p[i]]) {
                continue;
            }

            penalty += wa_num[p[i]];
            ac[p[i]] = true;
        } else {
            wa_num[p[i]]++;
        }
    }

    for (int64_t i = 0; i < N; i++) {
        ac_num += ac[i];
    }

    cout << ac_num << " " << penalty << endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define INF (1e9)
#define se second
#define f first
#define N 505
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
int dijkstra();
int w,h,n,sy,sx,gy,gx,ay,ax,t,c[4][N][N],d[N][N];
 
int main(){
  string s;
  cin>>w>>h>>n;
  cin>>sx>>sy>>gx>>gy;
  while(n--){
    cin>>ax>>ay;
    cin>>t>>s;
    string a=s;
    while(--t) s+=a;
    for(int i=0;i<s.size();i++){
      if(s[i]=='L'&&ax!=0) c[3][ay][ax]++,c[1][ay+1][ax]++,ax--;
      if(s[i]=='U'&&ay!=0) c[2][ay][ax]++,c[0][ay][ax+1]++,ay--;
      if(s[i]=='R'&&ax!=w-1) c[1][ay+1][ax+1]++,c[3][ay][ax+1]++,ax++;
      if(s[i]=='D'&&ay!=h-1) c[0][ay+1][ax+1]++,c[2][ay+1][ax]++,ay++;
    }
  }
  cout<<dijkstra()<<endl;
  return 0;
}
 
int dijkstra(){
  priority_queue<P1,vector<P1>,greater<P1> > q;
  int dy[4]={0,-1,0,1},dx[4]={-1,0,1,0};
  for(int i=0;i<=h;i++)
    for(int j=0;j<=w;j++) d[i][j]=INF;
  for(int i=0;i<4;i++) d[sy][sx]=0,q.push(P1(0,P(sy,sx)));
  while(!q.empty()){
    P1 t=q.top(); q.pop();
    int cost=t.f,y=t.se.f,x=t.se.se;
    if(d[y][x]<cost) continue;
    for(int i=0;i<4;i++){
      int ny=y+dy[i],nx=x+dx[i],co=c[i][y][x];
      if(ny<0||nx<0||h<ny||w<nx) continue;
      if(d[ny][nx]>cost+co){
    d[ny][nx]=cost+co;
    q.push(P1(cost+co,P(ny,nx)));
      }
    }
  }
  return d[gy][gx];
}

Measured memory_bytes: 10936
#include <iostream>

using namespace std;

int main(){
	int A, B, C;
	int ans = 0;
	cin >> A >> B >> C;
	
	while(1){
		if(A % 2 == 1 || B % 2 == 1 || C % 2 == 1) break;
		if(ans == 100000){
			ans = -1;
			break;	
		}
		int tmp1,tmp2,tmp3;
		tmp1 = A/2; tmp2 = B/2; tmp3 = C/2;
		A = tmp2 + tmp3;
		B = tmp1 + tmp3;
		C = tmp1 + tmp2;
		++ans;
	}	
	cout << ans << endl;
}


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

using namespace std;

int main()
{
    int n ;
    cin>>n ;
    int MAX = 0 , MIN = 1e9 ;
    for(int i = 0 ; i < n  ; ++i)
    {
        int x ;
        cin>>x ;
        if(x < MIN)
            MIN = x ;
        if(x > MAX)
            MAX = x ;
    }
    cout<<MAX-MIN;
    return 0 ;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
    int x,y,h,w;
     
    while(1){
        scanf("%d %d\n",&x,&y);
        if(0 == x && 0 == y){
            break;
        }else{
            for(h = 0; h < x; h++){
                for(w = 0; w < y; w++){
                    if(h == 0 || h == x -1){
                        printf("#");
                    }else{
                        if(w == 0 || w == y - 1){
                            printf("#");
                        }else{
                            printf(".");
                        }
                    }
                    
                }
                printf("\n");
            }
            printf("\n");
        }
    }
     
    return 0;
}
 

Measured memory_bytes: 1736
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <unordered_map>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

int main() {
    vector<unsigned long long> s(5, 0);
    unordered_map<char, int> m;

    m['M'] = 0;
    m['A'] = 1;
    m['R'] = 2;
    m['C'] = 3;
    m['H'] = 4;

    int N;
    cin >> N;

    REP(i, N) {
        string str;
        cin >> str;

        if (m.find(str[0]) != m.end()) s[m[str[0]]]++;
    }

    unsigned long long result = 0;
    for (int i = 0; i < 5; i++)
        for (int j = i + 1; j < 5; j++)
            for (int k = j + 1; k < 5; k++) result += s[i] * s[j] * s[k];

    cout << result << 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, x;
		int count;
		
		while(true){
			n = sc.nextInt();
			x = sc.nextInt();
			count = 0;
			
			if ((n == 0) && (x == 0)){
				break;
			}
			
			for (int i = 1; i <= n; i++){
				for (int j = i + 1; j <= n; j++){
					for (int k = j + 1; k <= n; k++){
						if ( i + j + k == x){
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
		

	}
}

Measured memory_bytes: 19588
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <functional>
#include <array>

using namespace std;
int64_t s, c;


int main(){
	
	cin >> s >> c ;
	
	int64_t SccS = 0;
	if (c >= 2 * s) {
		SccS = s;
		c -= 2 * s;
		s = 0;
	}
	else {
		SccS = c / 2;
		s -= c / 2;
		c = c % 2;
	}
	
	int64_t SccC = c / 4;

	cout << SccS + SccC << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N;
	cin >> N;
	ll ans = 0;
	for (int i = 1; i <= N; i++)
	{
		if (!(i%15 == 0 || i%3 == 0 || i%5 == 0))
			ans += i;
	}
	cout << ans << endl;
}



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

int main(){
    int n,m; cin >> n >> m;
    vector<int> a(m);
    for(int i=0;i<m;++i) cin >> a[i];
    long long sum=0;
    for(int i=0;i<m;++i) sum += a[i];
    long long ans = 0;
    ans = n - sum;
    if(ans >=0) cout << ans << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3672
N=int(input())
A,B=map(int,input().split())
P=list(map(int,input().split()))
p1,p2,p3=0,0,0
for pnt in P:
  if pnt <=A:
    p1+=1
  elif pnt <=B:
    p2+=1
  else:
    p3+=1
print(min([p1,p2,p3]))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;


int main()
{
  int A,B,C,D;
  int rect1, rect2;

  cin >> A >> B >> C >> D;

  rect1 = A * B;
  rect2 = C * D;

  if(rect1 > rect2) {
    cout << rect1 << endl;
  } else {
    cout << rect2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 5010;

void z_algorithm(string s, vector<int>& z) {
	z[0] = s.size();
	int i = 1, j = 0;
	while(i < s.size()) {
		while(i + j < s.size() && s[j] == s[i + j]) j++;
		z[i] = j;

		if(j == 0) {i++; continue;}
		int k = 1;
		while(k < j && k + z[k] < j) {z[i + k] = z[k]; k++;}
		i += k;
		j -= k;
	}
}

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> z(n);
	int ans = 0;
	for(int i = 0; i < n; i++) {
		int n2 = s.size() - i;
		z_algorithm(s.substr(i, n2), z);
		for(int j = 0; j < n2; j++) {
			if(z[j] <= j) {
				ans = max(z[j], ans);
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())

abc = list()
for _ in range(N):
    abc.append(list(map(int,input().split(' '))))


for i in range(N):
    if i == 0:
        continue
    
    for j in range(3):
        a = abc[i-1][(j + 1)%3] 
        b = abc[i-1][(j + 2)%3] 
        abc[i][j] += a if a>b else b


print(max(abc[-1]))

Measured memory_bytes: 30580
import java.io.PrintWriter;
import java.util.BitSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
		 PrintWriter out = new PrintWriter(System.out);
		 StringBuilder sb = new StringBuilder();
		 
		 int N = sc.nextInt();
		 BitSet in = new BitSet(N + 1);
		 BitSet result = new BitSet(N + 1);
		 
		 for (int i = 1; i <= N; i++) {
			 in.set(i, sc.nextInt() == 1);
		 }
		 
		 for (int i = N; i >= 1; i--) {
			 boolean t = in.get(i);
			 for (int j = i * 2; j <= N; j += i) {
				 t ^= result.get(j);
			 }
			 result.set(i, t);
		 }
		 
		 out.println(result.cardinality());
		 for (int i = 1; i <= N; i++) {
			 if (result.get(i)) {
				 sb.append(i).append(" ");
			 }
		 }
		 out.println(sb);
		 
		 sc.close();
		 out.flush();
		 

	}

}


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

#define INF64 1LL << 60;
#define INF32 1 << 29;

using namespace std;

void execute()
{
	int M500, M100, M50;
	int total;
	int total2;
	int ans = 0;
	cin >> M500 >> M100 >> M50 >> total;

	for (int i = 0; i <= M500; i++)
	{
		for (int j = 0; j <= M100; j++)
		{
			total2 = i * 500 + j * 100;
			if (total < total2)
				break;
			if ((total - total2) / 50 <= M50)
				ans++;
		}
	}
	cout << ans << endl;
	return;
}

int main()
{
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A>= B){
        if(C >= B && C <= A){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    
    else{
        if(C >= A && C <= B){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
	map<string, int> mp;

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

	string str;
	while (n--)
	{
		cin >> str;
		++mp[str];
	}

	printf("AC x %d\n", mp["AC"]);
	printf("WA x %d\n", mp["WA"]);
	printf("TLE x %d\n", mp["TLE"]);
	printf("RE x %d\n", mp["RE"]);

	return 0;
}


Measured memory_bytes: 3784
#include <stdio.h>

int main(void) {
	unsigned long long int ans[16][1024]={0};
	int i,j,k,n,s;
	ans[1][0] = 1;
	for(i = 1;i <= 100;i++){
		for(j = 8;j >= 1;j--){
			for(k = 0;(k + i) <= 1000;k++){
				ans[j+1][k+i]+=ans[j][k];
			}
		}
		ans[1][i] = 1;
	}
	while(scanf("%d%d",&n,&s) , n != 0){
		printf("%llu\n",ans[n][s]);
	}
	return 0;
}

Measured memory_bytes: 740
#include <bits/stdc++.h>
using namespace std;
int N;
int calc(int x){
    int ret = 0;
    while(x){
        ret += x % 10;
        x /= 10;
    }
    return ret;
}
int main(){
    scanf("%d", &N);
    if(N % calc(N) == 0)    puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <tuple>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

LL Max(LL a, LL b)
{
    return a > b ? a : b;
}

LL f(LL x, LL bitIndex)
{
    if (x < 0) return 0;
    LL bitCycle = 1LL << bitIndex;
    LL ans = 0;
    ans += bitCycle * ((x + 1) / (bitCycle * 2));
    ans += Max(((x + 1) % (bitCycle * 2)) - bitCycle, 0);
    return ans;
}

int main()
{
    LL A, B;
    cin >> A >> B;
    bitset<50> ans(0);
    REP(i, 45)
    {
        LL oneNum = f(B, i) - f(A - 1, i);
        ans.set(i, oneNum % 2 == 1);
    }
    cout << ans.to_ullong() << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    char s[n+1];
    scanf("%s",s);
    int i,count=0;
    for(i=0;i<n-2;i++)
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
            count++;
    printf("%d\n",count);
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a<=b) {
    cout << a << endl;
  }
  else {
    cout << a-1 << endl;
  }
}


Measured memory_bytes: 3608
#include <iostream>
#include <list>

using std::cin;
using std::cout;
using std::endl;
using std::list;

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

	while ( n != 0 || k != 0 || m != 0 ) {
		list<int> nums(n, 0);
		int num = 1;
		for (list<int>::iterator itr = nums.begin(); itr != nums.end(); ++itr) {
			*itr = num;
			num++;
		}
		
		int count_s = n;
		int rm = m;
		int l;
		bool first = true;

		for (list<int>::iterator itr = nums.begin(); count_s != 1;) {
			if ( first ) {
				for (int i = 0; i < rm-1; i++) {
					++itr;
					if ( itr == nums.end() ) {
						itr = nums.begin();
					}
				}
				first = false;
			}
			else {
				l = ((k-1)%count_s) + 1;
				for (int i = 0; i < l; i++) {
					++itr;
					if ( itr == nums.end() ) {
						itr = nums.begin();
					}
				}
			}

			itr = nums.erase(itr);
			if ( count_s == n ) {
				rm = k;
			}
			count_s--;
			if (count_s != 1) {
				--itr;
			}
		}
		cout << *nums.begin() << endl;
		cin >> n >> k >> m;
	}

	return 0;
}

Measured memory_bytes: 3380
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,c,k;
    long long summax=0;

    cin>>a>>b>>c>>k;
    if(a>=k){
        cout<<k<<endl;
        return 0;
    }else{
        summax+=a;
        k-=a;
    }
    if(b>=k){
        cout<<summax<<endl;
        return 0;
    }else{
        k-=b;
    }
    summax-=k;
    cout<<summax<<endl;
    return 0;
}

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

int main(void)
{
    int n, w;
    cin >> n >> w;

    vector<int> wi(n,0);
    vector<int> vi(n,0);

    for(int i = 0; i < n; ++i)
    {
        int w_tmp, v_tmp;
        cin >> w_tmp >> v_tmp;
        wi.at(i) = w_tmp;
        vi.at(i) = v_tmp;
    }
    
    vector<vector<long long int>> vt(n+1,vector<long long int>(w+1,0));

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j <= w; ++j)
        {
            if(j-wi.at(i) >= 0)
            {
                vt.at(i+1).at(j) = max(vt.at(i+1).at(j), vt.at(i).at(j-wi.at(i))+vi.at(i));
            }

            vt.at(i+1).at(j) = max(vt.at(i).at(j), vt.at(i+1).at(j));                
        } 
    }
    
    cout << vt.at(n).at(w) << endl;

    return 0;
}



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

using namespace std;
using ll = long long;
ll max(ll a, ll b) {
    if (a > b) {
        return a;
    } else {
        return b;
    }
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll output = max(max(a * c, b * d), max(a * d, b * c));

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>

const int MAX   = 100;
const int INFTY = (1<<21);
const int WHITE = 0;
const int GRAY  = 1;
const int BLACK = 2;

int n, M[MAX][MAX];

void Dijkstra()
{
    int minv;
    int d[MAX], color[MAX];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0;
    color[0] = GRAY;
    while (1) {
        minv = INFTY;
        int u = -1;
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) break;
        color[u] = BLACK;
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) {
                if (d[v] > d[u] + M[u][v]) {
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    for (int i = 0; i < n; i++) {
        std::cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << std::endl;
    }
}

int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = INFTY;
        }
    }

    int k, c, u, v;
    for (int i = 0; i < n; i++) {
        std::cin >> u >> k;
        for (int j = 0; j < k; j++) {
            std::cin >> v >> c;
            M[u][v] = c;
        }
    }

    Dijkstra();

    return 0;
}


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

int main(){
    int a,b,c,d,e;
    cin>>a>>b>>c;
    d=max(a,b);
    e=max(d,c);
    cout<<a+b+c-e<<endl;
    
   return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;
public class Main {
	static Map<Long,ArrayList<String>> l=new TreeMap<Long,ArrayList<String>>();
	static long p[];
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		char c[]=sc.next().toCharArray();
		if(c[0]-'a'>=0&&c[0]-'b'<26) {
			System.out.println("a");
		}else {
			System.out.println("A");
		}
	}
	
	
}

 


Measured memory_bytes: 27032
#include<stdio.h>

int main()
{
    int cards[99][99]={0},a,c,i,j;
    char b, d[5]="SHCD";
    scanf("%d\n", &a);
    for(i = 0; i < a; cards[b][c] = 1,i++){
    	scanf("%c %d\n",&b,&c);
    }
    for(i=0;i<4;i++){
    	for(j=1;j<14;j++){
    		if(!cards[d[i]][j]){
    		    printf("%c %d\n",d[i],j);
    		}
    	}
    }
    return 0;
}

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

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	
	int mult = 1;
	int ans = 1;
	for(int i = 0; i < n; ++i){
		mult *= a[i] % 2 == 0 ? 2 : 1;
		ans *= 3;
	}
	cout << ans - mult << endl;
	return 0;
}



Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
const double eps=1e-9;
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
int N;
int main(){
    read(N);
    for (int h=1;h<=3500;h++){
        for (int n=1;n<=3500;n++){
            long double w=1.0/(4.0/N-1.0/h-1.0/n);
            if (w<0) continue;
            if (w-(int)w<eps){
                return printf("%d %d %d\n",h,n,(int)w)*0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
N,W = map(int,input().split())
WV = []
for i in range(N):
    WV.append(list(map(int,input().split())))
dp = [[float('inf') for j in range(100001)] for i in range(N)]
dp[0][0] = 0
for i in range(N):
    w,v = WV[i]
    if i == 0:
        dp[i][v] = w
    else:
        for j in range(100001):
            if j-v >= 0:
                dp[i][j] = min(dp[i-1][j-v]+w,dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]

ans = 0
for i,e in enumerate(dp[-1]):
    if W >= e:
        ans = i
print(ans)

Measured memory_bytes: 317684
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
	int n;
	int x;
	cin >> n>> x;
	int a[n];
	a[0] = x;
	for(int i = 1; i <n; ++i){
		cin >>a[i];
		x ^= a[i];
	}
	for(int i =0; i < n;++i)
		cout<<(x^a[i])<<" ";
}


Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    int A[N + 1], B[N];
    for(int i = 0; i < N + 1; i++) cin >> A[i];
    for(int i = 0; i < N; i++) cin >> B[i];
    ll ans = 0;
    for(int i = 0; i < N; i++) {
        if(A[i] >= B[i])
            ans += B[i];
        else if(A[i] + A[i + 1] <= B[i]) {
            ans += A[i] + A[i + 1];
            A[i + 1] = 0;
        } else {
            ans += B[i];
            A[i + 1] -= B[i] - A[i];
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int K,A,B;
    cin>>K>>A>>B;
    bool ans =false;
    for(int i=A;i<B+1;i++){
        if(i%K==0)ans=true;
    }
    if(ans)cout <<"OK"<<endl;
    else cout <<"NG"<<endl;
}


Measured memory_bytes: 3124
import java.io.*;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		while (true) {
			String[] cut = br.readLine().split(" ");
			int H = Integer.parseInt(cut[0]);
			int W = Integer.parseInt(cut[1]);
			if (H == 0 && W == 0)
				break;

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

				if (i % 2 == 1) {
					for (int j = 0; j < W; j++) {
						if (j % 2 == 1) {
							sb.append("#");
						}
						if (j % 2 == 0) {
							sb.append(".");
						}
					}
					sb.append("\n");
				}

				if (i % 2 == 0) {
					for (int k = 0; k < W; k++) {
						if (k % 2 == 1) {
							sb.append(".");
						}
						if (k % 2 == 0) {
							sb.append("#");
						}
					}
					sb.append("\n");
				}

			}

			sb.append("\n");
		}

		System.out.print(sb);

	}
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define x first
#define y second

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int n; cin >> n, n;){
        vector< vector<pii> > lines(n + 2);

        range(i, 1, n + 2){
            int m; cin >> m;

            lines[i] = vector<pii>(m);
            rep(j, m){
                cin >> lines[i][j].x >> lines[i][j].y;
            }
            if(i == 1){
                lines[0] = lines[1];
                reverse(all(lines[1]));
            }
        }

        rep(i, n + 2){
            pii dist = lines[i][0];

            rep(j, lines[i].size()){
                lines[i][j].x -= dist.x;
                lines[i][j].y -= dist.y;
            }
        }

        range(i, 2, n + 2){
            bool ok = false;
            rep(j, 2){
                if(lines[i].size() != lines[j].size()) break;
                rep(k, 4){
                    bool okk = true;
                    rep(l, lines[i].size()){
                        swap(lines[j][l].x, lines[j][l].y);
                        lines[j][l].y *= -1;
                        
                        if(lines[i][l] != lines[j][l]){
                            okk = false;
                        }
                    }
                    if(okk) ok = true;
                }
            }
            if(ok) cout << i - 1 << endl;
        }

        cout << "+++++" << endl;
    }

	return 0;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

int n,d[205];
int main(void){
	scanf("%d",&n);
	rep(i,n*2)scanf("%d",&d[i]);
	sort(d,d+n*2);
	
	int ans=0;
	rep(i,n){
		ans+=d[i*2];
	}
	printf("%d\n",ans);
	return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  double N, Na;
  int X, ans;
  
  cin >> N;
  Na = N + 0.99;
  X = Na / 1.08;
  ans = X * 1.08;

  if(N == ans){
    cout << X << endl;
  }
  else{
    cout << ":(" << endl;
  }
}

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

const int N = 1e5 + 100;

int n, a[N], l[N], r[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		l[i] = __gcd(l[i - 1], a[i]);
	}
	for (int i = n; i; i--)
		r[i] = __gcd(r[i + 1], a[i]);
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans = max(ans, __gcd(l[i - 1], r[i + 1]));
	cout << ans;
	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

const int MAX_M=10000,MAX_N=100000;

int d;
int n;
int m;
int dis[MAX_N+1];
int k[MAX_M];

vector<int> out;

int main(){
	do{
		scanf("%d",&d);
		if (d!=0){
			scanf("%d",&n);
			scanf("%d",&m);
			for (int i=0;i<n-1;i++){
				scanf("%d",&dis[i]);
			}
			for (int i=0;i<m;i++){
				scanf("%d",&k[i]);
			}
			//??¬????????????
			dis[n-1]=0;
			dis[n]=d;
			sort(dis,dis+n+1);
			int res=0;
			for (int i=0;i<m;i++){
				//k[i]???????????????
				int *p=lower_bound(dis,dis+n+1,k[i]);
				int distance;
				distance=*p-k[i];
				if (p!=dis){
					distance=min(distance,k[i]-*(p-1));
				}
				res+=distance;
			}
			out.push_back(res);
		}
	}while(d!=0);
	for (int i=0;i<out.size();i++){
		printf("%d\n",out[i]);
	}
	return 0;
}

Measured memory_bytes: 1480
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    string s;
    cin >> s;
    int N = s.size();

    for(int i=0; i<N; i++) {
        if(i+1 < N && s[i] == s[i+1]) {
            cout << i+1 << ' ' << i+2 << endl;
            return 0;
        } else if(i+2 < N && s[i] == s[i+2]) {
            cout << i+1 << ' ' << i+3 << endl;
            return 0;
        }
    }

    cout << "-1 -1" << endl;
    return 0;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
int G[200][200];
int dp[200][200];
int color[200];
int N;
bool check(int v, int c) {
	color[v] = c;
	for (int to = 0; to < N; to++) {
		if (!G[v][to]) continue;
		if (color[to] == c) return 0;
		if (color[to] == 0 && !check(to, -c)) return 0;
	}
	return 1;
}
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		string S;
		cin >> S;
		for (int j = 0; j < N; j++) G[i][j] = S[j] - '0';
	}
	if (!check(0, 1)) {
		cout << -1 << endl;
		return 0;
	}
	fill((int *)dp, (int *)(dp + N), 1<<25);
	for (int i = 0; i < N; i++) {
		dp[i][i] = 0;
		for (int j = 0; j < N; j++) if (G[i][j]) dp[i][j] = 1;
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}
	int d = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			d = max(d, dp[i][j]);
		}
	}
	cout << d + 1 << endl;
}

Measured memory_bytes: 640
N = gets.chomp.to_i
A = gets.chomp.split.map(&:to_i)

l = 0
r = 0
ans = 0
xored = 0 # The xor of A[l..r-1]. If l == r, then xored = 0. If r == l + 1, then xored = A[l]
while (l < N)
  while (r < N) && (xored ^ A[r] == xored + A[r])
    # p "A[#{l}]: #{A[l]}, A[#{r}]: #{A[r]}"
    xored = xored ^ A[r]
    r += 1
  end
  # Here, the condition is not satisfied between xored and A[r].
  ans += r - l  # (r-1)-l+1
  xored = xored ^ A[l] # decrease l
  l += 1
end

p ans

Measured memory_bytes: 16652
n, m = list(map(int, input().split()))
s = input()
t = input()

# import math
import fractions
gcdd = fractions.gcd(n, m)

for i in range(gcdd):
    if s[i*(n//gcdd)] != t[i*(m//gcdd)]:
        print(-1)
        exit()

print(n*m//gcdd)


Measured memory_bytes: 5304
t = input()
answer = []
for idx, w in enumerate(t):
    if w in ['P', 'D']:
        answer.append(w)
    else:
        if len(answer) != 0 and answer[-1] == 'P':
            answer.append('D')
        else:
            if idx == len(t) - 1:
                answer.append('D')
            elif t[idx + 1] in ['D', '?']:
                answer.append('P')
            else:
                answer.append('D')
print(''.join(answer))


Measured memory_bytes: 11076
N = int(input())
W = list(map(int,input().split()))
p = sum(W)
q = 0
for i in range(N):
    q += W[i]
    if q >= p/2:
        print(min(abs(p-2*sum(W[:i])),abs(p-2*sum(W[:i+1]))))
        exit()

Measured memory_bytes: 9132
n=int(input())
if n<10:
  print(n)
else:
  s=str(n)
  t=len(s)
  f=lambda x:sum(map(int,x))
  v=max(9*(t-1),f(s))
  for i in range(1,t):
    v=max(v,f(str(n-n%(10**i)-1)))
  print(v)

Measured memory_bytes: 3064
H, W = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]
n = 0
memo = []

for x in range(W):
  for y in range(H-1):
    if A[y][x]%2 == 1:
      A[y][x] -= 1
      A[y+1][x] += 1
      n += 1
      memo.append([y+1,x+1,y+2,x+1])
for x in range(W-1):
  if A[H-1][x]%2 == 1:
    A[H-1][x] -= 1
    A[H-1][x+1] += 1
    memo.append([H,x+1,H,x+2])
    n += 1
print(n)
for i in range(n):
  print(" ".join(map(str,memo[i])))

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

using namespace std;

#define DIM 200009
#define pairll pair<long long,long long>
#define fi first
#define se second
#define INF ((long long)1e18+9ll)
#define amen exit(0)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define endl '\n'
#define ld long double

long long i,j,k,l,n,m;

int main()
{
    fast;

    cin>>n;
    cout<<360/__gcd(360ll,n)<<endl;

    amen;
}

Measured memory_bytes: 3504
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1) {
        c -= b;
        if(c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3676
k,n = map(int,input().split())
a = [int(i) for i in input().split()]

mi = min(a[n-1]-a[0], (k-a[1])+a[0])

for i in range(1,n-1):
  tmp = min(k-(a[i]-a[i-1]), k-(a[i+1]-a[i]))
  mi = min(tmp,mi)

print(mi)

Measured memory_bytes: 26436
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> foods(m);
    for (int i = 0; i < n; ++i) {
        int k; cin >> k;
        for (int j = 0; j < k; ++j) {
            int a; cin >> a;
            foods[a - 1]++;
        }
    }
    int ans = 0;
    for (int i = 0; i < m; ++i) if (foods[i] == n) ans++;

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};



int main() {
    int h,w;cin>>h>>w;
    vector<string> s(h);cin>>s;
   
    int rows[h+1];rep(i,h+1)rows[i]=0;
    int cols[w+1];rep(i,w+1)cols[i]=0;
    
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#'){rows[i] = 1;cols[j]=1;}
        }
    }
    
    rep(i,h){
        string out;
        rep(j,w){
            if(rows[i]==1 && cols[j]==1)out+=s[i][j];
        }
        if(out.size()!=0)cout<<out<<endl;
    }
    

    return 0;
}





Measured memory_bytes: 256
import queue

K = int(input())

count = 0
q = queue.Queue()
for i in range(1, 10):
    count += 1
    q.put(i)
    if count == K:
        print(i)
        break

result = 0
while count != K:
    tmp = q.get()  # 先頭のキューを取り出す
    keta1 = tmp % 10  # 1の位を取得
    for i in range(-1, 2):
        if keta1 == 0 and i == -1:  # 1の位が0のとき
            continue
        if keta1 == 9 and i == 1:  # 1の位が9のとき
            continue
        result = tmp * 10 + (keta1 + i)
        q.put(result)  # 最後に付け足す
        count += 1
        if count == K:
            print(result)
            break
        else:
            continue

Measured memory_bytes: 6768
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
typedef long long ll;
using namespace std;
using namespace atcoder;

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

    dsu d(N);
    for (int i = 0; i < M; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
    
        d.merge(u-1, v-1);
    }

    map<int, int> mp;

    rep(i, N){
        mp[d.leader(i)]++;
    }

    cout << mp.size() - 1 << endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

template<class T>
class SegmentTree {

public:
    /**
     * @param N size
     * @param e identity element
     * @param operation operation for query
     * @param updater operation for update
     */
    SegmentTree(size_t N, T e, function<T(T, T)> operation, function<T(T, T)> updater)
            : e(e), operation(std::move(operation)), updater(move(updater)) {
        n = 1;
        while (n < N) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, e);
    }

    /**
     * iの値をxに更新
     * @param i index ( 0-indexed )
     * @param x  value
     */
    void update(int i, T x) {
        i += n - 1;
        data[i] = updater(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    /**
     * [a, b)の区間でクエリを実行
     */
    T query(int a, int b) {
        return query(a, b, 0, 0, n);
    }

    /**
     * 添字でアクセス
     * @param i index ( 0-indexed )
     */
    T operator[](int i) {
        return data[i + n - 1];
    }

private:
    int n;
    vector<T> data;
    T e;
    function<T(T, T)> operation;
    function<T(T, T)> updater;

    T query(int a, int b, int k, int l, int r) {
        // 交差しない
        if (r <= a || b <= l) return e;
        // 区間 [a, b) に l, r が含まれる
        if (a <= l && r <= b) return data[k];
        // 左の子
        T c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
        // 右の子
        T c2 = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return operation(c1, c2);
    }
};

void Main() {
    int N;
    cin >> N;
    vector<ll> H(N), A(N);
    rep(i, N) cin >> H[i];
    rep(i, N) cin >> A[i];

    vector<ll> dp(N + 1, 0);
    SegmentTree<ll> segmentTree(N + 1, 0, [](ll a, ll b) { return max(a, b); }, [](ll a, ll b) { return max(a, b); });

    rep(i, N) {
        ll h = H[i];
        ll a = A[i];
        ll x = segmentTree.query(0, h);
        dp[h] = x + a;
        segmentTree.update(h, dp[h]);
    }
    ll ans = 0;
    rep(i, N) {
        ans = max(ans, dp[i + 1]);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 9088