akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
bool P[101][101][101]; // X, Y, 1;
struct e {
    int from, to, cost;
};

struct edge {int to; ll cost;};
struct node {int pos; ll cost;};
bool operator < (const node &a, const node &b){
    return a.cost > b.cost;
}

vector<ll> dijkstra(vector<vector<edge>> &G, int root){
    vector<ll> ret(G.size(), inf);
    priority_queue<node> pq;
    pq.push({root, 0});
    while (!pq.empty()) {
        node t = pq.top();
        pq.pop();
        
        if (ret[t.pos] == inf) ret[t.pos] = t.cost;
        else continue;
        
        for (edge e : G[t.pos]) {
            pq.push({e.to, t.cost + e.cost});
        }
    }
    return ret;
}


const int N = 100;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int A, B;
    cin >> A >> B;
    vector<vector<int>> D(A, vector<int> (B));
    rep(i, A) rep(j, B) cin >> D[i][j];
    rep(i, N) rep(j, N) rep(k, 101) P[i][j][k] = 1;
    rep(i, N) rep(j, N) rep(k, 101){
        rep(a, A) rep(b, B){
            if(D[a][b] > (a + 1) * i + (b + 1) * j + k) P[i][j][k] = 0;
        }
    }
    
    vector<e> ret;
    rep(i, N) rep(j, N){
        rep(k, 101) {
            if(P[i][j][k]){
                ret.pb({i, N * 2 + 1 - j, k});
                break;
            }
        }
    }
    
    rep(a, A) rep(b, B){
        vector<vector<edge>> G(N * 2 + 2);
        rep(i, N) G[i].pb({i + 1, a + 1});
        rep(i, N) G[i + N + 1].pb({i + N + 2, b + 1});
        for(auto e: ret) {
            G[e.from].pb({e.to, e.cost});
        }
        
        auto dist = dijkstra(G, 0);
        if(dist[N * 2 + 1] != D[a][b]){
            output("Impossible");
            return 0;
        }
    }
    cout << "Possible" << endl;
    cout << N * 2 + 2 << " " << N * 2 + (int)ret.size() << endl;
    
    rep(i, N){
        cout << i + 1 << " " << i + 2 << " " << "X" << endl;
    }
    rep(i, N){
        cout << i + N + 2 << " " << i + N + 3 << " " << "Y" << endl;
    }
    
    for(auto e: ret) {
        cout << e.from + 1 << " " << e.to + 1 << " " << e.cost << endl;
    }
    cout << 1 << " " << N * 2 + 2 << endl;
    
    return 0;
}


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

dp = [[0]*3  for _ in range(N)]

a, b, c = [0]*N, [0]*N, [0]*N
for i in range(N):
    a[i], b[i], c[i] = map(int, input().split())

dp[0] = [a[0], b[0], c[0]]

for i in range(N-1):
    dp[i+1][0] = max(dp[i][1]+ a[i+1], dp[i][2] + a[i+1])
    dp[i+1][1] = max(dp[i][0]+ b[i+1], dp[i][2] + b[i+1])
    dp[i+1][2] = max(dp[i][0]+ c[i+1], dp[i][1] + c[i+1])
print(max(dp[N-1])) 

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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int H, W, K;
  cin >> H >> W >> K;

  vector<vector<char>> c(H, vector<char>(W));
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      cin >> c[i][j];
    }
  }


  int ans = 0;

  for(int x = 0; x < (1 << H); ++x) {
    for(int y = 0; y < (1 << W); ++y) {
      int cnt = 0;
      for(int i = 0; i < H; ++i) {
        for(int j = 0; j < W; ++j) {
          if(!((x >> i) & 1) && !((y >> j) & 1) && c[i][j] == '#') {
            cnt++;
          }
        }
      }
      if(cnt == K) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int check(int a)
{
    int b=0;
    while(a>0)
    {
        b*=10;
        b+=(a%10);
        a/=10;
    }
    return b;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int a,b,c=0;
    cin>>a>>b;
    for(int i=a; i<=b; i++)
    {
        if(i==check(i))
            c++;
    }
    cout<<c<<endl;

    return 0;
}


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

int main() {
	int n;cin>>n;
	string s;cin>>s;
	if(s.length()<=n){cout<<s;}
	else{
		string s1=s.substr(0,n);
		cout<<s1<<"...";
	}
	
	return 0;
}

Measured memory_bytes: 3612
N, M = map(int, input().split())
P = list(map(int, input().split()))


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)


UF = UnionFind(N)
for i in range(M):
    x, y = map(int, input().split())
    x, y = x - 1, y - 1
    UF.union(x, y)

ans = 0
for i, p in enumerate(P):
    ans += UF.same(i, p - 1)

print(ans)


Measured memory_bytes: 14008
#include <iostream>
#include <vector> 
using namespace std;
int main(void){
    vector<int> vec;
    int l;
    while(1){
        cin >>l;
        if(l==0){
            break;
        }
        vec.push_back(l);
    }
    for (int i=0; i<vec.size(); i++){
        cout << "Case " << i+1 <<": "<< vec[i] <<endl;
    }
}


Measured memory_bytes: 3232
n = int(input())

L = list(map(int,input().split()))
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if L[j] == L[i]:
            continue
        for k in range(j+1,n):
            if L[k] == L[i] or L[k] == L[j]:
                continue
            if L[i] + L[j] > L[k] and L[i] + L[k] > L[j] and L[j] + L[k] > L[i]:
                ans += 1

print(ans)

Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}




