akhauriyash/Code-Regression huggingface dataset:
N, M = list(map(int, input().split()))
L = [0]*M
R = [0]*M
for i in range(M):
  L[i], R[i] = list(map(int, input().split()))

L_max = max(L)
R_min = min(R)
ok = 0
for i in range(N):
  if L_max <= i+1 <= R_min:
    ok += 1

print(ok)

Measured memory_bytes: 10996
#include <stdio.h>
int main(void){
    
    int S,h,m,s;
    
    scanf("%d",&S);
    
    h=S/3600;
    m=(S%3600)/60;
    s=(S%3600)%60;
    

    printf("%d:%d:%d\n",h,m,s);

    return 0;
    
}



Measured memory_bytes: 2104
def isPalindrome(s):
  n=len(s)
  i=0
  while(i<=(n-1)/2):
    if s[i]==s[-(i+1)]:
      i+=1
    else:
      return False
  return True

s=input()
n=len(s)

left = s[:(n-1)//2]
right = s[(n+3)//2-1:]

if isPalindrome(left) and isPalindrome(right):
  if isPalindrome(s):
    print("Yes")
  else:
    print("No")
else:
  print("No")


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm> 

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

using namespace std;

//const long long int inf = 1 << 20;

void dfs(int n, vector<vector<int>>& edge, vector<int>& vertex, vector<int>& ans) {
  vector<bool> check(n,false);

	stack<int> st;
	st.push(0);
	check[0] = true;

	while (!st.empty()) {
	  int s = st.top();
		st.pop();
		ans[s] += vertex[s];

			for (int i : edge[s]) if (!check[i]) {
			  ans[i] += ans[s];
			  st.push(i);
				check[i] = true;
			}
	}
	return;
}

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

	vector<vector<int>> edge(n);

	rep(i, n-1) {
	  int a, b;
		cin >> a >> b;
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	vector<int> vertex(n,0);

	rep(j, q) {
	  int p, x;
	  cin >> p >> x;
		p--;
		vertex[p] += x;
	}

	vector<int> ans(n,0);
	dfs(n, edge, vertex, ans);

	for (int v : ans) cout << v << " "; cout << endl;
}


Measured memory_bytes: 16372
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
board = []
for i in range(0, H):
	lst = []
	for j in range(0, W):
		lst.append('')
	board.append(lst)

h = 0
w = 0
index = 0
cnt = 0
while index < N:
	board[h][w] = str(index+1)
	cnt += 1
	if cnt == A[index]:
		index += 1
		cnt = 0
	if h % 2 == 0:
		if w+1 == W: h += 1
		else: w += 1
	else:
		if w-1 == -1: h += 1
		else: w -= 1
for i in range(0, H):
	ans = board[i][0]
	for j in range(1, W):
		ans = ans + ' ' + board[i][j]
	print(ans)


Measured memory_bytes: 41072
#include <cstdio>
#include <vector>
using namespace std;
int in_node[5000];
vector<int> node[5000];
int main() {
	vector<int> L,S;
	int n,m;
	bool not_only=false;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++) {
		int x,y;
		scanf("%d %d",&x,&y);
		node[x-1].push_back(y-1);
		in_node[y-1]++;
	}
	for(int i=0;i<n;i++) {
		if(in_node[i]==0) S.push_back(i);
	}
	if(S.size()>1) not_only=true;
	while(S.size()) {
		int s=S[S.size()-1];
		S.pop_back();
		L.push_back(s);
		int in_zero_cnt=0;
		for(int i=0;i<node[s].size();i++) {
			in_node[node[s][i]]--;
			if(in_node[node[s][i]]==0)
				in_zero_cnt++,S.push_back(node[s][i]);
		}
		if(in_zero_cnt>1) not_only=true;
	}
	for(int i=0;i<n;i++) {
		printf("%d\n",L[i]+1);
	}
	printf("%d\n",not_only);
}

Measured memory_bytes: 1876
#include<iostream>
#define MAXN 100000+10
using namespace std;
int par[MAXN];
int rank[MAXN];
int re[MAXN];
int n,q;
void init(){
	int i;
	for (i = 0;i < n;++i){
		rank[i]=0;
		par[i]=i;
	}
}

int find(int x){
	if (x == par[x]) return x;
	else return par[x]=find(par[x]);
}

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if (x == y) return;
	if (rank[x] < rank[y]) par[x]=par[y];
	else par[y]=par[x];
	if (rank[x] == rank[y]) rank[x]++;
	
}

int main(){
	int a,b,ord,i;
	int tot=0,p1,p2;
	cin>>n>>q;
	init(); 
	for (i = 0;i < q;++i){
		cin>>ord;
		cin>>a>>b;
		if (ord == 0){
			unite(min(a,b),max(a,b));
		}
		else if (ord == 1){
			p1=find(a);
			p2=find(b);
			if (p1 == p2) re[tot++]=1;
			else re[tot++]=0;
		}
	}
	for (i = 0;i < tot;++i)
		cout<<re[i]<<endl;
	return 0;
} 

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

int main() {
	char b;
  	cin>>b;
  
  if(b=='A'){
  	cout<<"T"<<endl;
  }
  if(b=='T'){
  	cout<<"A"<<endl;
  }  

  if(b=='G'){
  	cout<<"C"<<endl;
  }  

  if(b=='C'){
  	cout<<"G"<<endl;
  }    
  
  
  
  
}

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

