akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> s(H, vector<char> (W));
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      cin >> s.at(i).at(j);
    }
  }
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) {
      if(s.at(i).at(j) == '#') {
        if(i > 0) {
          if(s.at(i - 1).at(j) == '#') {
            continue;
          }
        }
        if(j > 0) {
          if(s.at(i).at(j - 1) == '#') {
            continue;
          }
        }
        if(i < H - 1) {
          if(s.at(i + 1).at(j) == '#') {
            continue;
          }
        }
        if(j < W - 1) {
          if(s.at(i).at(j + 1) == '#') {
            continue;
          }
        }
      } else {
        continue;
      }
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = []
cnt = 0
for i in range(1,n-1,2):
  cnt += a[i]*2  
ans.append(sum(a)-cnt)
for i in range(n):
  ans.append(a[i]*2-ans[i])
print(*ans[:-1])

Measured memory_bytes: 20552
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<limits>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
bool ok(string s){
	int count[10]={};
	rep(i,s.size()){
		count[s[i]-'0']++;
	}
	if(count[3]*count[5]*count[7]>0) return true;
	else return false;
}
int main(){
	string N;
	scan(N);
	int L=N.size();
	int dp[10001][2][2][2][2][2][2]={};//dp[i桁目まで読んだ][N未満であることが確定][3が既出][5が既出][7が既出][3,5,7以外出てこない][まだ0しか出てきてない]
	int ans=0;
	dp[0][0][0][0][0][1][1]=1;
	rep(i,L){
		rep(j,2){
			rep(three,2){
				rep(five,2){
					rep(seven,2){
						rep(p,2){
							rep(q,2){
								int lim= j ? 9 : N[i]-'0';
								rep(d,lim+1){
									dp[i+1][j||d<lim][three||d==3][five||d==5][seven||d==7][(p||q)&&(d==3||d==5||d==7)][q&&d==0]+=dp[i][j][three][five][seven][p][q];
								}
							}
						}
					}
				}
			}
		}
	}
	rep(j,2){
		ans+=dp[L][j][1][1][1][1][0];
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 2688
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MOD 1000000007
typedef unsigned long long ull;
typedef   signed long long sll;


#define N_MAX 100
#define M_MAX 100

ull n;
char s[N_MAX + 1];

void swap_adj(ull *a, ull *b){
	ull tmp = *b;
	*b = *a;
	*a = tmp;
	return;
}

int comp(const void *a, const void *b){
	if (*(ull*)a > *(ull*)b) {
		return -1;
	} else if (*(ull*)a < *(ull*)b) {
		return +1;
	} else {
		return 0;
	}
}

int solve(){
	
	int i;
	int leftFill = 0;
	int diff = 0;
	for (i = 0; i < n; i++) {
		if (s[i] == '(') {
			diff++;
		} else if (diff) {
			diff--;
		} else {
			leftFill++;
		}
	}

	for (i = 0; i < leftFill; i++) putchar('(');
	printf("%s", s);
	for (i = 0; i < diff; i++) putchar(')');
	putchar('\n');

	return 0;
}

int main(void){
	ull i;

	scanf("%llu", &n);
	scanf("%s", s);

	solve();

	return 0;
}


Measured memory_bytes: 128
n = int(input())
 
ans = n
for i in range(n+1):
    count = 0
    t = i
    while(t):
        count += t % 6
        t = int(t/6)
    t = n-i
    while(t):
        count += t % 9
        t = int(t/9)
    ans = min(ans, count)
print(ans)

Measured memory_bytes: 3064
def splitter(str):
    for i in range(1, len(str)):
        start = str[0:i]
        end = str[i:]
        yield (start, end)
        for split in splitter(end):
            result = [start]
            result.extend(split)
            yield result


if __name__ == "__main__":
    s = str(input())
    possibilities = list(splitter(s))
    sum = int(s)
    for i in possibilities:
        for j in i:
            sum += int(j)
    print(sum)


Measured memory_bytes: 3060
/*
*	User: Isanchez_Aguilar
*	Problem: CodeForces 
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>

using namespace std;
using Long = long long;

int main(void)
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	bool isGood = true;

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i)
	{
		int val;
		cin >> val;
			
		if (val % 2 == 0)	
			isGood &= (val % 3 == 0 or val % 5 == 0);
	}


	if (isGood)
		cout << "APPROVED\n";
	else
		cout << "DENIED\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

class Edge{
public:
    int from, to, cost;
    Edge(int from = 0, int to = 0, int cost = 0) :
            from(from), to(to), cost(cost){}

    bool operator < (const Edge &e) const{
        return cost < e.cost;
    }
    bool operator >(const Edge &e) const{
        return cost > e.cost;
    }

};

static const int INFTY = (1 << 21);

class Node{
public:
    vector<Edge> edges;
    int dist;
    Node(){
        dist = INFTY;
    }
};

class Graph{
public:
    vector<Node> nodes;
    Graph(int n) {
        rep(i, n) { Node n;  nodes.push_back(n); }
    }
    Node& operator[](int i){
        return nodes[i];
    }
};

class Data{

public:
    int dist;
    Edge edge;
    Data(int dist, Edge edge) {
        this->dist = dist;
        this->edge = edge;
    }

    bool operator < (const Data &d) const{
        return dist < d.dist;
    }
    bool operator >(const Data &d) const{
        return dist > d.dist;
    }
};

Graph G(0);
int N;

struct Info{ int idx, dist;};

Info bfs(int start){

    priority_queue<Data, vector<Data>, greater<Data>> q;

    rep(i, N){
        G[i].dist = INFTY;
    }
    G[start].dist = 0;
    for(Edge& ed: G[start].edges){
        q.push(Data(G[start].dist + ed.cost, ed));
    }

    while(!q.empty()){
        Data d = q.top(); q.pop();
        Edge& e = d.edge;
        Node& n = G[e.to];
        // printf("-- %d %d %d %d\n", e.from, e.to, e.cost, n.dist);

        if(n.dist != INFTY) continue;

        n.dist = d.dist;
        for(Edge &ed: n.edges){
            q.push(Data(n.dist + ed.cost, ed));
            // printf("// %d %d %d %d\n", ed.from, ed.to, ed.cost, n.dist);
        }

    }

    int dist = -1;
    int idx = -1;
    rep(i, N){
        if(G[i].dist > dist){
            dist = G[i].dist;
            idx = i;
        }
    }

    Info info;
    info.idx = idx; info.dist = dist;
    // printf("%d %d\n", idx, dist);
    return info;

}

int main() {
    cin >> N;
    G = Graph(N);
    rep(i, N-1){
        int from, to, cost;
        cin >> from >> to >> cost;
        G[from].edges.push_back(Edge(from, to, cost));
        G[to].edges.push_back(Edge(to, from, cost));
        // printf("++ %d %d %d\n", from, to, cost);
    }

    Info info = bfs(0);
    info = bfs(info.idx);

    cout << info.dist << endl;
}

Measured memory_bytes: 11600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
//#include "graph.cpp"
#define ll long long
#define loop(i,n) for(int i=0 ; i<n ; ++i)
#define rep(i,x,n) for(int i=x ; i<=n ; ++i)
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)
#define getOpp(x) (x^2)
#define NOT(x) (x^1)
using namespace std;
using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_set;
const int N=1e5 + 5;
int arr[N] , n;
ll memo[N][5];
ll dp(int i,bool changed){
    if(i>=n){
        return 0;
    }
    if(i==n-1){
        if(changed)
            return -1*arr[i];
        return arr[i];
    }
    ll &res = memo[i][changed];
    if(res != -1){
        return res;
    }
    if(changed){
        res = arr[i] + dp(i+1 , 1);
        res = max(res , -1*arr[i] + dp(i+1 , 0));
    }else{
        res = -1*arr[i] + dp(i+1 , 1);
        res = max(res , arr[i] + dp(i+1 , 0));
    }
    return res;
}
//void printPath(int i){
//    if(i>=n)return;
//    if(memo[i+1][1] >= memo[i+1][0]){
//        cout<<i<<" ";
//        printPath(i+1 );
//    }else{
//        printPath(i+1 );
//    }
//}
int main(){
    cin.sync_with_stdio(false), cin.tie(0) , cout.tie(0);
    cin>>n;
    memset(memo , -1,sizeof(memo));
    loop(i,n){
        cin>>arr[i];
    }
    cout<<dp(0,0)<<endl;
//    printPath(0);
}


Measured memory_bytes: 9216
N, D, A = gets.split.map(&:to_i)
XHs = readlines.map{|l| l.split.map(&:to_i)}

ans, b, bs = 0, 0, []
XHs.sort.each do |x, h|
  while !bs.empty? && bs[0][0] < x
    b -= bs.shift[1]
  end
  h -= b
  next if h <= 0
  n = (h + A - 1)/A
  ans += n
  y = n*A
  bs << [x + 2*D, y]
  b += y
end
puts ans

Measured memory_bytes: 34780
N,A,B,C=map(int,input().split())
l=[int(input()) for i in range(N)]
inf=10**9
def dfs(cur,a,b,c):
  if cur==N:
    return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf
  ret0 = dfs(cur+1,a,b,c)
  ret1 = dfs(cur+1,a+l[cur],b,c)+10
  ret2 = dfs(cur+1,a,b+l[cur],c)+10
  ret3 = dfs(cur+1,a,b,c+l[cur])+10
  return min(ret0,ret1,ret2,ret3)
print(dfs(0,0,0,0))

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

using namespace std;

using ll = long long;
constexpr ll mod = 998244353;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  // dp[i] := i 回の操作で元に戻るものの個数
  vector<ll> dp(2 * n + 10);
  ll ret = 0;
  for (int k = 2; k <= 2 * n; k++) {
    if (2 * n % k) continue;
    if ((2 * n / k) % 2 == 0) continue;
    string t = s.substr(0, k / 2), t2 = t;
    cerr << k << " " << t << endl;
    bool f = true;
    for (int i = 0; i < k / 2; i++) {
      if (t[i] == '0')
        t2[i] = '1';
      else {
        t2[i] = '0';
        f = false;
      }
    }
    string x = "";
    while (x.size() < n) {
      x += t;
      x += t2;
    }
    x = x.substr(0, n);
    // cerr << k << " " << x << endl;
    if (x <= s) {
      dp[k]++;
    }
    if (!f) {
      ll sum = 0, tmp = 1;
      reverse(t.begin(), t.end());
      for (int i = 0; i < k / 2; i++) {
        if (t[i] == '1') sum = (sum + tmp) % mod;
        tmp = tmp * 2 % mod;
      }
      cerr << k << " " << sum << endl;
      dp[k] = (dp[k] + sum) % mod;
    }
    for (int j = 2; j * j <= k; j++) {
      if (k % j) continue;
      dp[k] = (dp[k] + mod - dp[j]) % mod;
      if (j * j != k) dp[k] = (dp[k] + mod - dp[k / j]) % mod;
    }
    ret += (ll)k * dp[k] % mod;
    ret %= mod;
    cerr << k << " " << dp[k] << endl;
  }
  cout << ret << endl;
}


Measured memory_bytes: 4544
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    ll n;
    cin >> n;
    vector<int> vec;

    for(ll i = 2; i * i <= n; i++) {
        int cnt = 0;
        while(n % i == 0) {
            cnt++;
            n /= i;
        }
        if(cnt) vec.push_back(cnt);
    }
    if(n != 1) vec.push_back(1);

    int ans = 0;
    for(int x : vec) {
        int y = 1;
        while(x >= y) {
            x -= y;
            y++;
        }
        ans += y - 1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
int main()
{
  int a,b,i,j,n,k,x[500][500]; 
  scanf("%d",&k); 
  for(i=0;i<k;i++){
    scanf("%d%d",&a,&n);
    for(j=0;j<n;j++){
      scanf("%d",&b);
      x[a][b]=1;
    }
  }
  for(i=1;i<=k;i++){
    for(j=1;j<=k;j++){
      printf("%d",x[i][j]);
      if(j!=k) printf(" ");
    }
    printf("\n");
  }     
  return 0;
}



Measured memory_bytes: 2056
#include<iostream>
#include<vector>
#include<set>
#include<math.h>
#include<algorithm>
#define pair pairr
const int N=1e5+5;
const long long M=1e10+1;
const long long inf=1e18;
using namespace std;
long long ar[N];
vector<long long> norm,pair,snt;
set<long long> lis;
int main(){
	long long n,i,j,k,l,dem,r,ans=0,ans1=0;
	cin>>n;
	snt.push_back(2);
	lis.insert(4);
	for(i=3;i<N;i+=2){
		bool cac=true;
		for(j=3;j*j<=i;j+=2){
			if(i%j==0){
				cac=false;
				break;
			}
		}
		if(cac){
			snt.push_back(i);
			lis.insert(i*i);
			//cout<<i<<endl;
		}
	}
	for(i=1;i<=n;i++){
		cin>>ar[i];
		k=ar[i];
		dem=0;
		l=1;
		r=1;
		for(j=0;snt[j]*snt[j]*snt[j]<=ar[i];j++){
			if(k%snt[j]==0){
				while(k%snt[j]==0){
					dem++;
					k/=snt[j];
					if(dem>=3){
						dem-=3;
					}
				}
				if(dem==2){
					r*=snt[j];
				}
				if(dem==1){
					r*=snt[j]*snt[j];
				}
				while(dem){
					dem--;
					l*=snt[j];
				}
			}
		}
		l=l*k;
		norm.push_back(l);
		//cout<<l<<" ";
		if(lis.count(k)){
			r*=(long long)(sqrt(k));
			pair.push_back(r);
			//cout<<r<<endl;
		}
		else{
			r*=k;
			if(k<=inf/r){
				r*=k;
				pair.push_back(r);
				//cout<<r<<endl;
			}
			else{
				pair.push_back(inf);
				//cout<<inf<<endl;
			}
		}
	}
	i=0;
	j=0;
	sort(norm.begin(),norm.end());
	sort(pair.begin(),pair.end());
	while(pair[i]==1){
		if(i==0){
			ans++;
		}
		i++;
		j++;
	}
	while(i<n||j<n){
		if(i==n){
			ans1+=n-j;
			break;
		}
		if(j==n){
			ans1+=n-i;
			break;
		}
		l=0;
		k=0;
		if(norm[i]<pair[j]){
			ans1++;
			i++;
			continue;
		}
		else{
			if(norm[i]>pair[j]){
				ans1++;
				j++;
				continue;
			}
		}
		dem=i;
		r=j;
		while(dem<n&&norm[dem]==norm[i]){
			dem++;
		}
		while(r<n&&pair[j]==pair[r]){
			r++;
		}
		ans1+=max(dem-i,r-j);
		i=dem;
		j=r;
	}
	cout<<ans+ans1/2;
}

Measured memory_bytes: 3308
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    deque<char> que;
    for(int i = 0; i < s.size(); i++) {
        que.push_back(s[i]);
    }
    /*
    for(int i = 0;  i< que.size(); i++) {
        cout << que[i];
    }
    cout << endl;
    */
    bool flag = true; //1 f, 2, b;

    for(int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if(t == 1) {
            flag = !flag;
        }
        else if(t == 2) {
            int f;
            char c;
            cin >> f >> c;
            if(f == 1) {
                if(flag == true) {
                    que.push_front(c);
                }
                else {
                    que.push_back(c);
                }
            }
            else if(f == 2) {
                if(flag == false) {
                    que.push_front(c);
                }
                else {
                    que.push_back(c);
                }
            }
        }
    }
    
    if(flag == true) {
        for(int i = 0; i < que.size(); i++) {
            cout << que[i];
        }
    }
    else {
        for(int i = que.size()-1; i > -1; i--) {
            cout << que[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 896
S = input()[::-1]
i = 0
flag = True
while i < len(S):
    if S[i:i+5] == "maerd":
        i += 5
    elif S[i:i+7] == "remaerd":
        i += 7
    elif S[i:i+5] == "esare":
        i += 5
    elif S[i:i+6] == "resare":
        i += 6
    else:
        flag = False
        break

print("YES" if flag else "NO")

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

using namespace std;
int n, k, d;
bool a[100] = {false};

int main(){
  cin >> n >> k;
  cin.ignore();
  int tmp;
  for(int i = 0; i < k; i++){
    cin >> d;
    cin.ignore();
    for(int j = 0; j < d; j++){
      cin >> tmp;
      --tmp;
      a[tmp] = true;
    }
  }
  int cnt = 0;
  for(int i = 0; i < n; i++){
    if(a[i] == false){
      ++cnt;
    }
  }
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
#include<unordered_map>

#include<stdio.h>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

#define PI  3.141592
//----------------------------------------


int main(void)
{
	ll n;
	ll a, b;

	cin >> n >> a >> b;

	ll kaisuu = floor(n / (a + b));

	ll ans = kaisuu * a;

	ll last = n - kaisuu * (a + b);


	ans += min(a, last);

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
int main() {

	int h, r;
	cin >> h >> r;

	if (h + r == 0)cout << "0" << endl;
	if (h + r > 0)cout << "1" << endl;
	if (h + r < 0)cout << "-1" << endl;

}


Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
int MOD=1000000007;
int main() {
	int N,L,sum=0,mi=MOD,mi2=MOD;
	cin >> N >> L;
	for(int i=1; i<=N; i++){
		sum+=i+L-1;
		if(mi2>abs(i+L-1)){
		mi=i+L-1;
		mi2=abs(i+L-1);
		}
		
	}
	cout << sum-mi << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main()
{
    unsigned int n;
    while (scanf("%d", &n),n){
        unsigned int gp = 0;
        for(unsigned int i = 0; i < n; i++){
            unsigned int x;
            scanf("%d", &x);
            gp += x;
        }
        vector<unsigned int> j(n-1);
		
        for (unsigned int i = 0; i < n-1; i++){
            scanf("%d", &j[i]);
        }
         
        sort(j.begin(), j.end());
         
        unsigned int ans = gp * n;
         
        for (unsigned int i = n - 1; i > 0; i--){
			
            gp += j[i - 1];
            ans = max(ans, gp * i);
			
        }
         
        printf("%u\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1304
#include<stdio.h>
int main(){
int n,k,x,y;
scanf("%d",&n);
scanf("%d",&k);
scanf("%d",&x);
scanf("%d",&y);
if(n>k) printf("%d\n",(k*x)+((n-k)*y));
else printf("%d\n",n*x);
return 0;
}


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

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int n;
vector<int> dst;
vector<vector<P> > g;

void dfs(int r){
    for(int i = 0; i < g[r].size(); i++){
        if(dst[g[r][i].second]<0){
            dst[g[r][i].second] = dst[r] + g[r][i].first;
            dfs(g[r][i].second);
        }
    }
}

int tree_diameter(){
    dst.resize(n,-1);
    dst[0]=0;
    dfs(0);
    int p=0,d=-1;
    for(int i = 0; i < n; i++){
        if(dst[i]>d){
            d = dst[i];
            p=i;
        }
    }
    for(int i = 0; i < n; i++){
        dst[i]=-1;
    }
    dst[p]=0;
    dfs(p);
    d=-1;
    for(int i = 0; i < n; i++){
        d = max(d,dst[i]);
    }
    return d;
}
 
 
int main()
{
    cin>>n;
    g.resize(n);
    for(int i = 0; i < n-1; i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        int w = 1;
        g[a].push_back(P(w,b));
        g[b].push_back(P(w,a));
 
    }
 
    cout<<(tree_diameter()%3!=1?"First":"Second") <<endl;
 
    return 0;
}

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

int arr[40][500][500] = {};
int abc[40][3] = {};

int main(void) {

    int n, ma, mb;

    cin >> n >> ma >> mb;

    for (int i = 0; i < n; i++) {
        cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
    }

    for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 500; j++) {
            for (int k = 0; k < 500; k++) {
                arr[i][j][k] = 1000000;
            }
        }
    }


    arr[0][abc[0][0]][abc[0][1]] = abc[0][2];

    for (int i = 1; i < n; i++) {
        arr[i][abc[i][0]][abc[i][1]] = min(arr[i][abc[i][0]][abc[i][1]],abc[i][2]);
        for (int j = 450; j >= 0; j--) {
            for (int k = 450; k >= 0; k--) {
                arr[i][j][k] = min(arr[i - 1][j][k],arr[i][j][k]);
                if (arr[i - 1][j][k] != 1000000) {
                    arr[i][j + abc[i][0]][k + abc[i][1]] =
                        min(
                            arr[i - 1][j][k] + abc[i][2],
                            arr[i][j + abc[i][0]][k + abc[i][1]]
                            );
                }
            }
        }
    }


    int res = 1000000;
    for (int i = 1; ma*i < 500 && mb*i < 500; i++) {
        //cout << arr[n - 1][i*ma][i*mb] << endl;
        res = min(res, arr[n - 1][i*ma][i*mb]);
    }

    if(res == 1000000)
    cout << -1 << endl;
    else
    cout << res << endl;


}



Measured memory_bytes: 39296
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,c=0,max=0;
string s;
cin>>n>>s;
for(int i=0;i<n;i++){
	if(s[i]=='I')
	{
		c++;
	}
	else{
		c--;
	}
	if(max<c){
		max=c;
	}
}
cout<<max;
}

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

int main()
{
    int n,m,k;
    int ans=0;
    scanf("%d%d",&n,&m);
    k=m;
    int a[100005];
    int u,v;
    memset(a,0,sizeof(a));
    while(m--)
        {
            scanf("%d%d",&u,&v);
            a[u]++;
            a[v+1]--;
        }
        for(int i=1; i<=n; i++)
            a[i]=a[i]+a[i-1];
        for(int i=1; i<=n; i++)
        {
            if(a[i]==k)
                ans++;
        }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 4108
N,A,B=map(int, input().split())
x = []
for i in range(1,N+1):
  s=i%10+(i//10)%10+(i//100)%10+(i//1000)%10+(i//10000)%10
  if A<=s<=B:
    x.append(i)
print(sum(x))

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

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a.at(i);
  
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  
  int cnt = 1;
  for (int i = 1; i < n; i++) {
    if (a.at(i) != a.at(i - 1))
      cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include "iostream"

using namespace std;
void mondai1();

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

void mondai1() {
	int aTob, bToc,fare;
	cin >> aTob >> bToc;
	
	fare = aTob + bToc/2;

	cout << fare;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <map>
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 n;
    cin >> n;
    vector<ll>t(n),a(n);
    rep(i,n){
        cin >> t[i] >> a[i];
    }
    ll c=t[0],d=a[0];
    rep(i,n){
        if(c<=t[i]&&d<=a[i]){
            c = t[i];
            d = a[i];
            //cout << c <<" " << d << endl;
            
        }else{
            ll m = max((t[i]+c-1)/t[i],(a[i]+d-1)/a[i]);
            //cout << m << endl;
            c = t[i]*m;
            d = a[i]*m;
            //cout << c << " " << d << endl;
        }
        
    }
    cout << c + d << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int X = sc.nextInt();
		int T = sc.nextInt();

		if(N%X==0) {
			System.out.println((N/X)*T);
		} else {
			System.out.println((N/X+1)*T);
		}
	}
}

Measured memory_bytes: 35652
n = gets.to_i
data = []
n.times do
    data << gets.to_i
end

sum = data.inject(0) { |a, d| a + d }
filtered = data.reject { |d| d % 10 === 0 }

if sum % 10 != 0
    puts sum
elsif filtered.size === 0
    puts 0
else
    puts sum - filtered.min
end

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,TT;
ll T[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>TT;
	ll ret=0;
	ll ma=0;
	FOR(i,N) {
		cin>>T[i];
		
		if(ma<=T[i]) {
			ret+=TT;
		}
		else {
			ret+=T[i]+TT-ma;
		}
		ma=T[i]+TT;
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line


const int mod = 1e9+7;
int main()
{
	int N;
	cin >> N;
	vector<int> t(N), a(N);
	rep(i,N) cin >> t[i];
	rep(i,N) cin >> a[i];

	vector<P> left(N);
	vector<P> right(N);
	int m = 0;
	map<int,int> rock;
	rep(i,N){
		int l, r;
		if(t[i] > m){
			l = r = t[i];
			m = t[i];
			rock[i] = m;
		} else {
			l = 1;
			r = m;
		}
		left[i] = P(l,r);
	}
	m = 0;
	for(int i = N-1; i>=0; i--){
		int l, r;
		if(a[i] > m){
			l = r = a[i];
			m = a[i];
			rock[i] = m;
		} else {
			l = 1;
			r = m;
		}
		right[i] = P(l,r);
	}
	ll ans = 1;
	rep(i,N){
		// 山が確定しているときに、矛盾している記録があったらダメ
		if(rock[i]){
			if(left[i].second < rock[i] || right[i].second < rock[i]){
				//debug(rock[i]);
				cout << 0 << endl;
				return 0;
			}
		}
		int l = max(left[i].first,right[i].first);
		int r = min(left[i].second, right[i].second);
		ans *= (r-l + 1);
		ans %= mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 7296
from sys import stdin
N = 8
FREE = -1
NOT_FREE = 1
row = [FREE] * N
col = [FREE] * N
dpos = [FREE] * (2 * N - 1)
dneg = [FREE] * (2 * N - 1)
X = [[False] * N for _ in range(N)]
n = int(stdin.readline())
for _ in range(0, n):
    r, c = map(int, stdin.readline().split())
    X[r][c] = True
def printBoard():
    for i in range(0, N):
        for j in range(0, N):
            if X[i][j] != 0 and row[i] != j: return
    for i in range(0, N):
        print("." * row[i] + "Q" + "." * (8 - row[i] - 1))
def recursive(i):
    if i == N:
        printBoard()
        return
    for j in range(0, N):
        if (NOT_FREE == col[j] or
            NOT_FREE == dpos[i + j] or
            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
recursive(0)

Measured memory_bytes: 7796
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
const int maxn = 1<<17;
const int mod = 1e9+7;
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
int coutt[4][2]= {{0,1},{1,0},{-1,0},{0,-1}};
ll a[100000];
ll f(ll x,ll y,ll z)
{
    return x*x+y*y+z*z+x*y+y*z+x*z;
}
int main()
{

    int n;
    scanf("%d",&n);
    for(int i=1;i<=100;i++)
    {
        for(int j=1;j<=100;j++)
        {
            for(int k=1;k<=100;k++)
            {
                a[f(i,j,k)]++;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        printf("%lld\n",a[i]);
    }
 	return 0;
}


Measured memory_bytes: 4288
N = int(input())
*A, = map(int, input().split())

INF = 10**18
S = [0]*(N+1)
for i in range(N):
    S[i+1] = S[i] + A[i]
dp = [[0]*(N+1) for i in range(N+1)]
for k in range(2, N+1):
    for i in range(N-k+1):
        dp[i][k] = min(dp[i][j] + dp[i+j][k-j] for j in range(1, k)) + S[i+k] - S[i]
print(dp[0][N])


Measured memory_bytes: 43612
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	long long n = 0,m = 0;

	while(cin >> n >> m)
	{
		ostringstream p;
		string pp;
		p << n + m;

		pp = p.str();
		cout << pp.size() << endl;
	}
}



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

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

    ll N, Q;
    cin >> N >> Q;
    vector<tuple<ll, bool, ll>> events;
    for (ll i = 0; i < N; i++) {
        ll S, T, X;
        cin >> S >> T >> X;
        events.emplace_back(S - X, true, X); // 通行止め期間に入る
        events.emplace_back(T - X, false, X); // 通行止め期間が終わる
    }

    sort(begin(events), end(events), [](auto&& a, auto&& b) { return get<0>(a) < get<0>(b); });

    multiset<ll> closed;
    auto it_s = begin(events);

    for (ll i = 0; i < Q; i++) {
        ll D;
        cin >> D;
        while (it_s != end(events) && get<0>(*it_s) <= D) {
            ll x;
            bool insert;
            tie(ignore, insert, x) = *it_s;
            if (insert) {
                closed.insert(x);
            } else {
                // 必ず存在しなければおかしいのでfindの戻り値チェックは不要
                closed.erase(closed.find(x));
            }
            it_s++;
        }
        if (closed.empty()) {
            cout << -1 << "\n";
        } else {
            cout << *begin(closed) << "\n";
        }
    }
}


Measured memory_bytes: 21224
#include <bits/stdc++.h>
#define N 4010
using namespace std;

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
struct edge
{
	int v,next;
}vs[N<<1];
int n,A[N],ee,st[N],F[N];
inline void addedge(int u,int v)
{
	vs[++ee].v=v;vs[ee].next=st[u];st[u]=ee;
}
inline void dfs(int rt,int pr)
{
	for(int i=st[rt];i;i=vs[i].next)
	{
		if(vs[i].v==pr) continue;
		dfs(vs[i].v,rt);
		if(A[vs[i].v]<A[rt]&&!F[vs[i].v])
			F[rt]=1;
	}
}
int main()
{
	n=read(); for(int i=1;i<=n;i++)
		A[i]=read();
	for(int i=1;i<n;i++)
	{
		int u=read(), v=read();
		addedge(u,v); addedge(v,u);
	}
	for(int i=1;i<=n;i++)
	{
		memset(F,0,sizeof F);
		dfs(i,0); 
		if(F[i]) printf("%d ",i);
	}
	puts("");
	return 0;
}

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

int map[110][110],dp[110][110];

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=2;i++){
        for(int j=1;j<=n;j++){
            cin>>map[i][j];
        }
    }
    for(int i=1;i<=2;i++){
        for(int j=1;j<=n;j++){
            dp[i][j]=max(dp[i][j-1],dp[i-1][j])+map[i][j];
        }
    }
    printf("%d",dp[2][n]);
    return 0;
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long
#define mp make_pair
#define r0 return 0

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;
const int dxl[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dyl[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dxs[4] = {1, 0, -1, 0};
const int dys[4] = {0, 1, 0, -1};

/* main */
signed main(void)
{
    char in;
    cin >> in;
    switch (in)
    {
    case 'A':
        cout << 'T' << endl;
        break;
    case 'C':
        cout << 'G' << endl;
        break;
    case 'G':
        cout << 'C' << endl;
        break;
    case 'T':
        cout << 'A' << endl;
        break;
    default:
        break;
    }
    return 0;
}

Measured memory_bytes: 256
/*
	Author: Kuldeep
	Date Time: 11/07/20 18:55
	Description: https://atcoder.jp/contests/aising2020/tasks/aising2020_b
*/
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<ctype.h>

typedef long long ll;
#define Min(a,b) (((a)<(b))?(a):(b))
#define Max(a,b) (((a)>(b))?(a):(b))

int main()
{
	int count = 0, size, temp;
	scanf("%d",&size);
	for(int i= 1; i<=size; i++)
	{
		scanf("%d",&temp);
		if(i%2 != 0 && temp %2 != 0)
			count++;	
	}
	printf("%d\n",count);	
		
	return 0;
}


Measured memory_bytes: 1712
A,B,C,K = (int(x) for x in input().split())

score = 0

if K < A:
    score = K

else:
    score = A
    K = K - A
    if K > 0 and K < B:
        score = score
    elif K > 0 and K >= B:
        score = score
        K = K - B
        
        if K > 0:
            score = score - K

print(score)

Measured memory_bytes: 9132
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int[] data = new int[N];
		for (int i = 0; i < N; i++) {
			data[i] = scn.nextInt();
		}
		show(data);
		for (int j = 1; j < N; j++) {
			int v = data[j];
			int w = j - 1;
			while (w >= 0 && data[w] > v) {
				data[w + 1] = data[w];
				w--;
			}
			data[w + 1] = v;
			show(data);
		}

	}

	static void show(int[] pdata) {
		StringBuffer stb = new StringBuffer();
		stb.append(pdata[0]);
		for (int a = 1; a < pdata.length; a++) {
			stb.append(" " + pdata[a]);
		}
		System.out.println(stb.toString());
	}
}



Measured memory_bytes: 30240
N, K = map(int, input().split())
ans = 0
b = K+1
while b <= N:
  p = N//b
  r = N%b
  ans += p*max(0,b-K)+max(0, r-K+1)-(0 if K > 0 else 1)
  b += 1
print(ans)

Measured memory_bytes: 39536
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
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; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

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

    ll N, A, B;
    cin >> N >> A >> B;
    ll ct = 0, f = 0;
    string S;
    cin >> S;
    rep(i, len(S)){
        if(S[i] == 'c'){
            print("No");
            continue;
        }
        if(S[i] == 'a'){
            if(ct < A + B) print("Yes"), ++ct;
            else print("No");
        }
        else{
            if(ct < A + B and f < B) print("Yes"), ++ct, ++f;
            else print("No");
        }
    }

    return 0;
}

Measured memory_bytes: 848
def main():
    abck = [int(_x) for _x in input().split()]
    a = abck[0]
    b = abck[1]
    c = abck[2]
    k = abck[3]

    kk = k

    total = 0
    if kk >= a:
        kk = kk - a
        total += a
    else:
        print(kk)
        return

    if kk >= b:
        kk = kk - b
    else:
        print(total)
        return

    total = total - kk
    print(total)


main()


Measured memory_bytes: 9052
#include "bits/stdc++.h"
#define   LF      '\n'
#define   ALL(x)  x.begin(), x.end()
#define   iostreamBooster()  do{cin.tie(nullptr);ios::sync_with_stdio(false);}while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f'3f3f3f3fLL;


signed main()
{
  string s;
  cin >> s;
  int len = s.length();

  int ans = INF;

  for (int i = 0; i < len; ++i) {
    string t = s.substr(i, 3);

    //cout << t << endl;
    if ((int)t.length() != 3) continue;

    chmin(ans, abs(stoi(t) - 753));
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = 0, b = 0, c = 0,d = 0;
        for(int i = 1; i <= n; i++) {
            String x = in.next();
            if(x.equals("AC")) a++;
            if(x.equals("TLE")) c++;
            if(x.equals("WA")) b++;
            if(x.equals("RE")) d++;
        }
        System.out.println("AC x " + a);
        System.out.println("WA x " + b);
        System.out.println("TLE x " + c);
        System.out.println("RE x " + d);
        in.close();
    }
}

Measured memory_bytes: 58716
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int n, k;
  cin >> n;
  while(n--){
    vector<int> p, q;
    int u=0, v=0;
    cin >> k;
    for(int i=0; i<8; i++){
      p.push_back(k%10);
      k/=10;
    }
    sort(p.begin(),p.end());
    q.resize(8);
    for(int i=0; i<8; i++)
      q[7-i] = p[i];
    int sep = 1;
    for(int i=0; i<8; i++){
      u+= sep*p[i];
      v+= sep*q[i];
      sep*=10;
    }
    cout << u-v << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
def solve():
    opponent = input()
    p_amt = len(opponent) // 2
    me = "p" * p_amt + "g" * (len(opponent) - p_amt)

    ans = 0
    for i in range(len(opponent)):
        if opponent[i] == "g" and me[i] == "p":
            ans += 1
        
        if opponent[i] == "p" and me[i] == "g":
            ans -= 1
    
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 68036
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>  
#include<cstdio>  
#include<fstream>  
#include<iomanip>
#include<algorithm>  
#include<cmath>  
#include<deque>  
#include<vector>  
#include<assert.h>
#include<bitset>
#include<queue>  
#include<string>  
#include<cstring>  
#include<map>  
#include<stack>  
#include<set>
#include<functional>
#define pii pair<int, int>
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define eps 0.00000001
#define mst(a,i) memset(a,i,sizeof(a))
#define all(n) n.begin(),n.end()
#define lson(x) ((x<<1))  
#define rson(x) ((x<<1)|1) 
#define inf 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int r, c;
class T {
public:
	int mode, v, ope;
	bool operator<(const T&a)
	{
		return v < a.v;
	}
};
int getnum(int x, int y)
{
	if (y == 0)
		return x;
	else if (x == 0)
		return r + r + c + c - y;
	else if (x == c)
		return x + y;
	else if (y == r)
		return r + c + c - x;
	else return -1;
}

vector<T>a;
stack<int>sve;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int i, j, k, m, n;
	int x1, x2, y1, y2;
	cin >> r >> c >> n;
	int tempa, tempb;
	for (int i = 1; i <= n; ++i)
	{
		cin >> y1 >> x1 >> y2 >> x2;
		tempa = getnum(x1, y1);
		tempb = getnum(x2, y2);
		if (tempb == -1 || tempa == -1)continue;
		if (tempb < tempa)swap(tempa, tempb);
		a.push_back({ 1,tempa,tempb });
		a.push_back({ 2,tempb,tempa });
	}
	sort(all(a));
	for (int i = 0; i < a.size(); ++i)
	{
		if (a[i].mode == 1)
			sve.push(a[i].ope);
		else if (sve.top() == a[i].v)
				sve.pop();
		else
		{
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

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

using namespace std;

int main () {
  int N,L;
  cin >> N >> L;
  vector<string> vec(N);
  
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
   for(int i = 0; i < N; i++){
    cout << vec.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
#ifdef GCC
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#endif
 
#define log(x) cout << (x) << "\n"
#define loop(i, begin, end)for(__typeof(end) i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define rep(i, n) loop(i, 0, n)
 
using ll = long long;
using vll = vector<ll>;
 
int n;
vll a;
 
ll dp[100001][2];
int main() {
    cin >> n;
    a = vll(n+1, 0);
    rep (i, n) cin >> a[i];
 
  	
    dp[n][0]=0, dp[n][1]=0;
 
    for (int i=n-1; i>=0; --i) {
        for (int inc=0; inc<=1; ++inc) {
            if (i==n-1 and !inc) dp[i][0] = 0;
            else if (inc) dp[i][inc] = max((i!=n-1)?-a[i]-a[i+1]+dp[i+1][0]:a[i], a[i]+dp[i+1][1]);
            else dp[i][inc] = max(dp[i+1][1], 2*a[i]-a[i+1]+dp[i+1][0]);
        }
    }
 
    log(dp[0][1]);
}

Measured memory_bytes: 2560
#include<cstdio>
using namespace std;

int n,a[100001],b[100001];
long long ans=0;

int main() {
	int i;
	scanf("%d",&n);
	for(i=0;i<n;i++) {
		scanf("%d%d",a+i,b+i);
	}
	for(i=n-1;i>=0;i--) {
		int t=(a[i]+ans)%b[i];
		if(t!=0) ans+=(b[i]-(a[i]+ans)%b[i]);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
#define WHITE 1
#define GRAY 2
#define BLACK 3

void dfs(void);
void visit(int);

int n ,t;
int V[102][102], d[102], f[102], color[102];

int main(){
  int i, j, k, l, m;
  scanf("%d", &n);
  for(i = 1 ; i <= n ; i++){
    scanf("%d %d", &j, &k);
    for(l = 1 ; l <= k ; l++){
      scanf("%d", &m);
      V[j][m] = 1;
    }
  }
  dfs();
  for(i = 1 ; i <= n ; i++){
    printf("%d %d %d\n", i, d[i], f[i]);
  }
  return 0;
}

void dfs(void){
  int u;
  for(u = 1 ; u <= n ; u++) color[u] = WHITE;
  t = 0;
  for(u = 1 ; u <= n ; u++) if(color[u] == WHITE) visit(u);
}

void visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++t;
  for(v = 1 ; v <= n ; v++){
    if(color[v] == WHITE && V[u][v] == 1) visit(v);
  }
  color[u] = BLACK;
  f[u] = ++t;
}



Measured memory_bytes: 2104
#include<iostream>
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;


int main() {
    char c ;
  
  for(int i=0;i<9;i++){
    cin >> c ;
    if(i==0 || i==4 || i==8)
      cout << c ;
  }

  cout << endl ;
	return 0;
}



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

int main(){
    int n;
    long long a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    long long k = d - c;
    for(int i=0; i<=n-1; i++){
        long long j = n - 1 - i;
        long long e = b - (a + c*(i-j));
        if(-k*j <= e && e <= k*i){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

bool check(ll n, ll b) {
    if (b == 0) return false;
    return n / b == n % b;
}

int main() {

    ll n;
    cin >> n;
    ll ans = 0;
    for (ll x = 1; x * x <= n; x++) {
        if (n % x == 0) {
//            if (check(n, x - 1)) ans += x - 1;
            if (check(n, (n / x) - 1)) ans += (n / x) - 1;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,t = inpl()
wv = [None] * n
for i in range(n):
    a,b = inpl()
    wv[i] = (a,b)
rwv = wv[::-1]
udp = [[0] * t for _ in range(n)]
ddp = [[0] * t for _ in range(n)]

for i in range(n-1):
    w,v = wv[i]
    for j in range(t):
        if j < w:
            udp[i+1][j] = udp[i][j]
        else:
            udp[i+1][j] = max(udp[i][j], udp[i][j-w] + v)
res = udp[n-1][t-1] + wv[n-1][1]

for i in range(n-1):
    w,v = rwv[i]
    for j in range(t):
        if j < w:
            ddp[i+1][j] = ddp[i][j]
        else:
            ddp[i+1][j] = max(ddp[i][j], ddp[i][j-w] + v)
    res = max(res,ddp[n-1][t-1] + wv[0][1])
# print(res)
for i in range(1,n-1):
    u = i; d = n-i-1
    mx = 0
    for j in range(t):
        tmp = udp[u][j] + ddp[d][t-1-j]
        mx = max(mx, tmp)
    res = max(res, mx + wv[i][1])
print(res)

Measured memory_bytes: 187768
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a,b;
    vector<pair<ll,ll> > v;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        v.pb(make_pair(b,a));
    }
    ll num=0;
    bool ans=true;
    sort(be(v));
    for(int i=0;i<n;i++){
        num+=v[i].second;
        if(num>v[i].first){
            ans=false;
        }
    }
    cout <<((ans)?"Yes":"No")<<endl;
    return 0;
}


Measured memory_bytes: 6384
def function1(m, set1):
  set2 = set(str(m))
  if len(set1 & set2) > 0:
    return False
  else:
    return True
def function(n, set1):
  m = n
  while not function1(m, set1):
    m += 1
  return m

line1 = input().split()
n = int(line1[0])
k = int(line1[1])
list1 = input().split()
set1 = set(list1)

print(function(n, set1))

Measured memory_bytes: 3064