int dp[(int)1e5];
bool flag[(int)(1e5)];
vector<vector<int>> xy;
int f(int x){
  if(flag[x])return dp[x];
  flag[x] = true;
  int fans = 0;
  for(int y : xy[x])chmax(fans,f(y)+1);
  return dp[x]=fans;
}

// TODO: write
int main() {
  int h,w;cin>>h>>w;
  vector<string> a(h);rep(i,h)cin>>a[i];
  vector<vector<ll>> dp(h,vector<ll>(w,0));
  dp[0][0] = 1;

  rep(i,h){
    rep(j,w){
      if(a[i][j] == '#')continue;
      if(i-1 >= 0)dp[i][j] += dp[i-1][j];
      if(j-1 >= 0)dp[i][j] += dp[i][j-1];
      dp[i][j] %= INF;
    }
  }
  print(dp[h-1][w-1]);
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<bool>a(1001,false);
  a.at(1)=true;
  rep2(i,2,n){
    int co=i*i;
    while(co<1001){
      a.at(co)=true;
      co*=i;
    }
  }
  for(int i=n;i>0;i--){
    if(a.at(i)){
      cout<<i<<endl;
      break;
    }
  }
}

Measured memory_bytes: 256
//Subhash Suman
//Date: 14/02/19 ; Day: Thursday ; Time: 06::51::10 
//Description : 

#include<bits/stdc++.h>
#define ll long long int
#define MAX INT_MAX
#define MIN INT_MIN
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>

using namespace std;
const int N = 1e5 + 5;
int arr[101];
bool dp[N];

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }
    dp[0] = 0;
    for(int i = 1; i <= k; i++){
        bool b = 0;
        for(int j = 0; j < n; j++){
            if(i-arr[j]>=0){
                if(dp[i-arr[j]]==0){
                    b = 1;
                    break;
                }
            }
        }
        dp[i] = b;
    } 
    if(dp[k]){
        cout<<"First\n";
    }
    else{
        cout<<"Second\n";
    }
    return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.math.*;

public class Main {

    public static void main(String[] args) {
        //AtCoder Beginner Contest 052
        //d
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        double a = Double.parseDouble(sc.next());
        double b = Double.parseDouble(sc.next());
        double[] twn = new double[n];
        double[] dist = new double[n];
        double ans =  0;
        for(int i = 0; i < n; i++){
            twn[i] = Integer.parseInt(sc.next());
        }
        for(int i = 0; i < n-1; i++){
            dist[i] = Math.min((twn[i+1]-twn[i])*a, b);
            ans +=dist[i];
        }
        System.out.println(String.format("%.0f",ans));
    }
}

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