int main() {
  string C;
  cin >> C;
  
  string answer;
  
  for (int i = 0; i < C.size(); i++) {
    
    if (C.at(i) == 'a') {
      answer = "vowel";
      break;
    }
    else if (C.at(i) == 'e') {
      answer = "vowel";
      break;
    }
    else if (C.at(i) == 'i') {
      answer = "vowel";
      break;
    }
    else if (C.at(i) == 'o') {
      answer = "vowel";
      break;
    }
    else if (C.at(i) == 'u') {
      answer = "vowel";
      break;
    }
    else {
      answer = "consonant";
    }
    i++;
  }
  
  cout << answer << endl;
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int n;
int a[N][5];
int dp[N][5];

int solve(int i,int cur)
{
	if(i>n)
		return 0;
	if(dp[i][cur]!=-1)
		return dp[i][cur];
	if(cur==0)
	{
		dp[i][cur] =  max({a[i][1] + solve(i+1,1) , a[i][2] + solve(i+1,2) , a[i][3] + solve(i+1,3)});
		return dp[i][cur];
	}
	else if(cur==1)
	{
		dp[i][cur] = max(a[i][2] + solve(i+1,2),a[i][3] + solve(i+1,3));
		return dp[i][cur];
	}
	else if(cur==2)
	{
		dp[i][cur] =  max(a[i][1] + solve(i+1,1),a[i][3] + solve(i+1,3));
		return dp[i][cur];
	}
	else
	{
		dp[i][cur] =  max(a[i][1] + solve(i+1,1),a[i][2] + solve(i+1,2));
		return dp[i][cur];
	}
}
int32_t main()
{
	IOS;
	memset(dp,-1,sizeof(dp));
	cin >> n;
	rep(i,1,n)
	{
		cin >> a[i][1] >> a[i][2] >> a[i][3];
	}
	cout << solve(1,0) << endl;
}


Measured memory_bytes: 12800
object Main {
  def main(args:Array[String]) {
    val read = readLine()
    var A = read.split(' ')(0).toLong
    var B = read.split(' ')(1).toLong
    val K = read.split(' ')(2).toLong

    var a = 0l
    var b = 0l
    a = A - K
    if(0 < a) println(a + " " + B)
    else {
      b = B - math.abs(a)
      if(0 < b) println("0 " + b)
      else println("0 0")
    }
  }
}



Measured memory_bytes: 25420
n,m=map(int,input().split())
H=list(map(int,input().split()))
G=[[] for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(H[b])
    G[b].append(H[a])

ans=0
for i in range(n):
    if G[i]:
        if max(G[i])<H[i]:
            ans+=1
    else:
        ans+=1
print(ans)

Measured memory_bytes: 23048
#include <bits/stdc++.h>
#define rep(i,x) for(int i=0; i<(int) (x); i++)
#define PI 3.14159265359
using namespace std;

int main()
{
	int n,m;
	cin >> n >> m;
	int a, total=0;
	rep(i, m)
	{
		cin>>a;
		total += a;
	}
	if(n<total)
		cout << "-1" << endl;
	else
		cout << n - total << endl;
	return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }

using ll = long long;
const ll mod = LLONG_MAX;

int N;
int t[110],v[110];
int maxV[40010];
//x,y方向に二倍
double dp[240][40040];
int endTime=0;
int tempEndTime=0;
double ans;
int main(){
  cin>>N;

  rep(i,40010)rep(j,240)dp[j][i]=-1;
  rep(i,N){
    cin>>t[i];
    t[i]*=2;
    endTime+=t[i];
  }
  rep(i,N){
    cin>>v[i];
    v[i]*=2;
  }
  for(int i=0;i<40010;i++){
    int temp=0;
    for(int j=0;j<N;j++){
      temp+=t[j];
      if(temp>=i){
        maxV[i]=v[j];
        break;
      }
    }
  }


  // //speedが増える時
  // (speed+(speed+1))*1/2
  // //speedが減る時
  // (speed+(speed-1)*1)/2
  // //speedが変わらないとき
  // (speed+speed)*1/2;
  dp[0][0]=0;
  for(int Time = 1; Time <=endTime;Time++){
    for(int speed=0;speed <=220;speed++){
      if(dp[speed][Time-1]<0)continue;
      if(speed > maxV[Time])continue;
      if(speed < maxV[Time] && speed!=0 ){
        //等速か減速か加速
        dp[speed+1][Time]=max(dp[speed+1][Time],dp[speed][Time-1]+(double)(speed+(speed+1))/2.0);
        dp[speed][Time]=max(dp[speed][Time],dp[speed][Time-1]+(double)(speed+(speed))/2.0);
        dp[speed-1][Time]=max(dp[speed-1][Time],dp[speed][Time-1]+(double)(speed+(speed-1))/2.0);
      }
      else if(speed< maxV[Time]){
        //等速か加速
        dp[speed+1][Time]=max(dp[speed+1][Time],dp[speed][Time-1]+(double)(speed+(speed+1))/2.0);
        dp[speed][Time]=max(dp[speed][Time],dp[speed][Time-1]+(double)(speed+(speed))/2.0);
      }
      else {
        //等速か減速
        dp[speed][Time]=max(dp[speed][Time],dp[speed][Time-1]+(double)(speed+(speed))/2.0);
        dp[speed-1][Time]=max(dp[speed-1][Time],dp[speed][Time-1]+(double)(speed+(speed-1))/2.0);
      }

    }
  }


  cout<<fixed<<setprecision(20)<<dp[0][endTime]/4.0<<endl;
}


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

int main(void) {
    int n, m, x, ans = 114514;
    bool toll[114] = {};
    cin >> n >> m >> x;
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        toll[a] = true;
    }
    
    int temp = 0;
    for (int i = x; i >= 0; i--) {
        if (toll[i])
            temp++;
    }
    ans = min(ans, temp);
    
    temp = 0;
    for (int i = x; i <= n; i++) {
        if (toll[i])
            temp++;
    }
    ans = min(ans, temp);
    
    cout << ans << endl;
}


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

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for(int i = m; i < (int)(n); ++i)

int main()
{
    double c[25];
    c[1] = 1.0;
    rep2(i, 2, 25) c[i] = c[i-1] / (1<<(i-1));
    
    double memo[100010], ans[100010];
    memo[0] = 1.0; ans[0] = 0.0;
    rep2(i, 1, 100001)
    {
        memo[i] = 0.0;
        for(int j = min(i, 20); j > 0; --j)
            memo[i] += memo[i-j] * c[j];
        ans[i] = ans[i-1] + memo[i];
        memo[i] = 1.0 - memo[i];
    }
    
    int n;
    cout << fixed << setprecision(3);
    while(cin >> n, n)
        cout << ans[n] << endl;
}

Measured memory_bytes: 2796
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
const long long mod = 1e9 + 7;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> p;
    rep(i, n)
    {
        int a, b;
        cin >> a >> b;
        p.emplace_back(a, b);
    }
    sort(p.begin(), p.end());
    priority_queue<int> value;
    int day = 0;
    int index = 0;
    int ans = 0;
    while (day <= m)
    {
        while (index < n && p[index].first <= day)
        {
            value.push(p[index].second);
            index++;
        }
        if (!value.empty())
        {
            ans += value.top();
            value.pop();
        }
        day++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1908
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, D;
	cin >> N >> D;
	int ans = 0;
	int X[11][11];
	REP(i, N) {
		REP(j, D) {
			cin >> X[i][j];
		}
	}
	int A[1001];
	eREP(i, 1000) {
		A[i] = i * i;
	}
	REP(i, N - 1) {
		FOR(j, i + 1, N) {
			int cnt = 0;
			REP(k, D) {
				cnt += abs(X[i][k] - X[j][k])*abs(X[i][k] - X[j][k]);
			}
			eREP(i, 1000) {
				if (A[i] == cnt)ans++;
			}
		}
	}
	//cout << A[100] << endl;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<assert.h>
#include<stdbool.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
bool X[N][N];

void initialize(){
  int i;
  for(i=0;i<N;i++){
    row[i]=FREE;
    col[i]=FREE;
  }
  for(i=0;i<2*N-1;i++){
    dpos[i]=FREE;
    dneg[i]=FREE;
  }
}

void printBoard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]){
	if(row[i] !=j) return;
      }
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;
  if(i==N){
    printBoard();
    return;
  }
  for(j=0;j<N;j++){
    if(NOT_FREE == col[j] ||
       NOT_FREE == dpos[i+j] ||
       NOT_FREE == dneg[i-j+N-1]) continue;
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
    recursive(i+1);
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
  }
}

