akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
static const int N = 100;

int main() {
  int M[N][N];
  int n, u, k, v;

  cin >> n;

  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) M[i][j] = 0;
  }

  for ( int i = 0; i < n; i++ ) {
    cin >> u >> k;
    u--;
    for ( int j = 0; j < k; j++ ) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) {
      if ( j ) cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3132
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, x, ans = 0;
  scanf("%lld%lld", &n, &x);
  ll a[n], now[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]), now[i] = a[i], ans += a[i];
  for(i = 1; i < n; ++i) {
    ll sum = i * x;
    for(j = 0; j < n; ++j) {
      if(now[j] > a[(j + n - i) % n]) now[j] = a[(j + n - i) % n];
      sum += now[j];
    }
    if(sum < ans) ans = sum;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int a[5],k;
  cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>k;
  sort(a,a+5);
  if(k>=a[4]-a[0]) cout<<"Yay!";
  else cout<<":(";
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    rep(i, N) {
        if (S[i] != S[N - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    int N2 = (N - 1) / 2;
    rep(i, N2) {
        if (S[i] != S[N2 - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    for (int i = (N + 3) / 2 + 1; i < N; i++) {
        if (S[i] != S[N - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int A, B, C, D, x, y;
	cin >> A >> B >> C >> D;
	if (A < B) {
		x = A;
	}
	if (B < A) {
		x = B;
	}
	if (C < D) {
		y = C;
	}
	if (D < C) {
		y = D;
	}
	cout << x + y << endl;
	return 0;
}

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

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

  if (A < 10 && B < 10) {
    cout << A * B << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
ok = [1] * n
for i in range(m):
    x = int(input())
    ok[x-1] = 0
mod = 1000000007
dp = [0] * (n+2)
dp[1] = 1
for i in range(n):
    dp[i+2] = (dp[i+1] + dp[i])%mod if ok[i] else 0

print(dp[n+1])

Measured memory_bytes: 76128
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#define MOD 1000000007LL

using namespace std;
typedef long long int ll;
typedef pair<ll, int> Pl;
typedef pair<int, int> P;
typedef pair<ll, P> Pll;
typedef pair<P, P> PP;

int par[100002];
int rk[100002];
int size[100002];
vector<PP> g[100002];
vector<Pll> cab;
 
void init(int n){
	for(int i=0; i<n; i++){
		par[i]=i;
		size[i]=1;
	}
}
 
int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return find(par[x]);
	}
}
 
void unite(int x, int y, int i){
	x=find(x);
	y=find(y);
	if(x==y) return;
	if(rk[x]<rk[y]){
		par[x]=y;
		g[y].push_back(PP(P(i, x), P(size[x], size[y])));
		size[y]+=size[x];
	}else{
		par[y]=x;
		g[x].push_back(PP(P(i, y), P(size[y], size[x])));
		size[x]+=size[y];
		if(rk[x]==rk[y]) rk[x]++;
	}
}
 
bool same(int x, int y){
	return find(x)==find(y);
}

int num[100002];
ll ans[100002];
int ct;

void eulertour(int x){
	ct++;
	num[x]=ct;
	for(int i=0; i<g[x].size(); i++){
		int y=g[x][i].first.second;
		eulertour(y);
	}
}

bool used[100002];

void add(int x){
	used[x]=1;
	for(int i=0; i<g[x].size(); i++){
		int y=g[x][i].first.second;
		ll s1=(ll)g[x][i].second.first, s2=(ll)g[x][i].second.second;
		ll c=cab[g[x][i].first.first].first;
		ans[num[x]]+=(s1*c);
		ans[num[x]+s2]-=(s1*c);
		ans[num[y]]+=(s2*c);
		ans[num[y]+s1]-=(s2*c);
		add(y);
	}
}


int main()
{
	int n;
	cin>>n;
	init(n);
	for(int i=0; i<n-1; i++){
		int a, b; ll c;
		cin>>a>>b>>c;
		a--; b--;
		cab.push_back(Pll(c, P(a, b)));
	}
	sort(cab.begin(), cab.end(), greater<Pll>());
	for(int i=0; i<n-1; i++){
		ll c=cab[i].first;
		int a=cab[i].second.first, b=cab[i].second.second;
		unite(a, b, i);
	}
	fill(num, num+n, -1);
	ct=-1;
	for(int i=0; i<n; i++){
		if(num[i]>=0) continue;
		i=find(i);
		eulertour(i);
	}
	for(int i=0; i<n; i++){
		if(used[i]) continue;
		i=find(i);
		add(i);
	}
	for(int i=1; i<n; i++){
		ans[i]+=ans[i-1];
	}
	for(int i=0; i<n; i++){
		cout<<ans[num[i]]<<endl;
	}
	return 0;
}

Measured memory_bytes: 10608
C, R = map(int, input().split())
T = [[0]*(R+1) for i in range(C+1)]

for row in range(C):
    work = list(map(int, input().split()))
    for col in range(R):
        T[row][col] = work[col]

for row in range(C):
    for col in range(0, R):
        T[row][R] += T[row][col]

for row in range(C):
    for col in range(0, R):
        T[C][col] += T[row][col]

for row in range(C):
    T[C][R] += T[row][R]

for row in range(0, C+1):
    print("%d" % (T[row][0]), end="")
    for col in range(1, R+1):
        print(" %d" % (T[row][col]), end="")
    print()



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

#define int long long
#define pb push_back
#define ins insert
#define pii pair<int,int>
#define fs first
#define sc second
#define mpr make_pair
#define iter iterator
#define all(X) X.begin(),X.end()
#define sau(X) sort(all(X)),X.resize(unique(all(X))-X.begin())
#define exist(X,ele) binary_search(all(X),ele)

template<typename T1,typename T2>
ostream& operator << (ostream& out,const pair<T1,T2>& X)
{
	out<<"{"<<X.fs<<","<<X.sc<<"}";
	return out;
}

template<typename T>
ostream& operator << (ostream& out,const vector<T>& X)
{
	for(auto i:X) out<<i<<" ";
	return out;
}

inline void cmin(int& x,int y)
{
	x=min(x,y);
}

inline void cmax(int& x,int y)
{
	x=max(x,y);
}

const int inf=5000000000000000ll;

main()
{
	ios::sync_with_stdio(false);
	
	int x,y; cin>>x>>y;
	if(x==y) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}






















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

typedef double db;
typedef long long ll;
const int N=9;
const int C=59;
const int K=1<<7;

int n,c;
int l[9],a[9];
ll f[C*N][K+9][C*N],sum;
db ans;

int main()
{
	if(fopen("vj.in","r"))
	{
		freopen("vj.in","r",stdin);
		freopen("vj.out","w",stdout);
	}

	scanf("%d%d",&n,&c);
	int k=1<<(n-1);
	for(int i=0;i<n;i++)
		scanf("%d",&l[i]);
	sort(l,l+n,greater<int>());
	for(int i=1;i<n;i++)
		a[i]=i;

	do
	{
		memset(f,0,sizeof(f));
		f[0][0][l[0]*n]=1;
		for(int i=0;i<c*n;i++)
			for(int j=0;j<k;j++)
				for(int k=i;k<=c*n;k++)
					if(f[i][j][k])
					{
						f[i+1][j][k]+=f[i][j][k];
						if(i%n && !(j&(1<<(a[i%n]-1))))
							f[i+1][j|(1<<(a[i%n]-1))][min(c*n,max(k,i+l[a[i%n]]*n))]+=f[i][j][k];
					}
		sum+=f[c*n][k-1][c*n];
	}while(next_permutation(a+1,a+n));

	ans=sum;
	for(int i=1;i<n;i++)
		ans/=(db)i*(db)c;
	printf("%.14f\n",ans);
	return 0;
}


Measured memory_bytes: 302208
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

def cn(n,x):
    return n-(n//x)

def cnt(a,b,x):
    return cn(b,x) - cn(a-1,x)

A,B,C,D = map(int,input().split())
E = lcm(C,D)

# print(E)
# print(cnt(A,B,C))
# print(cnt(A,B,D))
# print(cnt(A,B,E))

print(cnt(A,B,C)+cnt(A,B,D)-cnt(A,B,E))

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> p;
typedef vector<p> vp;
int n,m;
priority_queue<p,vp,greater<p> >  que;
int ans=0;
int main(int argc,char const* argv[])
{
  cin >> n >> m;
  vector<int> x(m);
  for(int i=0;i<m;i++)
    {
      cin >> x[i];
    }
  if(m==1 || n>=m)
    {
      cout << 0 << endl;
      return 0;
    }
  vector<int> dif(m-1);
  sort(x.begin(),x.end());
  ans=x[m-1]-x[0];
  for(int i=0;i<m-1;i++)
    {
      dif[i]=x[i+1]-x[i];
    }
  sort(dif.begin(),dif.end(),greater<int>());
  for(int i=0;i<n-1;i++)
    {
      ans-=dif[i];
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'

const int N = 1e5;

ll arr[2*N+5];
ll cnt[2*N+5];

int main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n; cin >>n;
    for(int i = 0; i<n; i++){
        cin >>arr[i]; cnt[arr[i]]++;
    }

    ll aux = 0;
    for(int i = 1; i<=n; i++){
        aux += (cnt[i]*(cnt[i]-1))/2;
    }

    ll ans;
    for(int i = 0; i<n; i++){
        ans = aux - ((cnt[arr[i]]*(cnt[arr[i]]-1))/2) +  (((cnt[arr[i]]-1)*(cnt[arr[i]]-2))/2);
        cout <<ans <<endl;
    }

    return 0;
}


Measured memory_bytes: 4736
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val a, b = sc.nextFloat

    val ans =
      if (b == 1) 0
      else if (a >= b) 1
      else 1 + Math.ceil((b - a) / (a - 1))
    println(ans.toInt)
  }
}

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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
const int MAX = 10;

using P = pair<int, int>;
using PP = pair<P, int>;  //<<y,x>,distance>

int H,W;
bool g[MAX][MAX]; // 通れるマスならtrue
bool visited[MAX][MAX];

int visited_counter = 1;
bool bfs(int start_y, int start_x) {
  queue<PP> q;
  PP qt = PP(P(start_y, start_x),0);
  q.push(qt);
  while(!q.empty()) {
    qt = q.front();
    int curr_x = qt.first.second;
    int curr_y = qt.first.first;
    int curr_d = qt.second;
    q.pop();
    for(int dy = 0; dy <= 1; ++dy) {
      for(int dx = 0; dx <= 1; ++dx) {
        if(!dy && !dx) continue;  // 自分の位置
        if(dy+dx == 2) continue;
        

        int next_x = curr_x + dx;
        int next_y = curr_y + dy;
        int next_d = curr_d + 1;

        // 範囲外
        if(next_x < 0 || next_x >= W) continue;
        if(next_y < 0 || next_y >= H) continue;

        // 通れないまたはすでに到達済み
        if(!g[next_y][next_x]) continue;
        if(visited[next_y][next_x]) continue;

        if(dx == 1 && curr_y+1 < H && g[curr_y+1][curr_x] && !visited[curr_y+1][curr_x]) {
          return false;
        }

        q.push(PP(P(next_y,next_x),next_d));
        visited[next_y][next_x] = true;
        ++visited_counter;
      }
    }
  }
  return true;
}

signed main() {
  int counter = 0;
  cin >> H >> W;
  REP(h, H) {
    REP(w, W) {
      char c;
      cin >> c;
      g[h][w] = (c == '#');
      if(g[h][w]) ++counter;
    }
  }
  bool possible = bfs(0,0);
  if(!possible) {
    cout << "Impossible" << endl;
    return 0;
  }

  if(counter == visited_counter) {
    cout << "Possible";
  } else {
    cout << "Impossible";
  }
  cout << "\n";
  return 0;
}
/***** MAIN *****/

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();

        long size = b-a + 1;
        long numOfRemoved= 0;
       
        long numOfMultiplyC = b / c - (a -1) / c;
        long numOfMultiplyd = b / d - (a-1) / d;

        long x = c * d / gcd(c, d);
        long numOfMultiplycd = b / x - (a-1) / x;
        
        System.out.println(size - numOfMultiplyC - numOfMultiplyd + numOfMultiplycd);
    }
    

      
    private static long gcd(long m, long n) {
      if(m < n) return gcd(n, m);
      if(n == 0) return m;
      return gcd(n, m % n);
  }
}

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

int main(){
               int A,B,C;cin >> A >> B;
               if (A >= B){
                              C=A-B;
                              if (C%2 == 0){
                                             cout <<B+(C/2)<<endl;
                              }else{
                                             cout << "IMPOSSIBLE" <<endl;
                              }
               }
               if (B >= A){
                              C=B-A;
                              if (C%2 == 0){
                                             cout<<A+(C/2)<<endl;
                              }else{
                                             cout << "IMPOSSIBLE" <<endl;
                              }
               }

}


Measured memory_bytes: 256
import math
N, K = map(int, input().split())
prob = []
for i in range(N):
  if i+1 >= K:
    prob.append(1)
  else:
    temp = i+1
    x = 0
    while temp < K:
      temp *=2
      x += 1
    prob.append(0.5**x)
Answer = sum(prob)/N

print(Answer)

Measured memory_bytes: 3956
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
//              0 1 2 3 4 5 6 7 8 9
int match[10]={-1,2,5,5,4,5,6,3,7,6};

string maxstr(string s1, string s2){
  if(s2.size()>s1.size()) return s2;
  if(s2.size()<s1.size()) return s1;
  if(s1<s2) return s2;
  else return s1;
}

string dp[11111];
int main(){
  int n,m;
  cin>>n>>m;  

  int t;
  vector<pii> a;
  for(int i=0;i<m;i++){
    cin>>t;
    a.pb(pii(match[t],t));
  }
  
  for(int i=0;i<m;i++){
    int tugi=n-a[i].first;
    if(tugi<0) continue;
    dp[tugi]=maxstr(dp[tugi],to_string(a[i].second));
  }
  
  for(int k=n;k>0;k--){
    if(dp[k]=="") continue;
    
    for(int i=0;i<m;i++){
      int tugi=k-a[i].first;
      if(tugi<0) continue;
      string tmp=maxstr(dp[tugi],(dp[k]+to_string(a[i].second)));
      dp[tugi]=tmp;
    }
  }
  cout<<dp[0]<<endl;
  
  // for(int i=n;i>=0;i--){
  //   cout<<i<<" : "<<dp[i]<<endl;
  // }
  
  return 0;
}


Measured memory_bytes: 33024
import sys

n,k=input().strip().split()
r,s,p=input().strip().split()
t=input().strip()

n=int(n)
k=int(k)
r=int(r)
s=int(s)
p=int(p)

esp=list(t)

totalWin=0

for i in range(len(esp)):
    win=0
    if esp[i]=="r": #paper
        win=p
    elif esp[i]=="s": #rock
        win=r
    elif esp[i]=="p": #sisers
        win=s
    
    bef=(i-k)

    if bef>=0:
        if esp[bef]==esp[i]:
            win=0
            esp[i]="v"

    totalWin+=win

print(totalWin)
sys.exit()


Measured memory_bytes: 4084
s = input()
s1 = s[0:2]
s2 = s[2:4]
res = ("1" if int(s[0:2]) <= 12 and int(s[0:2]) > 0 else "0") + \
    ("1" if int(s[2:4]) <= 12 and int(s[2:4]) > 0 else "0")

if(res == "11"):
    print("AMBIGUOUS")
elif(res == "10"):
    print("MMYY")
elif(res == "01"):
    print("YYMM")
elif(res == "00"):
    print("NA")


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
    int n,L;
    cin>>n>>L;
    int pre=0,cur,sum=0,t=0;
    bool flag=0;
    for(int i=0;i<n;++i){
        cin>>cur;
        if(!flag&&cur-pre>0||flag&&cur-pre<0) t += L-cur;
        else{
            sum=max(sum,t);t=L*2-pre-cur;flag=!flag;
        }
        pre=cur;
    }
    sum=max(sum,t);
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3100
#include <stdio.h>

int main(){
	char ch;
	while((ch = getchar()) != EOF){
			if(ch >= 97 && ch <= 122)
				printf("%c",ch-32);
			else if(ch >= 65 && ch <= 90)
				printf("%c",ch+32);
			else
				printf("%c",ch);
	}
    return 0;
}


Measured memory_bytes: 2036
N=int(input())
s=list(map(int,input().split()))

s.sort()
sums=0
for i in range(N):
    if i<=1:
        sums=sums+s[i]
    else:
        sums=sums+s[i]*(2**(i-1))
sums=sums/(2**(N-1))
print(sums)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

int N, M, A[9][9];
//---------------------------------------------------------------------------------------------------
int check(int y) {
    int win = 0, lose = 0;
    rep(x, 0, N) {
        if (A[y][x] == 1) win++;
        else if (A[y][x] < 0 and y != x) lose++;
    }
    return win <= (N - 1) / 2 and (N - 1) / 2 <= win + lose;
}
//---------------------------------------------------------------------------------------------------
int answer = 0;
void dfs(int cu) {
    int x = cu % N;
    int y = cu / N;

    if (cu == N * N) {
        answer++;
        return;
    }

    if (x == y or 0 <= A[y][x]) {
        if (check(y)) dfs(cu + 1);
        return;
    }
    
    A[y][x] = 1; A[x][y] = 0;
    if(check(y)) dfs(cu + 1);

    A[y][x] = 0; A[x][y] = 1;
    if (check(y)) dfs(cu + 1);

    A[y][x] = A[x][y] = -1;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    while (cin >> N) {
        if (N == 0) return;
        cin >> M;
        rep(i, 0, N) rep(j, 0, N) A[i][j] = -1;
        rep(i, 0, M) {
            int a, b; cin >> a >> b;
            a--; b--;
            A[a][b] = 1;
            A[b][a] = 0;
        }

        answer = 0;
        dfs(0);
        printf("%d\n", answer);
    }
}




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

using namespace std;

int main(){
 int i;
 string S;
 cin >> S;
 int f[26];
 for (i=0;i<26;++i){
   f[i]=0;
 }
 if (S.length()==26) {
   for (i=0;i<25;++i) {
     f[S.c_str()[25-i]-'a']=1;
     if (S.c_str()[25-i] > S.c_str()[24-i]) {
       break;
     }
     if (i==24) {
       cout << -1;
       return 0;
     }
   }
   char U=S.c_str()[24-i];
   int j=0;
   for (j=0;j<26;++j){
     U+=1;
     if (f[U-'a']==1) break;
   }
   cout << S.substr(0,24-i) + U;
   return 0;
 }
 for (i=0;i<S.length();++i){
   f[S.c_str()[i]-'a']=1;
 }
 for (i=0;i<26;++i){
   if (f[i]==0) break;
 }
 char U='a'+i;
 cout << S + U;
 return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

ll eulerPhi(ll n){
  if(n <= 0) return 0;
  ll res = n;
  for(int i=2; i*i<=n; i++) {
    if(n % i == 0){
      res -= res / i;
      while(n % i == 0) n /= i;
    }
  }
  if(n > 1) res -= res / n;
  return res;
}

int main(){
  int n;

  cin >> n;

  cout << eulerPhi(n) << endl;
  
  return 0;
}





Measured memory_bytes: 3096
import java.util.*;
public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		String number = sc.next();

		String start = number.substring(0, 1);
		String end = number.substring(2, 3);

		if (start.equals(end)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 25428
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define Q queue
#define Qi Q<int>
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;

unordered_map<int, int> factor(int n){
  int cnt = 0;
  unordered_map<int, int> m;
  int nn = n;
  while (!(nn & 1))
    cnt++, nn /= 2;
  if(cnt)
    m[2] = cnt;
  for (int i = 3; i <= sqrt(n); i++){
    cnt = 0;
    while(nn % i == 0)
      nn /= i, cnt++;
    if (cnt)
      m[i] = cnt;
  }
  if (nn > 2)
    m[nn] = 1;
  
  return m;
}



int n, m, QQ;
const int q = 200200;
int max_ = 0;
int a[q], b[q], c[q], d[q];

void dfs(int bars, int balls, Vi v){
  if (bars){
    Vi u = v;
    u.pb(0);
    dfs(bars - 1, balls, u); 
  }
  if(balls){
    Vi u = v;
    u.pb(1);
    dfs(bars, balls - 1, u);
  }
  if (not bars and not balls){
    int cur = 1;
    Vi vv;
    for (int i: v)
      if(i)
	cur++;
      else
	vv.pb(cur);
    
    int s = 0;
    for (int i = 0; i < QQ; i++){
      s += d[i]  * (vv[b[i]] - vv[a[i]] == c[i]);
    }
    max_ = max(max_, s);

  }


}

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

  
  cin >> n >> m >> QQ;
  for (int i = 0; i < QQ; i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }

  Vi v;
  // n bars and m - 1 balls
  dfs(n, m - 1, v);

  cout << max_ << endl;
}


Measured memory_bytes: 3632
a = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]
x, y = map(int, input().split())
c = 0
for i in range(3):
    if x in a[i] and y in a[i]:
        c = 1
print("Yes" if c == 1 else "No")

Measured memory_bytes: 3060
N = int(input())
An = list(map(int,input().split(' ')))

a = sum(An[0::2]) - sum(An[1::2])
output_list = [0] * N
output_list[0] = a
last = An[N-1] * 2 - a
output_list[N-1] = last
for i in range(N -2):
    output_list[N-i-2] = An[N-i-2] * 2 - output_list[N-i-1]
print(' '.join(map(str,output_list)))

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


int main() {
    int a,b; cin >> a >> b;
    int count = 1, sum = a;
    while(sum < b){
        sum += (a-1);
        count++;
    }
    if(b == 1) 
    {
        cout << '0' << endl;
        return 0;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define rep(i,N) for(ll i=0; i<N; i++)
const ll mod=1e9+7;

int main(){
	int N;
	cin >> N;
	vector<string> S(N);
	map<string,int> m;
	int max=0;
	rep(i,N){
		cin >> S[i];
		m[S[i]]++;
		if(max<m[S[i]]){
			max=m[S[i]];
		}
	}	

	for(auto item : m){
		if(max==item.second){
			cout << item.first << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 26752
#include <bits/stdc++.h>
#define  rep(i,a,b)for(int i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const int INF=1000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;


int main() {
	int n;
	int a[100005];
	cin>>n;
	a[0]=0;
	a[n+1]=0;
	int ans=0;
	rep(i,1,n+1){
		cin>>a[i];
		ans+=abs(a[i]-a[i-1]);
	}
	ans+=abs(a[n]);

	rep(i,1,n+1){
		int t=ans;
		ans-=abs(a[i]-a[i-1]);
		ans-=abs(a[i+1]-a[i]);
		ans+=abs(a[i+1]-a[i-1]);
		cout<<ans<<endl;
		ans=t;
	}

	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
    int x, y;

    while(1)
    {
        cin >> x >> y;
        if(x==y && x==0) break;
        vector<int> vec;
        vec.push_back(x);
        vec.push_back(y);
        sort(vec.begin(), vec.end());
        cout << vec[0] << " " << vec[1] << endl;
    }
    return 0;
}



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

#define MOD 1000000007
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a % mod * a % mod;
        n >>= 1;
    }
    return res;
}

ll comb(ll a, ll b){ //aCbをmod計算
    ll ans = 1;
    for (int i = 1; i <= b; i++)
    {
        ans %= MOD;
        ans *= (a-i+1);
        
    }
    for (int i = 1; i <= b; i++)
    {
        ans %= MOD;
        ans *= modinv(i, MOD);
    }
    return ans%MOD;
}

int main() {
    ll n,a,b; cin >> n >> a >> b;
    ll ans = modpow(2,n,MOD);
    ans -= comb(n,a)+comb(n,b);
    ans = ans%MOD;
    if(ans < 0) ans += MOD;
    cout << ans-1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (void) {
	int N, M;
	cin >> N>> M;
	vector<int> hoge(N, 0);
	for(int i= 0; i < M; i++){
      int a, b;
      cin >> a >> b;
      hoge[a-1]++;
      hoge[b-1]++;
    }
  	for(int i = 0; i < N; i++){
      	cout << hoge[i] << endl;
    }
	return 0; 
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            //var S = Console.ReadLine();
            var N = long.Parse(Console.ReadLine());
            //var ABHM = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();

            var S = new long[N];
            var ans = 0L;
            for (int i = 0; i < N; i++)
            {
                S[i] = long.Parse(Console.ReadLine());
                ans += S[i];
            }

            if (ans%10 == 0)
            {
                Sort(S);
                var ex = -1L;
                for (int i = 0; i < N; i++)
                {
                    if(S[i]%10 != 0)
                    {
                        ex = S[i];
                        break;
                    }
                }

                if(ex == -1)
                {
                    Console.WriteLine(0);
                }
                else
                {
                    Console.WriteLine(ans - ex);
                }
            }
            else
            {
                Console.WriteLine(ans);
            }


            
        }


    }

}


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

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define scn(var)         cin >> var;
#define pYes()           prt("Yes")
#define pNo()            prt("No")
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"

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

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

  vecll b(n);
  rep(i,n){
    if(i==0){
      b[i] = a[0]-a[n-1]+k;
    } else {
      b[i] = a[i]-a[i-1];
    }
  }

  sortall(b);
  prt(k-b[n-1]);
}


Measured memory_bytes: 3328
#include <stdio.h>
#include <string.h>

int ans = 0, n;

void backtrack(int panjang, int mask, int angka) {
	if ((panjang == 0)) {
		if ((mask == 7) && (angka <= n))
			ans++;
		return;
	}
	backtrack(panjang - 1, mask | 1, (10 * angka) + 3);
	backtrack(panjang - 1, mask | 2, (10 * angka) + 5);
	backtrack(panjang - 1, mask | 4, (10 * angka) + 7);
}

int main() {
	int len;
	char teks[15];
	scanf("%s", teks);
	len = strlen(teks);
	sscanf(teks, "%d", &n);
	for (int i = 3; i <= len; i++)
		backtrack(i, 0, 0);
	printf("%d\n", ans);
	return 0;
}

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

	public static void main(String[] args) {
		String input;
		int cnt = 0;
		Scanner sc = new Scanner(System.in);
		input = sc.next();
		String[] strArray = input.split("");
		for(String s : strArray) {
			if(s.equals("1")) {
				cnt++;
			}
		}
		System.out.println(cnt);

	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int a,b,c;
	int total=0;

	cin>>a>>b>>c;

	if(a!=b&&a!=c){
		total++;
	}
	if(a!=b&&b!=c){
		total++;
	}
	if(a!=c&&b!=c){
		total++;
	}
	if(a==c){
		total++;
	}else if(a==b){
		total++;
	}else if(b==c){
		total++;
	}

	cout<<total<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define testing 1
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = -1;
#if !testing
#define cerr if(0)cout
#endif

int32_t main() 
{
	IAMSPEED
	ll x,y,z; cin >> x >> y >> z;
	swap(x,y);
	swap(x,z);
	cout << x << ' ' << y << ' ' << z;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

int main() {
  //
  string s;
  cin >> s;
  int ans = s.size();
  int n = s.size();
  rep(i, n - 1) {
    if (s[i] != s[i + 1]) {
      int k = max(i + 1, n - 1 - i);
      // cerr << k << endl;
      ans = min(ans, k);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
     int n;
     cin>>n;
     int j,arr[n];
     for(j=0;j<n;j++)
     {
		 cin>>arr[j];
	 }
	 int answer=1000000000;
	 for(int x=1;x<=100;x++)
	 {
		 int count=0;
		 for(j=0;j<n;j++)
		 {
			 int p=arr[j];
			 count+=(x-p)*(x-p);
		 }
		 answer=min(answer,count);
	 }
	 cout<<answer<<endl;
}


Measured memory_bytes: 256
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)	

int max(ll a, ll b) {
	ll max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(ll a, ll b) {
	ll min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main() {
	int n, k;
	int h[100002];
	int cnt = 0;

	cin >> n >> k;

	rep(i, n) {

		cin >> h[i];

		if (h[i] >= k) cnt++;
	}

	cout << cnt << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fi first
#define se second
#define pb push_back
ll mod = 1000000007;
void secondsort(vector<pair<ll,ll>> &v){
    for(ll i=0;i < v.size();i++){
    swap(v.at(i).first,v.at(i).second);
    }
    sort(v.begin(),v.end());
    for(ll i=0;i < v.size();i++){
    swap(v.at(i).first,v.at(i).second);
    }
}

signed main(){
    ll n,k,cntt=1,ans=0;
    cin >> n >> k;
    vector<bool> v(n,false);//flag
    vector<pair<ll,ll>> u(n);
    vector<ll> s;//二個目以降
    vector<ll> f;

    for (ll i = 0; i < n; i++)
    {
        cin >>u.at(i).fi>>u.at(i).se;
    }

    secondsort(u);//おいしさ順にソート
    
    for (ll i = n-1; 0<=i; i--)
    {
        if(v.at(u.at(i).fi-1)==false){
            v.at(u.at(i).fi-1)=true;
            f.pb(u.at(i).se);
        }else{
            s.pb(u.at(i).se);
        }
    }//種類トップを分別

    sort(f.begin(),f.end());
    sort(s.begin(),s.end());//ソート（昇順）
    
    vector<ll> fsum((ll)f.size()),ssum((ll)s.size());
    for (ll i = 0; i < f.size(); i++)
    {
        if(i==0){
            fsum.at(i)=f.at((ll)f.size()-i-1);
        }else{
            fsum.at(i)=fsum.at(i-1)+f.at((ll)f.size()-i-1);
        }
    }//累積テーブルを作っておく（降順）→いくつ取るかすぐわかる

    for (ll i = 0; i < ssum.size(); i++)
    {
        if(i==0){
            ssum.at(i)=s.at((ll)s.size()-i-1);
        }else{
            ssum.at(i)=ssum.at(i-1)+s.at((ll)s.size()-i-1);
        }
    }//累積
    
    if(k-1<(ll)fsum.size()){
        ans=max(fsum.at(k-1)+(k*k),ans);
    }//片方のテーブルからのみ選ぶ場合（secondテーブルだけから取るのは明らかに不適当）

    for (ll i = 0; i < (ll)fsum.size(); i++)
    {
        if(0<=k-i-2 && k-i-2< (ll)ssum.size() && i<(ll)fsum.size()){
            ans=max(ans,fsum.at(i)+(i+1)*(i+1)+ssum.at(k-i-2));
        }
    }
    
    cout << ans << endl;
}
/*単純なおいしさ貪欲、種類貪欲は無理、DPも計算量が無理→アルゴリズムを作るしかない...?

種類トップのおいしさ順のテーブル(first)と、残りで作ったおいしさ順のテーブル(second)を作る
両方のテーブルを降順にソートし、それぞれ（片方）のテーブルの上位から選んで、合計ｋ個とる(O(k))
全ての取り方のうちのmaxが答え(上位から選ぶ部分は累積和で処理）

種類別のおいしさトップを取ることなしに、その種類を取ることは明らかに不適当
なので何種類取ったかは fからいくつ取ったかで判断する→ネタボーナスを加えられる
x種類選ぶときは、必ず種類topのテーブルのをとる
*/

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define ifnot(x) if(not(x))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int N, C, K;
int T[100000];
int cnt;

void solve() {
  cin >> N >> C >> K;
  rep(i, N) {
    cin >> T[i];
  }
  sort(T, T+N);

  for(int i = 0; i < N;) {
    int capacity = C;
    cerr << "BUS " << cnt << ": " << T[i];
    int last = T[i] + K;
    capacity--; i++;
    while (capacity && i < N) {
      if (T[i] > last) break;
      cerr << ' ' << T[i];
      capacity--; i++;
    }
    cerr << endl;
    cnt++;
  }
  cout << cnt << endl;
}

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

Measured memory_bytes: 640
a,b,k = gets.chomp.split(' ').map(&:to_i)
if a >= k # aがk以上
  a-=k
elsif b >= (k-a) # 
  b-=(k-a)
  a = 0
else # b < k
  a = 0
  b = 0
end
puts "#{a} #{b}"

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


int main(void) {
   string S;
   cin>>S;
   map<char,int> s;
   bool flag = true;
   for (int i = 0; i < 4; i++) s[S[i]] += 1;
   for (auto el:s) {
      if (el.second != 2) flag = false;
      // cout<<el.first<<" "<<el.second<<endl;
   }
   if (flag) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}

Measured memory_bytes: 256
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#define ll long long
#define str string
#define rtn return
#define endl '\n'
#define F first
#define S second
#define pb push_back
#define db long double
#define MOD 1000000007
#define INF 1e18
#define EPS 1e-15
#define pll pair <ll, ll>
#define vi vector<ll>
#define vpll vector<pll>
#define value_at find_by_order
#define index_of order_of_key
#define fill(a,v) memset(a,v,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(ll i=0;i<n;++i)
#define per(i,n) for(ll i=n-1;i>=0;--i)
#define loop1(i, n) for (int i=1;i<=n;++i)
#define loop(i, begin, end) for (__typeof(end) i = (begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);std::cout.tie(NULL)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma+1, args...);
}
#else
#define trace(...)
#endif

template<class T> void remin(T &a, T b) {a = min(a, b);}
template<class T> void remax(T &a, T b) {a = max(a, b);}
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define N 3005

ll dp[N][N][2];
ll a[N];
ll n;

ll solve(int i, int j, int mask) {
  if (i == j) {
    if (!mask) rtn a[i];
    else rtn -a[i];
  }
  if (dp[i][j][mask] != -1) rtn dp[i][j][mask];
  if (!mask) {
    dp[i][j][mask] = -INF;
    remax(dp[i][j][mask], a[i] + solve(i + 1, j, !mask));
    remax(dp[i][j][mask], a[j] + solve(i, j - 1, !mask));
  } else {
    dp[i][j][mask] = INF;
    remin(dp[i][j][mask], solve(i + 1, j, !mask) - a[i]);
    remin(dp[i][j][mask], solve(i, j - 1, !mask) - a[j]);
  }
 // trace(i, j, mask, dp[i][j][mask]);
  rtn dp[i][j][mask];
}

int main() {
  FAST_IO;
  fill(dp, -1);
  cin >> n;
  rep(i, n) cin >> a[i];
  cout << solve(0, n-1, 0);
  rtn 0;
}


Measured memory_bytes: 141568
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;



int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int a, b;
    cin >> a >> b;
    cout << (ll) a * b / __gcd(a, b);




}


Measured memory_bytes: 256
#include <stdio.h>

int uruu(int year);
int ndays(int fromy, int fromm, int fromd, int toy, int tom ,int tod);

int main(){
    while (1) {
        int y, cnt = 0;
        int fromy, fromm, fromd, toy, tom, tod;
        scanf("%d %d %d %d %d %d", &fromy, &fromm, &fromd, &toy, &tom, &tod);
        if (fromy < 0 || fromm < 0 || fromd < 0 || toy < 0 || tom < 0 || tod < 0) {
            break;
        }
        int total = ndays (fromy, fromm, fromd, toy, tom, tod);
        for(y = fromy + 1; y < toy; y++) {
            if(uruu (y) == 1) {
                cnt++;
            }
        }
        total += (((toy - fromy - 1)) * 365) + cnt;
        printf("%d\n", total);
    }
    return 0;
}
int uruu(int year){
    int result = 0;
    if(year % 400 == 0){
        result = 1;
    }
    else if (year % 100 == 0){
        result = 0;
    }
    else if (year % 4 == 0){
        result = 1;
        
    }
    return result;
}

int ndays (int fromy, int fromm, int fromd, int toy, int tom, int tod){
    int j;
    int result = 0;
    int day[13] ={0,31,28,31,30,31,30,31,31,30,31,30,31};
    for (j = fromm;  j <= 12; j++) {
        if (j == 2) {
            result+=uruu(fromy);
        }
        result += day[j];
    }
    for (j = 1; j < tom; j++){
        if (j == 2){
            result += uruu(toy);
        }
        result += day[j];
    }
    result += tod;
    result -= fromd;
    return result;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int test[12345678];
signed main() {
	int n, a, res = 0, ok = 0; cin >> n;
    vector<vector<int>> kariG(n + 1), cost(123456), ans(123456);
    vector<int> G(n + 1), kari(n + 1);
    //for (int h = 0; h <= n; h++) { ans[h] = INF; }//初期化
    for (int h = 2; h <= n; h++) {//入力
        cin >> a; G[h] = a; kari[a]++; kariG[a].push_back(h);
	}
    queue<int> QUE; queue<int> CNT;//1からその頂点までの距離を調べる
    for (int i = 0; i < kariG[1].size(); i++) {
        QUE.push(kariG[1][i]); CNT.push(2); 
        if (kariG[kariG[1][i]].size() == 0) {
            cost[2].push_back(kariG[1][i]);
        }
        res = max(res, (long long)2);
    }
    while (QUE.size()) {
        for (int i = 0; i < kariG[QUE.front()].size(); i++) {
            QUE.push(kariG[QUE.front()][i]); CNT.push(CNT.front() + 1);
            if (kariG[kariG[QUE.front()][i]].size() == 0) {
                cost[CNT.front() + 1].push_back(kariG[QUE.front()][i]);
            }
            res = max(res, CNT.front() + 1);//1からの最大値
        }
        QUE.pop(); CNT.pop();
    }
    for (int h = res; h >= 0; h--) {
        for (int i = 0; i < cost[h].size(); i++) {
            ans[cost[h][i]].push_back(0);
        }
    }
    for (int h = res; h >= 0; h--) {
        for (int i = 0; i < cost[h].size(); i++) {
            //cout << h << ' ' << cost[h][i] << endl;
            int z = 0;
            if (cost[h][i] != 1) {
                sort(ans[cost[h][i]].begin(), ans[cost[h][i]].end());
                for (int j = 0; j < ans[cost[h][i]].size(); j++) {
                    ans[cost[h][i]][j] += ans[cost[h][i]].size() - 1 - j;
                    z = max(z, ans[cost[h][i]][j]);
                }
                //cout << G[cost[h][i]] << ' ' << cost[h][i] << endl;
                if (test[G[cost[h][i]]] == 0) { cost[h - 1].push_back(G[cost[h][i]]); }
                test[G[cost[h][i]]]++;
                ans[G[cost[h][i]]].push_back(z + 1);
            }
        }
    }
    sort(ans[1].begin(), ans[1].end());
    for (int h = 0; h < ans[1].size(); h++) {
        ans[1][h] += ans[1].size() - h - 1;
        ok = max(ok, ans[1][h]);
        //cout << ans[1][h] << endl;
    }
    cout << ok << endl;
	return 0;
}

Measured memory_bytes: 20096
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cstdio>
using namespace std;

inline int getint()
{
	int x = 0, c = getchar();
	while (c > 47 && c < 58)
	{
		x = x * 10 + c - 48;
		c = getchar();
	}
	return x;
}

constexpr int MAX = 300001;
int res[MAX * 4];
int H, W, M, ans, x, y, h, w, mxr = 0, mxc = 0, ctrow = 0, ctcol = 0;

int main()
{
	H = getint();
	W = getint();
	M = getint();

	for (int i = 0; i < M; ++i)
	{
		h = getint(), w = getint();
		res[i + 2 * MAX] = h, res[i + 3 * MAX] = w;
		x = ++res[h], y = ++res[w + MAX];

		if (x == mxr) ++ctrow;
		else if (x > mxr) mxr = x, ctrow = 1;

		if (y == mxc) ++ctcol;
		else if (y > mxc) mxc = y, ctcol = 1;
	}
	ans = mxr + mxc;

	int ct = ctrow;
	if (ctrow > M / ctcol)
	{
		printf("%d\n", ans);
		return 0;
	}
	ct *= ctcol;

	for (int i = 0; i < M; ++i) if (res[res[i + 2 * MAX]] == mxr && res[res[i + 3 * MAX] + MAX] == mxc) --ct;
	printf("%d\n", ans - (ct <= 0));
}

Measured memory_bytes: 6292
input = readlines()

a, b = input.shift().chomp.split("\s")
s, t = input.shift().chomp.split("\s").map{|x| x.to_i}
u = input.shift().chomp

s2 = a == u ? s - 1 : s
t2 = b == u ? t - 1 : t

puts "#{s2} #{t2}"


Measured memory_bytes: 14268
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    ll n,w,x,y;
    cin>>n>>w;
    ll a[w+3]={0},b[n+2];
    for(ll i=1;i<=n;i++){
        cin>>b[i]>>a[i];
    }
    ll d[n+1][w+1]={0};
    for(ll j=1;j<=w;j++){
        if(j<b[1]) d[1][j]=0;
        else d[1][j]=a[1];
    }
    
    for(ll i=2;i<=n;i++){
        for(ll j=0;j<=w;j++){
            d[i][j]=d[i-1][j];
            if(j>=b[i]){
                d[i][j]=max(d[i][j],d[i-1][j-b[i]] + a[i]);
            }
            //cout<<d[i][j]<<" ";
        }
        //cout<<"\n";
    }
    /*for(int i=1;i<=n;i++){
        for(int j=0;j<=w;j++) cout<<d[i][j]<<" ";
        cout<<"\n";
    }*/
    cout<<max(d[n][w],d[n][w-1]);
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
#define MOD 1000000007

int main(void){

    ull n, b, r;
    cin >> n >> b >> r;

    ull  roop = b + r;

    ull div_n = n / roop;
    ull mod_n = n % roop;

    if(mod_n >= b)
        cout << div_n * b + b << endl;
    else
        cout << div_n * b + mod_n << endl;
    return 0;
}

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

typedef long long ll;

main()
{
    string s;
    cin >> s;
    int c = 0;
    for(int i = 0; i < s.size(); i++){
        for(int j = i + 1; j < s.size(); j++ ){
            if(s[i] == s[j]){
                c++;
            }
        }
    }
    if(c == 2){
        cout << "Yes";
    }
    else{
        cout << "No";
    }


}





///promy_pompom
//hello world


Measured memory_bytes: 3604