int main() {
	for (;;) {
		int m, f, r;
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) {
			break;
		}
		int rate = m + f;
		if (m == -1 || f == -1) {
			cout << "F" << endl;
		}
		else if (rate >= 80) {
			cout << "A" << endl;
		}
		else if (rate >= 65) {
			cout << "B" << endl;
		}
		else if (rate >= 50) {
			cout << "C" << endl;
		}
		else if (rate >= 30) {
			if (r >= 50) {
				cout << "C" << endl;
			}
			else {
				cout << "D" << endl;
			}
		}
		else {
			cout << "F" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3108
import sys
import heapq
from collections import deque

# sys.setrecursionlimit(100001)
INF = sys.maxsize


# ===CODE===
def main():
    v, e = map(int, input().split())
    dist_mat = [[INF if i != j else 0 for i in range(v)] for j in range(v)]

    for i in range(e):
        s, t, d = map(int, input().split())
        dist_mat[s][t] = d

    negative = False
    for k in range(v):
        for i in range(v):
            for j in range(v):
                dist_mat[i][j] = min(dist_mat[i][j],
                                     dist_mat[i][k] + dist_mat[k][j] if dist_mat[i][k] < INF and dist_mat[k][
                                         j] < INF else INF)
                if i == j and dist_mat[i][j]<0:
                    negative = True
                    print("NEGATIVE CYCLE")
                    exit(0)

    for d in dist_mat:
        for i in range(v):
            if d[i] == INF:
                d[i] = "INF"
        print(*d, sep=" ")


if __name__ == '__main__':
    main()



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

using namespace std;

#define long long long
#define INF 1e18
#define MOD (long) (998244353)

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

    vector<long> a(n);
    for (auto &x : a) cin >> x;
    sort(a.begin(), a.end(), greater<long>());

    long ans = 0;
    long prev = a[0];
    long k = 0;
    bool first = false;
    for (long i = 1; i < n; i++) {
        if (i == 1) {
            ans += a[k];
            k++;
        } else {
            ans += a[k];
            if (first) {
                k++;
                first = false;
            } else {
                first = true;
            }
        }
    }
    printf("%lld\n", ans);
}


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

using namespace std;

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

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

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

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

int n,m,e,s,t,r;
vi graph[110];


int a[8],b[8],c[8];

int dist[110][110][1<<8];

typedef tuple<int,int,int,int> state;

int dijkstra(){
	rep(i,110)rep(j,110)rep(k,1<<8) dist[i][j][k]=inf;
	dist[s][0][0]=0;
	state init(0,s,0,0);
	priority_queue<state,vector<state>,greater<state>>q;
	q.push(init);
	while(!q.empty()){
		state cur=q.top();q.pop();
		int cost,v,num,mask;
		tie(cost,v,num,mask)=cur;
		rep(i,e) if(c[i]==v) mask|=(1<<i);

		if(dist[v][num][mask]<cost) continue;

		if(num<r){
			for(auto &i:graph[v]){
				if(dist[i][num+1][mask]>cost+1){
					dist[i][num+1][mask]=cost+1;
					state in(cost+1,i,num+1,mask);
					q.push(in);
				}
			}
			rep(i,e) if(mask&(1<<i)){
				if(v==a[i]&&dist[b[i]][num+1][mask]>cost+1){
					dist[b[i]][num+1][mask]=cost+1;
					state in(cost+1,b[i],num+1,mask);
					q.push(in);
				}
				if(v==b[i]&&dist[a[i]][num+1][mask]>cost+1){
					dist[a[i]][num+1][mask]=cost+1;
					state in(cost+1,a[i],num+1,mask);
					q.push(in);
				}
			}
		}
		if(dist[s][0][mask]>cost+1){
			dist[s][0][mask]=cost+1;
			state in(cost+1,s,0,mask);
			q.push(in);
		}
	}
	int ans=inf;
	rep(i,r+1)rep(k,1<<e) ans=min(ans,dist[t][i][k]);
	return ans;
}

int main(void){
	cin >> n >> m >> e >> s >> t >> r;
	rep(i,m){
		int aa,bb;
		cin >> aa >> bb;
		graph[aa].pb(bb);
		graph[bb].pb(aa);
	}
	rep(i,e) cin >> a[i] >> b[i] >> c[i];
	int ans=dijkstra();
	if(ans==inf)
		cout << -1 << endl;
	else
		cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15280
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
    public static Node root;

    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for(int i = 0; i < n; i++){
            String[] input = br.readLine().split(" ");
            if(input.length == 2){
                insert(Integer.parseInt(input[1]));
            }else{
                inorder(root);
                System.out.println("");
                preorder(root);
                System.out.println("");
            }
        }
    }

    public static void insert(int key){
        Node x_parent = null;
        Node x = root;
        Node z = new Node(key);

        while(x != null){//x???null????????????????????????????????????????????????                  
            x_parent = x;
            if(z.key < x.key){
                x = x.left;
            }else{
                x = x.right;
            }
        }
        z.parent = x_parent;
//?????????????????\                                                              
        if(x_parent == null){
            root = z;
        }else{
            if(z.key < x_parent.key){
                x_parent.left = z;
            }else{
                x_parent.right = z;
            }
        }
    }

    public static void inorder(Node node){
        if(node == null)return;
        inorder(node.left);
        System.out.print(" " + node.key);
        inorder(node.right);
    }

    public static void preorder(Node node){
        if(node == null)return;
        System.out.print(" " + node.key);
        preorder(node.left);
        preorder(node.right);
    }


}

class Node{
    int key;
    Node right, left, parent;

    Node(int key){
        this.key = key;
        this.right = null; this.left = null; this.parent = null;
    }
}

Measured memory_bytes: 139352
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<vector>
#include<map>

const int INF = (int)1 << 20;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;




int main(){
    int h, w;
    cin >> h >> w;
    vector<string> map(h);
    for (int i = 0; i < h; i++)
    {
        cin >> map[i];
    }
    int maxv = -INF;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if(map[i][j]=='#')
                continue;

            P p(i, j);

            vector<vector<int>> dist(h, vector<int>(w, INF));
            queue<P> q;
            q.push(p);
            dist[p.first][p.second] = 0;
            P u;
            while (!q.empty())
            {
                u = q.front();//q.front()
                q.pop();
                for (int dir = 0; dir < 4; dir++)
                {
                    int ni = u.first + di[dir];
                    int nj = u.second + dj[dir];
                    if (ni < 0 || h <= ni || nj < 0 || w <= nj)
                        continue;
                    if(map[ni][nj]=='#')
                        continue;
                    if(dist[ni][nj] != INF)
                        continue;
                    dist[ni][nj] = dist[u.first][u.second] + 1;
                    q.push(P(ni, nj));
                }
            }
            for (int si = 0; si < h; si++)
            {
                for (int sj = 0; sj < w; sj++)
                {
                    if(dist[si][sj]==INF)
                        continue;
                    maxv = max(dist[si][sj], maxv);
                }
            }
            

        }
        
    }
    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#define MAX 100000
#define INFTY 1<<30 // 2^30
using namespace std;
typedef long long llong;

static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c)
{
  stack<int> S;
  S.push(r);
  color[r] = c;
  while(!S.empty())
  {
    int u = S.top(); S.pop();
    for(int i = 0; i < G[u].size(); i++)
    {
      int v = G[u][i];
      if(color[v] == NIL)
      {
        color[v] = c;
        S.push(v);
      }
    }
  }
}