int main(){
  initialize();

  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      X[i][j]=false;
    }
  }

  int k,r,c;
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    X[r][c]=true;
  }

  recursive(0);
  return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include <climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N, i;
	cin >> N >> i;
	cout << N - i + 1;

	return 0;
}

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

int n,a[4],l[10],m=1e9;

int f(int x){
    int y=x,v[4],w[4],z=0;
    fill(v, v+4, 0);
    fill(w, w+4, -1);
    for(int i=0;i<n;i++){
        v[y%4]+=l[i];
        w[y%4]++;
        y/=4;
    }
    for(int i=1;i<4;i++){
        if(w[i]==-1)return 1e9;
        z+=abs(v[i]-a[i])+w[i]*10;
    }
    return z;
}

int main(void){
    cin>>n>>a[1]>>a[2]>>a[3];
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    for(int i=0;i<(1<<(n*2));i++){
        m=min(m, f(i));
    }
    cout<<m<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void) {
	char S[1000];
	int w=0, s=0, e=0, n=0;
	scanf("%s", &S);
	for (unsigned int i = 0; i < strlen(S); i++) {
		if (S[i] == 'W')w++;
		if (S[i] == 'S')s++;
		if (S[i] == 'N')n++;
		if (S[i] == 'E')e++;
	}
	if ((w!=0&&e==0) || (w == 0 && e!= 0) || (n== 0 && s != 0)|| (n != 0 && s == 0)) {
		printf("No");
	}
	else {
		printf("Yes");
	}
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  string s,t;
  cin>>s >>t;

  ll a,b;
  cin>>a>>b;
  string u;
  cin>>u;

  if(s==u)
    a--;
  else
    b--;
  cout<< a<<" " << b<<endl;
}


Measured memory_bytes: 256
class UnionFind:

    def __init__(self, n):
        self.t = [-1] * (n + 1)

    def flatten(self):
        for i, _ in enumerate(self.t):
            self.find_root(i)

    def union(self, a, b):
        ra = self.find_root(a)
        rb = self.find_root(b)
        if ra != rb:
            self.t[max(ra, rb)] = min(ra, rb)

    def find_root(self, x):
        t = []
        while self.t[x] > 0:
            t.append(x)
            x = self.t[x]
        for _t in t:
            self.t[_t] = x
        return x