void assingColor()
{
  int id = 1;
  for(int i = 0; i < n; i++) color[i] = NIL;
  for(int u = 0; u < n; u++)
    if(color[u] == NIL) dfs(u,id++);
}

int main()
{
  int s, t, m ,q;
  cin >> n >> m;
  for(int i = 0; i < m; i++)
  {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assingColor();

  cin >> q;
  for(int i = 0; i < q; i++)
  {
    cin >> s >> t;
    cout << ((color[s] == color[t]) ? "yes" : "no") << endl;
  }
  return 0;
}

Measured memory_bytes: 7060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll a,b;
  cin>>a>>b;
  cout<<a*b;
}


Measured memory_bytes: 3636
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <cstdlib>
#include <unordered_map>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.0000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define SECOND_MOD 1000000009
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
using namespace std;
int grid[400][400] = {};
int main() {
	long long ans = 0;
	int n;
	cin >> n;
	vector<string> s;
	REP(i, n) {
		string a;
		cin >> a;
		s.push_back(a);
	}
	for (int i = 0; i < n; ++i) {
		for (int q = 0; q < n; ++q) {
			for (int j = 0; j < n; ++j) {
				grid[(q + i) % n][j] = s[q][j] - 'a';
			}
		}
		long long failed = 0;
		for (int q = 0; q < n; ++q) {
			for (int j = 0; j < n; ++j) {
				if (grid[q][j] != grid[j][q]) {
					failed = 1;
					break;
				}
			}
			if (failed == 1) break;
		}
		if (failed == 0) {
			ans += n;
		}
	}
	cout << ans << endl;
	return 0;
}

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

struct Edge{int u,v;long long cost;};

int n,m,s,t;
vector<vector<pair<int,long long>>> graph_yen(111111);
vector<vector<pair<int,long long>>> graph_snuuk(111111);
vector<long long> yen(111111,99999999999999999LL);
vector<long long> snuuk(111111,99999999999999999LL);
vector<pair<long long,int>> cost_sum(111111);

void Dijkstra_yen(){
	vector<bool> done(n,false);
	vector<bool> in_que(n,false);
	priority_queue<int> que;
	yen[s]=0;
	que.push(s);
	in_que[s]=true;
	
	while(!que.empty()){
		int f=que.top();
		que.pop();
		in_que[f]=false;
		done[f]=true;
		for(auto e:graph_yen[f]){
			int to;long long cost;
			tie(to,cost)=e;
			cost+=yen[f];
			if(yen[to]>cost){
				yen[to]=cost;
				if(!in_que[to])que.push(to);
			}
		}
	}
}

void Dijkstra_snuuk(){
	vector<bool> done(n,false);
	vector<bool> in_que(n,false);
	priority_queue<int> que;
	snuuk[t]=0;
	que.push(t);
	in_que[t]=true;
	
	while(!que.empty()){
		int f=que.top();
		que.pop();
		in_que[f]=false;
		done[f]=true;
		for(auto e:graph_snuuk[f]){
			int to;long long cost;
			tie(to,cost)=e;
			cost+=snuuk[f];
			if(snuuk[to]>cost){
				snuuk[to]=cost;
				if(!in_que[to])que.push(to);
			}
		}
	}
}

int main(){
	cin >> n >> m >> s >> t;
	s--;
	t--;
	for(int i=0;i<m;i++){
		int u,v;
		long long a,b;
		cin >> u >> v >> a >> b;
		u--;
		v--;
		graph_yen[u].push_back(make_pair(v,a));
		graph_yen[v].push_back(make_pair(u,a));
		graph_snuuk[u].push_back(make_pair(v,b));
		graph_snuuk[v].push_back(make_pair(u,b));
	}
	
	Dijkstra_yen();
	Dijkstra_snuuk();
	
	for(int i=0;i<n;i++)cost_sum[i]=make_pair(yen[i]+snuuk[i],i);
	sort(cost_sum.begin(),cost_sum.begin()+n);
	int pos=0;
	for(int i=0;i<n;i++){
		while(cost_sum[pos].second<i)pos++;
		cout << 1000000000000000LL-cost_sum[pos].first << endl;
	}
	//for(int i=0;i<n;i++)printf("%lld %lld\n",yen[i],snuuk[i]);
	return 0;
}

Measured memory_bytes: 21700
from itertools import*
s,k=open(0)
k=int(k)
g=[len(list(v))for _,v in groupby(s)]
print(sum(c//2for c in g)*k+(g[0]*g[-2]%2*s[0]==s[-2])*~-k//2**(len(s)-1==g[0]))

Measured memory_bytes: 3188
#include <stdio.h>

int selectionSort(int A[],int N){
  int i,minj,c=0,j,t;
  for(i=0;i<N;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj])minj=j;
    }
    t=A[i];
    A[i]=A[minj];
    A[minj]=t;
    if(i!=minj)c++;
  }
  return c;
}

int main(){
  int A[100],N,c,i;

  scanf("%d",&N);
  while(N<1||N>100){
    scanf("%d",&N);
  }

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

  c=selectionSort(A,N);

  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  
  printf("\n%d\n",c);

  return 0;
}



Measured memory_bytes: 2084
#include <iostream>
#include <vector>

int main() {
  int N, L;
  std::cin >> N >> L;

  const int taste_zero_index = 1 - L;
  const int taste_sum = (L + L + N - 1) * N / 2; // 20, 0, -1065

  int answer = 0;
  if (taste_zero_index < 1) {
    answer = taste_sum - (L + 1 - 1);
  } else if (taste_zero_index > N) {
    answer = taste_sum - (L + N - 1);
  } else {
    answer = taste_sum;
  }

  std::cout << answer << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include <set>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,m,n) for(int i=m;i<n;i++)
#define endre getchar(); getchar();return 0;
#define pie 3.141592653589793
#define INF 1000000007
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int a[25][25], b[25];
signed main() {
	int n, m, c,ans=0;
	cin >> n >> m >> c;
	rep(i, m) {
		cin >> b[i];
	}
	rep(i, n) {
		rep(j, m) {
			cin >> a[i][j];
		}
	}
	rep(i, n) {
		int sum = 0;
		rep(j, m) {
			sum += a[i][j] * b[j];
		}
		if (sum + c > 0)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=2000100,mod=1e9+7;
inline int read(){
    int x=0,c=getchar(),f=0;
    for(;c>'9'||c<'0';f=c=='-',c=getchar());
    for(;c>='0'&&c<='9';c=getchar())
    x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
void write(ll x){
    if(x>9)write(x/10);
    putchar(x%10+'0');
}char s[N];
int m,i,a,b,ans,n,x,sm[N],pri[N],j,k,v[N];
int main(){
	for(i=2;i<=1000;i++){
		if(!v[i])pri[++m]=i;
		for(j=1;j<=m;j++){
			k=i*pri[j];
			if(k>1000)break;
			v[k]=1;if(i%pri[j]==0)break;
		}
	}
	scanf("%d",&n);x=1;
	for(i=1;i<=n;i++){
		k=i;
		for(j=1;k>1&&j<=m;j++){
			while(k%pri[j]==0)
			sm[j]++,k/=pri[j];
		}
	}
	for(i=1;i<=m;i++){
		x=1ll*x*(sm[i]+1)%mod;
	}
	printf("%d\n",x);
	return 0;
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll INF = (1LL<<60);

int main(){

    ll n; cin >> n;
    string s, t;
    cin >> s >> t;

    string ans = "";
    rep(i, n){
        ans += s[i];
        ans += t[i];
    }

    cout << ans << endl;

    return 0;
}

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

int ans[100005];
string s;

void left(int x){
  
  int idx = x;
  int begin = idx;
  
  while(1){
    idx--;
    if( idx < 0 ) break;
    if( s[idx] == 'L' ) break;
    begin = idx;
  }
  
  idx = x;
  
  while(begin<=idx){
    ans[x]++;
    idx-=2;
  }
  
  idx = x-1;
  
  while(begin<=idx){
    ans[x+1]++;
    idx-=2;
  }
  
}

void right(int x){

  int idx = x;
  int end = idx;
  
  while(1){
    idx++;
    if( (int)s.size() <= idx ) break;
    if( s[idx] == 'R' ) break;
    end = idx;
  }
  
  idx = x;
  
  while(idx<=end){
    ans[x]++;
    idx+=2;
  }
  
  idx = x+1;
  
  while(idx<=end){
    ans[x-1]++;
    idx+=2;
  }
  
}

signed main(){
  
  cin>>s;
  
  for(int i=0;i<(int)s.size()-1;i++){
    
    if( !( s[i] == 'R' && s[i+1] == 'L' ) ) continue;
    
    left( i );
    
    right( i + 1 );
    
  }
  
  for(int i=0;i<(int)s.size();i++){
    if( i ) cout<<' ';
    cout<<ans[i];
  }
  
  cout<<endl;
  
  return 0;
}


Measured memory_bytes: 1408
try:
    while True:
        a: list = sorted(map(int, input().split(",")))

        if a.count(a[0]) == 4 or a.count(a[1]) == 4:
            print("four card")
        elif len(set(a)) == 2:
            print("full house")
        elif (a[0]+4 == a[1]+3 == a[2]+2 == a[3]+1 == a[4] or
              a == [1, 10, 11, 12, 13]):
            print("straight")
        elif max(a.count(a[0]), a.count(a[1]), a.count(a[2])) == 3:
            print("three card")
        elif len(set(a)) == 3:
            print("two pair")
        elif len(set(a)) == 4:
            print("one pair")
        else:
            print("null")

except EOFError:
    exit()


Measured memory_bytes: 5596
$s = <STDIN>;
my ($N,$X,$Y) = split(/ /,$s);

my @data;
for(my$i=1;$i<$N;$i++){
  $data[$i] = 0;
}
for($i=1;$i<$N;$i++){
  for($j=($i+1);$j<=$N;$j++){
    $dist = $j-$i;
    $A  = abs($X- $i) +abs($Y-$j) +1;
    if($A <$dist ){
      $dist = $A;
    }
    $data[$dist]++;
  }
}

for(my$i=1;$i<$N;$i++){
  print "$data[$i]\n";
}


Measured memory_bytes: 640
import math
K = int(input())
A,B = map(int,input().split())

if K == 1:
    print("OK")
    exit()
if A%K==0:
    print("OK")
    exit()

x = math.floor(A/K)
y = math.floor(B/K)

if y-x > 0:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 9012
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    bool ok=1;
    for(int i=n-1;i;i--)
    {
        if(a[i-1]-a[i]>=2)
        {
            ok=0;
            break;
        }
        else if(a[i-1]-a[i]==1)
            a[i-1]--;
    }
    char ans[10][10]={"No","Yes"};
    printf("%s",ans[ok]);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  vector<ll> H(N);
  rep(i,N) cin >> H[i];
  sort(H.begin(), H.end(), greater<ll>());
  ll ans = 0;
  for(ll i=K; i<N; ++i) {
    ans += H[i];
  }
  cout << ans;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

#define double long double

const int INF=1001001001;
const int INFLL=1001001001001001001ll;
const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int dy[4]={-1,0,1,0};
int dx[4]={0,-1,0,1};

int H,W;
char fld[555][555];
double E[555][555];
bool check(double e){
    queue<pint>que;
    fill_n(*E,555*555,1e14);
    rep(i,H)rep(j,W)if(fld[i][j]=='g'){
        E[i][j]=0;
        que.push({i,j});
    }
    bool flag=false;
    while(true){
        if(que.size()==0){
            if(flag)break;
            rep(i,H)rep(j,W)if(fld[i][j]=='*'){
                E[i][j]=e;
                que.push({i,j});
            }
            flag=true;
            continue;
        }
        int y,x;
        tie(y,x)=que.front();
        que.pop();

        if(E[y][x]+1>=e&&!flag){
            rep(i,H)rep(j,W)if(fld[i][j]=='*'){
                E[i][j]=e;
                que.push({i,j});
            }
            flag=true;
        }

        rep(d,4){
            int ny=y+dy[d],nx=x+dx[d];
            if(fld[ny][nx]=='#'||fld[ny][nx]=='*')continue;

            if(E[ny][nx]!=1e14)continue;
            E[ny][nx]=E[y][x]+1;
            que.push({ny,nx});
        }
    }

    double sum=0;
    int cnt=0;
    rep(i,H)rep(j,W){
        if(fld[i][j]=='#'||fld[i][j]=='*'||fld[i][j]=='g')continue;
        cnt++;sum+=E[i][j];
    }

    return sum<=e*cnt;
}


signed main(){
    cin>>W>>H;
    rep(i,H)cin>>fld[i];

    vector<vint>dist(H,vint(W,INT_MAX));
    queue<pint>que;
    rep(i,H)rep(j,W)if(fld[i][j]=='s'){
        dist[i][j]=0;
        que.push({i,j});
    }
    bool flag=false;
    while(que.size()){
        int y,x;
        tie(y,x)=que.front();
        que.pop();
        rep(d,4){
            int ny=y+dy[d],nx=x+dx[d];
            if(fld[ny][nx]=='#'||dist[ny][nx]!=INT_MAX)continue;
            if(fld[ny][nx]=='*')flag=true;
            dist[ny][nx]=dist[y][x]+1;
            que.push({ny,nx});
        }
    }

    if(!flag){
        rep(i,H)rep(j,W)if(fld[i][j]=='g'){
            printf("%.20Lf\n",(double)dist[i][j]);
            return 0;
        }
    }

    double lb=0,ub=1e12;
    rep(i,70){
        double mid=(ub+lb)/2;
        if(check(mid))ub=mid;
        else lb=mid;
    }

    rep(i,H)rep(j,W){
        if(fld[i][j]=='s'){
            printf("%.20Lf\n",E[i][j]);
        }
    }
    return 0;
}

Measured memory_bytes: 10360
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	sc.Scan()
	s := strings.Split(sc.Text(), " ")
	D, _ := strconv.Atoi(s[0])
	N, _ := strconv.Atoi(s[1])
	a := 0
	switch D {
	case 0:
		if N != 100 {
			a = N
		}else{
			a = N+1
		}
	case 1:
		if N != 100 {
			a = N * 100
		}else{
			a = (N+1) * 100
		}
	case 2:
		if N != 100 {
			a = N * (100 * 100)
		}else{
			a = (N+1) * (100 * 100)
		}

	}
	fmt.Print(a)
}

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

using namespace std;

#define int long long

void knapsack_01(int n,int W,vector<pair<int,int>>v)
{
    int m[n+1][W+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=W;j++)
        {
            if(i==0||j==0)
                m[i][j]=0;
            else if(v[i-1].first>j)
                m[i][j]=m[i-1][j];
            else
                m[i][j]=max(m[i-1][j],v[i-1].second+m[i-1][j-v[i-1].first]);
        }
    }
    cout<<m[n][W]<<endl;
}

int32_t main()
{
    int n,W;
    cin>>n>>W;
    vector<pair<int,int>>v;
    for(int i=0;i<n;i++){
        int w,a;
        cin>>w>>a;
        v.push_back({w,a});
    }
    knapsack_01(n,W,v);
}


Measured memory_bytes: 79104
#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 main()
{
    int n;
    cin>>n;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin>>h[i];
    }
    int ans=1;
    int ma=h[0];
    for(int i = 1; i < n; i++){
        if(ma<=h[i])ans++;
        ma = max(ma,h[i]);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   1e9 +7  ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
    string s , t ;
    cin >> s >> t ;
    for( int i = 0 ; i < s.size() ; i++){
        if(s[i]!=t[i]){
            cout << "No";
            return;
        }
    }
    cout << "Yes";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
   // cin >> t ;
    while(t--){
        solve( );
    }
}



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

void main_()
{
    ll N;
    cin >> N;

    map<ll, ll> as;
    for (ll i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        as[a]++;
    }

    // すべての数字が0
    if (as.size() == 1 && as.count(0) > 0) {
        cout << "Yes\n";
        return;
    }

    // 数字が2種の場合、0、x、x、0、x、x…の並びであればOK
    if (as.size() == 2 && as.count(0) > 0 && N % 3 == 0) {
        auto zero_count = begin(as)->second;
        auto x_count = next(begin(as), 1)->second;
        if (zero_count == N / 3 && x_count == 2 * N / 3) {
            cout << "Yes\n";
            return;
        }
    }

    // 数字が3種の場合、x ^ y ^ z = 0でx,y,z,x,y,z…の並びであればOK
    if (as.size() == 3 && N % 3 == 0) {
        auto x_it = begin(as);
        auto y_it = next(x_it);
        auto z_it = next(y_it);
        if (x_it->second == N / 3 && y_it->second == N / 3 && z_it->second == N / 3
            && (x_it->first ^ y_it->first ^ z_it->first) == 0) {
            cout << "Yes\n";
            return;
        }
    }

    cout << "No\n";
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

ll d[310][310];
ll e[310][310];
int V;

void warshall_floyd(){
    rep(k,V){
        rep(i,V){
            rep(j,V)chmin(d[i][j],d[i][k]+d[k][j]);
        }
    }
}
void warshall_floyd2(){
    rep(k,V){
        rep(i,V){
            rep(j,V)chmin(e[i][j],e[i][k]+e[k][j]);
        }
    }
}

int main() {
    int n,m,l;
    cin >> n >> m >> l;
    V=n;
    rep(i,n){
        rep(j,n){
            if(i==j)d[i][j]=0;
            else d[i][j]=INF;
        }
    }
    rep(i,m){
        int x,y,z;
        cin >> x >> y >> z;
        d[x-1][y-1]=z;
        d[y-1][x-1]=z;
    }
    warshall_floyd();
    rep(i,n){
        rep(j,n){
            if(d[i][j]>l)e[i][j]=INF;
            else e[i][j]=1;
        }
    }
    warshall_floyd2();
    int q;
    cin >> q;
    rep(Q,q){
        int s,t;
        cin >> s >> t;
        if(e[s-1][t-1]>=INF)cout << -1 << endl;
        else cout << e[s-1][t-1]-1 << endl;
    }

}

/*



 */



Measured memory_bytes: 2048
Q = int(input())
AB = [list(map(int,input().split())) for i in range(Q)]

for i in range(Q):
    a,b = AB[i]
    C = int((a*b)**0.5)
    if C*C == a*b:
        ans = 2*(C-1)
        if min(a,b) < C:
            ans -= 1
    elif C*(C+1) >= a*b:
        ans = 2*C - 2
    else:
        ans = 2*C - 1
    
    print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
int main(){
  long long int A,B,X;
  cin>>X>>A>>B;
  string ans="delicious";
  long long int det=B-A;
  if(det>0){
    ans="safe";
    if(det>X)ans="dangerous";
  }
  cout<<ans<<endl;
  }


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

using namespace std;

struct Node
{
	Node* parent;
	Node* left;
	Node* right;
};

Node*  make_tree(Node* t, int* n, string s)
{
	if (s.empty())
		return NULL;

	int paren = 0;
	int i;
	for (i = 1; paren != 0 || s[i] != ','; ++i)
	{
		if (s[i] == '(')
			++paren;
		else if (s[i] == ')')
			--paren;
	}

	int curN = (*n)++;
	t[curN].left = make_tree(t, n, s.substr(1, i-1));
	t[curN].right = make_tree(t, n, s.substr(i+1, s.size()-2-i));

	return t + curN;
}

void print_intersection(Node* a, Node* b)
{
	if (a == NULL || b == NULL)
		return;
	putchar('(');
	print_intersection(a->left, b->left);
	putchar(',');
	print_intersection(a->right, b->right);
	putchar(')');
}
void print_union(Node* a, Node* b)
{
	if (a == NULL && b == NULL)
		return;
	putchar('(');
	print_union(a ? a->left : NULL, b ? b->left : NULL);
	putchar(',');
	print_union(a ? a->right : NULL, b ?  b->right : NULL);
	putchar(')');
}

int main()
{
	char ope;
	string a, b;
	while (cin >> ope >> a >> b)
	{
		const int TreeSize = 128;
		Node treeA[TreeSize], treeB[TreeSize];
		memset(treeA, 0, sizeof(treeA));
		memset(treeB, 0, sizeof(treeB));

		int n = 0;
		Node* first =	make_tree(treeA, &n, a);
		n = 0;
		Node* second = make_tree(treeB, &n, b);

		if (ope == 'u')
			print_union(first, second);
		else
			print_intersection(first, second);
		printf("\n");

	}

	return 0;
}

Measured memory_bytes: 0
#include "iostream"
#include "math.h"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
using namespace std;

int main() {
	int height[100005], n;
	cin >> n;
	int max = 0, cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> height[i];
	}
	for (int i = 0; i < n-1; i++) {
		if (height[i] >= height[i + 1]) {
			cnt++;
		}
		else {
			cnt = 0;
		}
		if (cnt > max)max = cnt;
	}
	cout << max << endl;
}

Measured memory_bytes: 640
while gets
  s,a=$_.chomp,""
  f=0
  s.each_char do |c|
    if f==-1 then f=c.to_i
    elsif f>0 then f.times{a<<c};f=0
    elsif c=="@" then f=-1
    else a<<c
    end
  end
  puts a
end

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

struct Student
{
    int num;
    int a;
};

bool cmp(const Student &s1, const Student &s2){
    return s1.a < s2.a;
}

int main() {
    int N;
    vector<Student> students;
    cin >> N;
    for(int i = 0; i < N; i++){
        int tmp;
        cin >> tmp;
        Student s = {i, tmp};
        students.push_back(s);
    }
    sort(students.begin(), students.end(), cmp);
    for(int i = 0; i < N; i++) {
        cout << students[i].num + 1<< ' ';
    }
    cout << endl;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N, M;
    cin >> N >> M;
    vector<tuple<int, int, int>> v(M);
    REP(i, M) {
        int p, y;
        cin >> p >> y;
        v[i] = make_tuple(i, p, y);
    }
    sort(ALL(v), [](auto x, auto y){return get<1>(x) != get<1>(y) ? get<1>(x) < get<1>(y) : get<2>(x) < get<2>(y);});
    map<int, int> dic;
    REP(i, M) {
        int f, s, t;
        tie(f, s, t) = v[i];
        dic[s] += 1;
        v[i] = make_tuple(f, s, dic[s]);
    }
    sort(ALL(v));
    REP(i, M) {
        int s, t;
        tie(ignore, s, t) = v[i];
        printf("%06d", s);
        printf("%06d\n", t);
    }
    return 0;
}



Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        if(x % 2 == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3180
K,A,B = list(map(int, input().strip().split(' ')))

if B-A >= 3 and K >= A+2-1:
  bis = B
  K = K-(A+2-1)
  rem = K%2
  bis = bis + (B-A)*(K//2) + rem

else:
  bis = 1+K

print(bis)

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

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

    string s;
    cin >> s;
    int k,f;
    for(int i = 0; i < s.size(); i++)
        if(s[i] == 'A'){
            k=i;
            break;
        }
    for(int i = s.size()-1; i >=0; i--)
        if(s[i] == 'Z'){
            f=i;
            break;
        }
    cout << f - k + 1;
}
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


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

int main(void)
{
	int n,a[300000],i,j,x;
	long long sum;
	scanf("%d",&n);
	for(i=0;i<3*n;i++)	scanf("%d",&a[i]);
	sort(a,a+3*n);
	sum=0;	x=3*n-2;
	for(i=0;i<n;i++)	{
		sum+=a[x];
		x=x-2;
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 1280
n, k = map(int, input().split())
a_list = []
for i in range(n):
	a, b = map(int, input().split())
	a_list.append([a, b])
a_list.sort(key=lambda x: x[0])
for i in range(n):
	k -= a_list[i][1]
	if k <= 0:
		print(a_list[i][0])
		break


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

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

    vector<int> t(N);
    for (int i = 0; i < N; i++){
        t[i] = i + 1;
    }

    int count = 0;
    for (int i = 0; i < N; i++){
        if (p[i] != t[i]){
            count ++;
        }
    }

    string ans = "NO";
    if (count == 0 || count == 2){
        ans = "YES";
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(int i=n;i<N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf = 1e9+7;

int a, b;
int main() {
    cin>>a>>b;
    if(a>b){
        p(a-1);
    }else{
        p(a);
    }
    return 0;
}

Measured memory_bytes: 256
n,x = map(int,input().split())
l = list(map(int,input().split()))
l=sorted(l)

ans=0
for i in range(n-1):
    if l[i] <= x:
        x-=l[i]
        ans+=1
else:
    if l[-1]==x:
        ans+=1

print(ans)

Measured memory_bytes: 9128
#include <iostream>
#include <vector>
#include <string>
#include <sstream>

int main(){
    int n;
    std::cin >> n;
    int list[n][n] = {};
    std::vector<std::vector<int>> vertex;
    int tmp2;
    int num;
    for(int i=0;i<n;i++){
        std::vector<int> tmp;
        std::cin >> tmp2;
        std::cin >> num;
        for(int j=0;j<num;j++){
            std::cin >> tmp2;
            tmp.push_back(tmp2);
        }
        vertex.push_back(tmp);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<vertex[i].size();j++){
            if(vertex[i][j] > 0){
                list[i][vertex[i][j]-1] = 1;
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            std::cout << list[i][j];
            if(j!=n-1){
                std::cout << " ";
            }
        }
        std::cout << "\n";
    }
}



Measured memory_bytes: 3160