def solve(string):
    n, m, k, *abcd = map(int, string.split())
    ab, cd = abcd[:2 * m], abcd[2 * m:]
    r = [0] * (n + 1)
    uf = UnionFind(n)
    for a, b in zip(*[iter(ab)] * 2):
        r[a] += 1
        r[b] += 1
        uf.union(a, b)
    uf.flatten()
    for i, v in enumerate(uf.t):
        if v < 0:
            uf.t[i] = i
    mp = {k: [] for k in set(uf.t[1:])}
    for i, v in enumerate(uf.t[1:], start=1):
        mp[v].append(i)
    mp = {k: set(v) for k, v in mp.items()}
    for c, d in zip(*[iter(cd)] * 2):
        r[c] += 1 if d in mp[uf.t[c]] else 0
        r[d] += 1 if c in mp[uf.t[d]] else 0
    mp = {k: len(v) for k, v in mp.items()}
    return " ".join([str(mp[uf.t[i]] - 1 - r[i]) for i in range(1, n + 1)])


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 83944
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

//TODO name
template <class V = ll, V defval = (V)1e16>
struct SegTreeT{
    SegTreeT *l, *r;
    int left, right;
    V value = defval;
    SegTreeT(int size):SegTreeT(0, size - 1){ }
    SegTreeT(int st, int lt): left(st), right(lt){
        if(left == right){
            l = r = nullptr;
        }else{
            int piv = (right - left) / 2 + left;
            l = new SegTreeT(left, piv);
            r = new SegTreeT(piv + 1, right);
        }
    }
    void set(int lv, int rv, V val){
        if(right < lv || rv < left){ return; }
        if(lv <= left && right <= rv){
            value = min(value, val);
        }else if(l){
            l->set(lv, rv, val);
            r->set(lv, rv, val);
        }
    }
    V getVal(int idx){
        if(right < idx || idx < left){ return defval; }
        ll ret = value;
        if(l){
            //TODO
            ret = min(ret, l->getVal(idx));
            ret = min(ret, r->getVal(idx));
        }
        return ret;
    }
};
using SegTree = SegTreeT<ll>;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> ls(m), rs(m), cs(m);
    for(int i = 0; i < m; i++){
        cin >> ls[i] >> rs[i] >> cs[i];
        ls[i]--;
        rs[i]--;
    }
    vector<int> is(m);
    iota(is.begin(), is.end(), 0);
    sort(is.begin(), is.end(), [&](int i, int j){ return ls[i] < ls[j]; });
    SegTree st(n);
    st.set(0, 0, 0);
    for(auto i : is){
        st.set(ls[i], rs[i], cs[i] + st.getVal(ls[i]));
    }
    ll ans = st.getVal(n - 1);
    cout << (ans == 1e16 ? -1 : ans) << '\n';
}


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

typedef long long int ll;



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

	ll i,j,t,k,l,m,n,x,y,z,a,b,c;

	cin >> n;

	if(n >= 30)
		cout << "Yes\n";
	else
		cout << "No\n";
	
	

}

Measured memory_bytes: 3648
from numpy import*;B=searchsorted;a,b=split(int32(open(0).read().split()[1:]),2);c=0;h=l=2**29
while l:l//=2;y=sort(hstack((b%h-h,b%h)));c+=sum(B(y,h-a%h)-B(y,l-a%h))%2*l;h=l
print(c)

Measured memory_bytes: 59256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n;
		int c;
		boolean[] prime = new boolean[1000000];
		for (int i = 0; i < prime.length; i++) {
			prime[i] = true;
		}
		for (int i = 2; i < Math.sqrt(prime.length); i++) {
			for (int j = 2; j < prime.length; j++) {
				if (prime[j]) {
					if (j / i != 1 && j % i == 0) {
						prime[j] = false;
					}
				}
			}
		}
		while (scan.hasNext()) {
			n = scan.nextInt();
			c = 0;

			for (int i = 2; i <= n; i++) {
				if (prime[i]) {
					c++;
				}
			}
			System.out.println(c);
		}
	}

}

Measured memory_bytes: 22484
import java.util.Arrays;

class Main {
    public static void main(String args[]) {
        java.util.Scanner sc = new java.util.Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[][] adjacency = new int[n][n];

        for(int i=0; i<n; i++){
            int vIndex = Integer.parseInt(sc.next())-1;
            int nAdj = Integer.parseInt(sc.next());
            for(int j=0; j<nAdj; j++){
                int connectTo = Integer.parseInt(sc.next())-1;
                adjacency[vIndex][connectTo] = 1;
            }
        }

        DFS dfs = new DFS(adjacency);
        for(int i=0; i<dfs.getNp(); i++){
            dfs.execute(i);
        }
        
        dfs.printAnswer(); 
    }


    static class DFS{
        private final  int[][] adjacency;
        private final int[][] ans;
        private final Status[] status;
        private int time = 1;
        private final int np;

        public int getNp(){
            return this.np;
        }

        public DFS(int[][] adjacency){
            this.adjacency = adjacency;
            this.np = adjacency.length;
            this.ans = new int[adjacency.length][3];
            for(int i=0; i<np; i++){
                this.ans[i][0] = i+1;
            }
            Status[] status = new Status[np];
            Arrays.fill(status, Status.NOT_YET);
            this.status = status;
        }

        private void searchNotYet(int vi){
            for(int i=0; i<np; i++){
                if( adjacency[vi][i] == 1 && i != vi && this.status[i] == Status.NOT_YET){
                    int iNotYet = i;
                    execute(iNotYet);
                }
            }
        }

        public void execute(int vi){
            if(this.status[vi] != Status.NOT_YET) return;
            ans[vi][1] = time++;
            status[vi] = Status.CURRENT;
            searchNotYet(vi);
            ans[vi][2] = time++;
        }
        public void printAnswer(){
            for(int i=0; i<np; i++){
                for(int j=0; j<3; j++) {
                    if(j== 2)   System.out.println(ans[i][j]);
                    else System.out.print(ans[i][j]+" ");
                }
            }
        }
    }

    static enum Status{
        DONE,
        CURRENT,
        NOT_YET
    }
}



Measured memory_bytes: 28260
N = int(input())
S = [input() for i in range(N)]
# M A R C H
num = [0] * 5
for s in S:
    if s[0] == "M":
        num[0] += 1
    elif s[0] == "A":
        num[1] += 1
    elif s[0] == "R":
        num[2] += 1
    elif s[0] == "C":
        num[3] += 1
    elif s[0] == "H":
        num[4] += 1
non_zero = []
for n in num:
    if n != 0:
        non_zero.append(n)
if len(non_zero) < 3:
    print(0)
    exit()
ans = 0
for i in range(len(non_zero)):
    for j in range(i + 1, len(non_zero)):
        for k in range(j+1, len(non_zero)):
            ans += non_zero[i] * non_zero[j] * non_zero[k]
print(ans)


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

#include<algorithm>
#include<iostream>
#include<vector>

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

int main(){
  int n;
  cin >> n;

  vector<int> p(n);
  vector<int> q(n);
  rep(i, n) cin >> p.at(i);
  rep(i, n) cin >> q.at(i);

  vector<int> nums(n);
  for(int i=0; i<n; i++){
    nums.at(i) = i+1;
    //cout << nums.at(i);
  }

  int a=0;
  int b=0;
  int j=0;
  
    do{
    if(nums==p) a=j;
    if(nums==q) b=j;
    //rep(i, n) cout << nums.at(i);
    //cout << endl;
    j++;
  }while(next_permutation(nums.begin(), nums.end()));

  cout << abs(a-b);
  

  
}

Measured memory_bytes: 256
n, k, q = gets.strip.split.map(&:to_i)
aa = readlines.map {|line| line.strip.to_i }

base = k-q

points = aa.group_by(&:itself)

#p aa
#p points

n.times do |i|
  point = points[i+1]&.length || 0
  if point+base > 0
    puts 'Yes'
  else
    puts 'No'
  end
end


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

int main() {
    string S;
    cin >> S;
    string T;
    cin >> T;
    int count = 0;
    for(int i = 0;i < 3;i++) {
        if(S.at(i) == T.at(i)) {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
//g++ -Wshadow -Wall -O2 -Wno-unused-result -Wno-psabi
#include "bits/stdc++.h"
#define f first
#define s second
#define inf 1e18
#define ll long long
#define mod 1000000007
#define pb emplace_back
#define vll vector<long long int>
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) ((long long int)(x).size())
#define mll map<long long int, long long int>
#define pll pair<long long int, long long int>
using namespace std;

ll n;

void input(){
	cin >> n;
}

void solve(){
	ll x = 0;
	bool f = false;
	for(ll i = 0; i < n; i++){
		ll u, v;
		cin >> u >> v;
		if(u == v)x++;
		else x = 0;
		if(x >= 3) f = true;
	}
	if(f)cout << "Yes";
	else cout << "No";
	
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(20);
	ll t = 1;
	//cin >> t;
	while(t--){
		input();
		solve();
        cout<<endl;
	}
	cin.get();
	return 0;
}

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

int main(){
	// sengen
	map<string,int> mp;
	// nyuryoku
	string s,t,u;
	int a,b;
	cin >> s >> t >> a >> b >> u;
	mp[s] = a;
	mp[t] = b;
	mp[u]--;
	// keisan
	cout << mp[s] << ' ' << mp[t];
	// syutsuryoku
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
      int N = sc.nextInt(); // 合計値
      int S = sc.nextInt();

      StringBuilder val = new StringBuilder();
      for(int count = 0; count < S; count++) {
          String cntval = Integer.toString(N);
          val.append(cntval);
      }
      String NN = new String(val);
      StringBuilder val2 = new StringBuilder();
      for(int count = 0; count < N; count++) {
          String cntval = Integer.toString(S);
          val2.append(cntval);
      }
      String SS = new String(val2);
      
      if(NN.compareTo(SS) > 0){
      	System.out.println(SS);
      } else {
      	System.out.println(NN);
      }
   }
}


Measured memory_bytes: 23892
#include<iostream>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        int flag=0;
          for(int i=1;i<=10;i++)
        {
            for(int j=1;j<=10;j++)
            if(n%(4*i+7*j)==0)
            {
                flag=1;
                break;
            }
        }
        if((n%4==0||n%7==0||flag==1)&&n>=4)
            cout<<"Yes"<<endl;
            else
                cout<<"No"<<endl;

    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const long long LINF = 1000000000000000018ll;
const int INF = 1000000009;
const int mod = 1000000007;
const int mod2 = 998244353;

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

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::setprecision(20) << std::fixed;

  int N;
  cin >> N;

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    ans += (((i + 1) & 1) && (A & 1));
  }
  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    string s;
    cin >> s;
    vector<int> ans;
    int t = n;
    while(t != 0){
        int i = m;
        for(i=min(t,m);i>=0;i--){
            if(s[t-i] == '0'){
                ans.push_back(i);
                t -= i;
                break;
            }
        }
        if(i == 0) {
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i=ans.size()-1;i>=0;i--){
        cout <<  ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1144
/* B - Making Triangle */

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

int main(){
  int N, cnt = 0;
  cin >> N;
  vector<int> L(N);
  for(int i = 0; i < N; i++){
    cin >> L.at(i);
  }
  for(int i = 0; i < N; i++){
    for(int j = i; j < N; j++){
      if(L.at(i) == L.at(j)) continue;
      for(int k = j; k < N; k++){
        if(L.at(i) == L.at(k) || L.at(j) == L.at(k)) continue;
        int l1, l2, l3;
        if(L.at(j) < L.at(k)){
          if(L.at(i) < L.at(j)){
            l1 = L.at(i);
            l2 = L.at(j);
            l3 = L.at(k);
          }else if(L.at(k) < L.at(i)){
            l1 = L.at(j);
            l2 = L.at(k);
            l3 = L.at(i);
          }else{
            l1 = L.at(j);
            l2 = L.at(i);
            l3 = L.at(k);
          }
        }else{ // k < j
          if(L.at(i) < L.at(k)){
            l1 = L.at(i);
            l2 = L.at(k);
            l3 = L.at(j);
          }else if(L.at(j) < L.at(i)){
            l1 = L.at(k);
            l2 = L.at(j);
            l3 = L.at(i);
          }else{
            l1 = L.at(k);
            l2 = L.at(i);
            l3 = L.at(j);
          }
        }
        if(l1 + l2 > l3) cnt++;
      }
    }
  }
  cout << cnt << endl;
}


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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

long long mod = 1000000007;

long long powmod(long long value, long long n)
{
    long long ans = 1;

    for (long long i = 0; i < n; i++)
    {
        ans = ans * value % mod;
    }

    return ans;
}

int main()
{
    // int x;
    // cin >> x;

    // cout << !x << endl;

    // long long a, b, c, d;
    // long long max;

    // cin >> a >> b >> c >> d;

    // max = a * c;

    // if (a * d > max)
    // {
    //     max = a * d;
    // }
    // if (b * c > max)
    // {
    //     max = b * c;
    // }
    // if (b * d > max)
    // {
    //     max = b * d;
    // }

    // cout << max << endl;

    long long n;
    cin >> n;

    long long ans = powmod(10, n) - powmod(9, n) - powmod(9, n) + powmod(8, n);
    ans %= mod;

    ans = (ans + mod) % mod;

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

Measured memory_bytes: 3592
/*
[abc120] D - Decayed Bridges
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;
const int MAX_M = 1e5;

class UnionFind {
public:
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return false;
        }
        if (data[y] < data[x]) {
            swap(x, y);
        }
        data[x] += data[y];
        data[y] = x;

        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : (data[x] = root(data[x])); }
    int size(int x) { return -data[root(x)]; }
};

int N, M;
int A[MAX_M], B[MAX_M];

void solve() {
    UnionFind uf(N);
    ll ans[MAX_M + 1];
    ans[M] = (N - 1LL) * N;
    for (int i = M - 1; i >= 0; i--) {
        if (uf.same(A[i], B[i])) {
            ans[i] = ans[i + 1];
            continue;
        }
        ll as = uf.size(A[i]), bs = uf.size(B[i]);
        ans[i] = ans[i + 1] + (as - 1) * as + (bs - 1) * bs;
        uf.unite(A[i], B[i]);
        ll ss = uf.size(A[i]);
        ans[i] -= (ss - 1) * ss;
    }

    for (int i = 0; i < M; i++) {
        cout << ans[i + 1] / 2 << endl;
    }
}

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

    solve();

    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef tuple<ll, ll, ll> P;

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

int main(){
	ll a, b, c, x, y, z, area, k;
	int n;
	P t;
	set<P> s;
	cin >> a >> b >> c >> n;
	area = 2 * (a * b + b * c + a * c);
	for(int i = 0;i < n;++i){
		cin >> x >> y >> z;
		k = 0;
		k += (x == 0) + (x == a - 1);
		k += (y == 0) + (y == b - 1);
		k += (z == 0) + (z == c - 1);
		for(int i = 0;i < 6;++i){
			t = make_tuple(x + dx[i], y + dy[i], z + dz[i]);
			if(s.find(t) != s.end()) ++k;
		}
		area += -k + (6 - k);
		s.insert(make_tuple(x, y, z));
	}
	cout << area << endl;
	return 0;
}



Measured memory_bytes: 3188
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1010;
const int INF = 0x3f3f3f3f;
int main()
{
    int n;
    cin>>n;
    int nx=0,ny=0,nt=0,flag=0;
    while(n--){
        int t,x,y;
        cin>>t>>x>>y;
        int need = abs(nx-x)+abs(ny-y);
//        cout<<need<<endl;
        if(need <= (t-nt) && ((t-nt)-need)%2==0){
            nt=t;
            nx=x;
            ny=y;
        }
        else{
            flag = 1;
        }
    }
    if(!flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
while True:
    m, d = map(int, input().split())
    if m == d == 0:
        break
    dim = {1: 0, 2: 31, 3: 60, 4: 91, 5: 121, 6: 152, 7: 182, 8: 213, 9: 244, 10: 274, 11: 305, 12: 335}
    ds = dim[m] + d -1
    print({0:'Thursday', 1:'Friday', 2:'Saturday', 3:'Sunday', 4:'Monday', 5:'Tuesday', 6:'Wednesday'}[ds % 7])

Measured memory_bytes: 7544
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

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

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int k[10], s[10][10], p[10];

    rep(i, m) {
        cin >> k[i];

        rep(j, k[i]) {
            cin >> s[i][j];
            s[i][j]--;
        }
    }

    rep(i, m) cin >> p[i];
    int cnt = 0;

    rep(bi, 1 << n) {
        bool can = true;
        bitset<20> bs(bi);

        rep(i, m) {
            int xor_sum = 0;

            rep(j, k[i]) {
                xor_sum ^= bs[s[i][j]];
            }
            if (xor_sum != p[i]) can = false;
        }
        if (can) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import heapq

x,y,z,k=(int(i) for i in input().split())
#print(x,y,z,k)

a=list(int(i) for i in input().split())
a.sort(reverse=True)
b=list(int(i) for i in input().split())
b.sort(reverse=True)
c=list(int(i) for i in input().split())
c.sort(reverse=True)
#print(a,b,c)

q=[]
for h in range(x):
  for i in range(y):
    if (h+1)*(i+1) <= k:
      for j in range(z):
        if (h+1)*(i+1)*(j+1) <= k:      
          heapq.heappush(q,-(a[h]+b[i]+c[j]))
          
for i in range(k):
    val=heapq.heappop(q)
    print((-1)*val)

Measured memory_bytes: 60892
#include <stdio.h>
#include <math.h>
int main(){
  
  int n,s[1000],i;
  double ave,result,Save[1000];
  
  while(1){
    
    scanf("%d",&n);
    
    if(n != 0){

      ave=result=0;
      
      for(i = 0; i < n; i++){
	
	scanf("%d",&s[i]);
	
	ave += s[i];
	
      }
      
      ave=ave/n;
      
      for(i = 0; i < n; i++){
	
	Save[i]=s[i]-ave;
	
	result += Save[i]*Save[i];
	  
	  }
      
      result=result/n;
      
      result=sqrt(result);
      
      printf("%.5lf\n",result);
      
    } else {
      
      break;
      
    }
    
  }
  
  return 0;

}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(N * A, B) << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))

H = [[-1, 10**9] for i in range(N)]

prev = 0
for i, x in enumerate(T):
    if prev != x:
        if H[i][0] < 0:
            H[i][0] = x
        elif H[i][0] != x:
            print(0)
            exit(0)
    prev = x
    H[i][1] = min(H[i][1], x)
prev = 0
for i in range(N-1, -1, -1):
    x = A[i]
    if prev != x:
        if H[i][0] < 0:
            if H[i][1] >= x:
                H[i][0] = x
            else:
                print(0)
                exit(0)
        elif H[i][0] != x:
            print(0)
            exit(0)
    prev = x
    H[i][1] = min(H[i][1], x)
ans = 1
mod = 10**9 + 7
for x, y in H:
    if x > 0:
        continue
    else:
        ans *= y
        ans %= mod
print(ans)


Measured memory_bytes: 21744
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

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

  string ans = "";
  for(int c : S) {
    int rot = (c - 'A' + N) % 26;
    ans.push_back(rot + 'A');
  }

  cout << ans << endl;
}


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

// --------------------------------------------------------------------------------
#define FASTIO	ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long 
#define mset(arr,val) memset(arr,val,sizeof(arr))
#define fset(arr,n,val) for(int i=0;i<n;++i) arr[i] = val
#define deb(name,value) cout <<"->>  "<<name<< "= " <<value<<" "
#define frepi(a,b,k) for(int i=a;i<=b;i+=k)
#define frepj(a,b,k) for(int j=a;j<=b;j+=k)
// --------------------------------------------------------------------------------

void solve_main()
{
    int n;cin>>n;
    int ans = 1;
   	int x;cin>>x;
   	int min = x;
   	frepi(2,n,1)
   	{
   		cin>>x;
   		if(x<=min)
   		{
   			ans++;
   			min = x;
   		}
   	}
   	cout<<ans;
}

int main()
{

	#ifndef ONLINE_JUDGE
		freopen("/home/suryakant/input.txt","r",stdin);
		freopen("/home/suryakant/output.txt","w",stdout);
	#endif

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

Measured memory_bytes: 3560
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 10000000 + 5
#define Mod 998244353

int n, ans, Fac[N], Inv[N], Pow3[N], Pow2[N];

void Prepare()
{
	Fac[0] = Inv[0] = Inv[1] = Pow3[0] = Pow2[0] = 1;
	for (int i = 1; i <= n; i ++)
	{
		Fac[i] = 1LL * Fac[i - 1] * i % Mod;
		Pow3[i] = 3LL * Pow3[i - 1] % Mod;
		Pow2[i] = 2LL * Pow2[i - 1] % Mod;
	}
	for (int i = 2; i <= n; i ++)
		Inv[i] = Mod - (1LL * Inv[Mod % i] * (Mod / i) % Mod);
	for (int i = 2; i <= n; i ++)
		Inv[i] = 1LL * Inv[i - 1] * Inv[i] % Mod;
}

inline int C(int u, int v)
{
	if (u < 0 || v < 0 || u < v)
		return 0;
	return 1LL * Fac[u] * Inv[v] % Mod * Inv[u - v] % Mod;
}

inline int Inc(int u, int v)
{
	return u + v - (u + v >= Mod ? Mod : 0);
}

int Calc()
{
	int res = 0;
	for (int t = n / 2 + 1; t <= n; t ++)
		res = (2LL * C(n, t) * Pow2[n - t] + res) % Mod;
	return res;
}

int main()
{
	scanf("%d", &n);
	Prepare();
	ans = Inc(Pow3[n], Mod - Calc());
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 156416
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();

        // 候補の配列
        List<Integer> candidate = new ArrayList<>();
        candidate.add(a);
        candidate.add(b);
        candidate.add(c);
        candidate.add(d);
        candidate.add(e);

        // 順列の配列
        List<Integer> perm = new ArrayList<>();
        List<List<Integer>> ret = new ArrayList<>();
        make(candidate, perm, ret);

        int ans = Integer.MAX_VALUE;
        for (List<Integer> pattern : ret) {
            int total = 0;
            for (int i = 0; i < pattern.size(); i++) {
                total += pattern.get(i);
                if (total % 10 != 0 && i != pattern.size() - 1) {
                    total += 10 - (total % 10);
                }
            }
            ans = Math.min(ans, total);
        }
        System.out.println(ans);
    }


    private static void make(List<Integer> candidate, List<Integer> perm, List<List<Integer>> ret) {
        if (candidate.size() == 0) {
            ret.add(perm);
        }

        for (int i = 0; i < candidate.size(); i++) {
            List<Integer> p = new ArrayList<>(perm);
            List<Integer> c = new ArrayList<>(candidate);
            p.add(c.get(i));
            c.remove(i);
            make(c, p, ret);
        }
    }
}

Measured memory_bytes: 23764
h,w = map(int,input().split())
s =[[i for i in input()] for j in range(h)]
for i in range(h):
	for j in range(w):
		if s[i][j]=='#':
			flag = 0
			for di in range(-1,2):
				for dj in range(-1,2):
					if di!=0 and (dj==-1 or dj==1):
						# print(1)
						continue
					if di==0 and dj ==0:
						continue
					if not (0<=i+di<h and 0<=j+dj<w):
						# print(2)
						continue
					if s[i+di][j+dj]=='#':
						flag = 1
			if flag ==0:
				print('No')
				break		
	else:
		continue
	break

else:
	print('Yes')
					

 

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

template <typename T>
struct segtree_lazy {
	int n;
	vector<T> tree, lazy;
	T def = numeric_limits<T>::max(), none = -1;
	
	segtree_lazy(int n_) {
		for (n = 1; n < n_; n *= 2) {
			
		}
		tree.assign(2 * n, def);
		lazy.assign(2 * n, none);
	}
	
	T merge(T a, T b) {
		return max(a, b);
	}
	
	void set_lazy(int index, T x) {
		tree[index] = x;
		lazy[index] = x;
	}
	
	void push(int index) {
		if (lazy[index] == none) {
			return;
		}
		set_lazy(2 * index, tree[index]);
		set_lazy(2 * index + 1, tree[index]);
		lazy[index] = none;
	}
	
	void fix(int index) {
		tree[index] = merge(tree[2 * index], tree[2 * index + 1]);
	}
	
	void update(int a, int b, int index, int l, int r, T x) {
		if (r <= a || b <= l) {
			return;
		}
		if (a <= l && r <= b) {
			set_lazy(index, x);
			return;
		}
		push(index);
		update(a, b, 2 * index, l, (l + r) / 2, x);
		update(a, b, 2 * index + 1, (l + r) / 2, r, x);
		fix(index);
	}
	
	void update(int l, int r, T x) {
		update(l, r, 1, 0, n, x);
	}
	
	T query(int a, int b, int index, int l, int r) {
		if (r <= a || b <= l) {
			return none;
		}
		if (a <= l && r <= b) {
			return tree[index];
		}
		push(index);
		T puni = query(a, b, 2 * index, l, (l + r) / 2);
		T muni = query(a, b, 2 * index + 1, (l + r) / 2, r);
		return merge(puni, muni);
	}
	
	T query(int l, int r) {
		return query(l, r, 1, 0, n);
	}
};

int main() {
	int n, q;
	cin >> n >> q;
	segtree_lazy<int> seg(n);
	for (int i = 0; i < q; i++) {
		bool b;
		cin >> b;
		if (b) {
			int x;
			cin >> x;
			cout << seg.query(x, x + 1) << endl;
		} else {
			int s, t, x;
			cin >> s >> t >> x;
			seg.update(s, t + 1, x);
		}
	}
	return 0;
}

Measured memory_bytes: 4908
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int f=1,x=0;
    char ch;
    do{
        ch=getchar();
        if(ch=='-'){
            f=-1;
        }
    }while(ch<'0'||ch>'9');
    do{
        x=x*10+ch-48;
        ch=getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}
int main(){
    int n=read(),a=read();
    int temp=n/500;
    n=n-500*temp;
    if(n<=a){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

using namespace std;
typedef pair<int, int> P;

void solve()
{
	vector<P> Vec;
	set<int, greater<int> > Set;
	P p;
	while(~scanf("%d,%d", &p.first, &p.second))
	{
		if(!p.first && !p.second)
		{
			break;
		}
		Vec.push_back(p);
		Set.insert(p.second);
	}
	int n;
	while(cin >> n)
	{
		int count = 0;
		for(set<int, greater<int> >::iterator Ite = Set.begin(); Ite != Set.end(); ++Ite)
		{
			++count;
			if(*Ite == Vec[n - 1].second)
			{
				break;
			}
		}
		cout << count << endl;
	}
}

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

Measured memory_bytes: 0