akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	ll x;
	cin >> x;
	ll res = -1;
	if (x == 1) {
		cout << 1 << endl;
		return 0;
	}
	vector<ll> ex(x + 1);
	for (ll i = 2; i <= sqrt(x); i++) {
		ll tmp = i*i;
		while (tmp<=x) {
			ex[tmp] = 1;
			tmp *= i;
		}
	}
	for (ll i = x; i >= 1; i--) {
		if (ex[i]) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>

void trace(int A[],int N);
void insertionSort(int A[],int N);

int main(){
  int N,i,j;
  int A[1000];

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

  trace(A,N);
  insertionSort(A,N);
  }
  else{ return 0;}
  return 0;
}

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

void insertionSort(int A[],int N){
  int j,i,v;
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    trace(A,N);
  }
}



Measured memory_bytes: 2064
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  int mul4 = 0, mul2 = 0, mul1 = 0;
  for(int i=0; i<N; i++){
    int in;
    cin >> in;
    if(in % 4 == 0) mul4++;
    else if(in % 2 == 0) mul2++;
    else mul1++;
  }

  if((N + 1) / 2 < mul1){
    cout << "No" << endl;
  } else if(N % 2 == 1 && (N + 1) / 2 == mul1){
    if(mul4 >= mul1 - 1)
      cout << "Yes" << endl;
  } else if(mul4 >= mul1){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        Integer[] arr = { a, b, c };
        Arrays.sort(arr, Comparator.reverseOrder());

        int ans = Integer.parseInt(String.valueOf(arr[0]) + String.valueOf(arr[1])) + arr[2];
        System.out.println(ans);
    }

}



Measured memory_bytes: 21716
#include <stdio.h>

int main(){
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		if(x == 0 && y == 0) break;
		if(x < y){
			printf("%d %d\n",x,y);
		}else if(x > y){
			printf("%d %d\n",y,x);
		}else{
			printf("%d %d\n",x,y);
		}
	}
	return 0;
}

Measured memory_bytes: 600
N = int(input())
X = list(map(int, input().split()))

Xs = sorted(X)
median1 = Xs[int(N/2)-1]
median2 = Xs[int(N/2)]

for i in range(N):
    if X[i] >= median2:
        print(median1)
    else:
        print(median2)

Measured memory_bytes: 26016
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

vector<ll> prime;

void setPrime(ll x) {
    for (ll i=2; i<=x; i++) {
        bool ok = true;
        for (ll e: prime) {
            if (i%e==0) {
                ok = false;
                break;
            }
            if (e*e>i) {
                break;
            }
        }
        if (ok) prime.push_back(i);
    }
}

const int NMAX = 1000005;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    setPrime(NMAX);
    vi a(n);

    rep(i, n) cin >> a[i];
    int total = a[0];
    rep(i, n) {
        total = __gcd(total, a[i]);
    }
    if (total!=1) {
        cout << "not coprime" << endl;
        return 0;
    }
    vector<bool> v(NMAX);
    bool ok = true;
    rep(i, n) {
        int now = a[i];
        for (int e: prime) {
            if (e*e>now) {
                if (now>1) {
                    if (v[now]) {
                        ok = false;
                        break;
                    }
                    v[now] = true;
                }
                break;
            }
            if (now%e==0) {
                while (now%e==0) {
                    now /= e;
                }
                if (v[e]) {
                    ok = false;
                    break;
                }
                v[e] = true;
            }
            
        }
        
        if (!ok) break;
    }
    if (ok) cout << "pairwise coprime" << endl;
    else cout << "setwise coprime" << endl;
    return 0;
}


Measured memory_bytes: 7944
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i = 0; i , (n); ++i)
using ll = long long;
using namespace std;
int sum(int n) {
    if (n == 0) {
        return 0;
    }

    int s = sum(n - 1);
    return (s + n);
}
//int kaizyou(ll k) {
    //ll sum = 1;
    //for (int i = 1; i <= k; ++i)
    //{
      //  sum *= i;
      //  sum %= 1000000007;
    //}
    //return sum;
//}
int main() {
    string A;
    cin >> A;
    cout << A;
    reverse(A.begin(), A.end());
    if (A[0] == 's') {
        cout << "es";
    }
    else {
        cout << 's';
    }
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cmath>
#include <climits>
#include <algorithm>
using namespace std;

class Point {
public:
    double x, y;
    Point (double x = 0, double y = 0) : x(x), y(y) { }
    Point operator + (Point p) { return  Point(x + p.x, y + p.y); }
    Point operator - (Point p) { return  Point(x - p.x, y - p.y); }
    Point operator * (double a) { return  Point(a * x, a * y); }
    Point operator / (double a) { return  Point (x / a, y / a); }
};

struct Segment {
    Point p1, p2;
};

double dot(Point a, Point b) {
    return a.x * b.x + a.y * b.y;
}

double norm(Point a) {
    return a.x * a.x + a.y * a.y;
}

int main()
{
    Segment s;
    double x1, y1, x2, y2, xq, yq, r;
    int q;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    s.p1 = Point(x1, y1);
    s.p2 = Point(x2, y2);
    Point base = s.p2 - s.p1;
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%lf %lf", &xq, &yq);
        Point p = Point(xq, yq);
        r = dot(p - s.p1, base) / norm(base);
        Point res = s.p1 + base * r;
        printf("%.10lf %.10lf\n", res.x, res.y);

    }
    return 0;
}


Measured memory_bytes: 2756
from sys import stdin

def main():
  N, M = map(int, stdin.readline().rstrip().split())
  beforeA=-1
  Mlist=[]

  for i in range(M):
    a = int(stdin.readline().rstrip())
    if (a-beforeA)==1:
      print("0")
      exit()
    Mlist.append(a)
    beforeA = a
      
  if N == 1 or (N == 2 and M==1):
    print("1")
    exit()
  if N == 2:
    print("2")
    exit()

  Mindex=0
  broken=-2
  if len(Mlist) >0:
    broken = Mlist[Mindex]
  an2=0
  an1=1
  patern=1
  brokenNext=False
  for i in range(1,N+1):
    if broken == i:
      Mindex+=1
      if len(Mlist) > Mindex:
        broken = Mlist[Mindex]
      brokenNext=True
      continue
    if brokenNext:
      brokenNext=False
      an2=0
      continue
    patern=(an1+an2)%1000000007
    an2=an1
    an1=patern
    #print("{}: {}".format(i,patern))
  print(patern%1000000007 )

main()


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

int main() {
    int H,W;
    cin >> H >> W;
    vector<vector<char>> s(H+2,vector<char>(W+2,'.'));
    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            cin >> s[i][j];
        }
    }
    
    bool ok = true;

    for(int i=1;i<H+1;i++){
        for(int j=1;j<W+1;j++){
            if(s[i][j]=='#'){
                if(s[i-1][j]=='.'&&s[i+1][j]=='.'&&s[i][j-1]=='.'&&s[i][j+1]=='.') ok = false;
            }
        }
    }
    
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import floor

a, b = map(int, readline().split())
for i in range(100000):
    if floor(i * 0.08) == a and floor(i * 0.1) == b:
        print(i)
        exit()
print(-1)


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);

int i=1;

while(true){
int x = sc.nextInt();
if(x==0){break;}
System.out.println("Case "+ i + ": "+x);
i=i+1;

}

}
}

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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string X;
    cin >> X;
    int count = X.size();
    for(int i = 0;i < X.size()-1;i++){
        if(X.at(i) == 'S' && X.at(i+1) == 'T'){
//            cout << i << " and " << i+1 << " is ST!" << endl;
            X.at(i) = '#';
            X.at(i+1) = '#';
            count -= 2;
            for(int j = 1;true;j++){
                if(i - j < 0){
                    break;
                }
                if(X.at(i - j) == '#'){
                    continue;
                }
                for(int k = 1;true;k++){
//                    cout << "J = " << j << endl;
                    if(i + k + 1 >= X.size() || i - j < 0){
                        break;
                    }
                    if(i + k + 1 == '#'){
                        continue;
                    }
//                    cout << "K = " << k << endl;
                    if(X.at(i - j) == 'S' && X.at(i+k+1) == 'T'){
//                        cout << i-j << " and " << i+k+1 << " is ST!" << endl;
                        X.at(i - j) = '#';
                        X.at(i + k + 1) = '#';
                        count -= 2;
                        while(true){
                            j++;
                            if(i - j >= 0 && X.at(i-j) == '#'){
                                continue;
                            }
                            else{
                                break;
                            }
                        }
                        continue;
                    }
                    break;
                }
                break;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 720
use std::io::*;
fn main() {
	let a = read();
	let mut count_b = 0;
	if a < 105 {
		println!("0");
	} else if a == 105 {
		println!("1");
	} else {
		for c in 105..a + 1{
			let mut count_a = 1;
			for d in 1..(c / 2) + 1 {
				if c % d == 0 {
					count_a += 1;
				}
			}
			if count_a == 8 && c % 2 == 1 {
				count_b += 1;
			}
		}
		println!("{}", count_b);
	}
}

fn read() -> usize{
    let s = stdin();
    let b = s.bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    b.parse().ok().unwrap()
}


Measured memory_bytes: 4352
import sys
input=sys.stdin.readline
def main():
  n,m=map(int,input().split())
  p=list(map(int,input().split()))
  xy=[list(map(int,input().split())) for i in range(m)]
  class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

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

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)
  uf=UnionFind(n)
  for i in range(m):
    uf.union(p[xy[i][0]-1]-1,p[xy[i][1]-1]-1)
  ans=0
  for i in range(n):
    if uf.same(i,p[i]-1):
      ans+=1
  print(ans)
if __name__=='__main__':
  main()


Measured memory_bytes: 33660
#include<iostream>
#include<climits>
#include<cstring>
#define inf 1e18
using namespace std;
long long int a[401];
long long int dp[404][404];
long long int sum(int i,int k)
{  long long int sum=0;
	for(int s=i;s<=k;s++)
	    {
		   sum=(sum+a[s]);
	       // sum=sum%100;
	    }
	   return sum;
}
long long int mixture(int i,int j)
{ if(i>=j)
   return 0;
   if(dp[i][j]!=-1)
   return dp[i][j];
   
   dp[i][j]=inf;
   for(int k=i;k<=j;k++)
     dp[i][j]=min(dp[i][j],mixture(i,k)+mixture(k+1,j)+sum(i,k)+sum(k+1,j));
     return dp[i][j];
	
	
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	  cin>>a[i];
	memset(dp,-1,sizeof(dp));
	  cout<<mixture(0,n-1);
	
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
using ll=int_fast64_t;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    using i64=int_fast64_t;
    i64 a;
    static constexpr i64 MOD=998244353;
    modint(){a=0;}
    modint(i64 a_){
        a=a_%MOD;
        if(a<0) a+=MOD;
    }
    modint inv()const{
        i64 n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y;
        y.a=a+x.a;
        if(y.a>MOD) y.a-=MOD;
        return y;
    }
    modint operator-(const modint& x){
        modint y;
        y.a=a-x.a;
        if(y.a<0) y.a+=MOD;
        return y;
    }
    modint operator*(const modint& x){
        modint y;
        y.a=(a*x.a)%MOD;
        return y;
    }
    modint operator/(const modint& x){
        modint y;
        y.a=(a*x.inv().a)%MOD;
        return y;
    }
    modint& operator+=(const modint& x){
        a+=x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint& operator-=(const modint& x){
        a-=x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    modint& operator*=(const modint& x){
        (a*=x.a)%=MOD;
        return *this;
    }
    modint& operator/=(const modint& x){
        (a*=x.inv().a)%=MOD;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    int_fast64_t a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(int_fast64_t a,int_fast64_t b){
    modint _;
    int_fast64_t n=1,A=a;
    while(b){
        if(b&1) (n*=A)%=modint::MOD;
        (A*=A)%=modint::MOD;
        b>>=1;
    }
    _.a=n;
    return _;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,d;
    in>>n;
    vector<int> v(n);
    in>>d;
    if(d) return cout<<0<<endl,0;
    ++v[d]
;    fr(i,n-1){
        in>>d;
        ++v[d];
    }
    if(v[0]>1) return cout<<0<<endl,0;
    modint ans{1};
    bool f=true;
    fr(i,n-1){
        if(v[i]==0&&v[i+1]) return cout<<0<<endl,0;
        if(f){
            if(v[i]==0){
                f=false;
                continue;
            }
            ans*=pwr(v[i],v[i+1]);
        }
        if(!f&&v[i+1]) return cout<<0<<endl,0;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,p,tmp,j=0;
  cin >> N >> M;
  vector<int> num(N,-1);
  for(int i=0;i<M;i++) {
    cin >> p >> tmp;
    if(num.at(p-1)==-1||num.at(p-1)==tmp) {
      num.at(p-1)=tmp;
    } else{
      j--;
    }
  }  
  if(N!=1&&num.at(0)==0||j<0){
    cout << -1 << endl;
  } else {
    for(int i=0;i<N;i++) {
      if(N!=1&&i==0&&num.at(i)==-1) cout << 1;
      else if(num.at(i)==-1) cout << 0;
      else cout << num.at(i);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = 5
s = []
lastS = []
for i in range(n):
    s.append(raw_input())
    lastS.append(int(s[i][-1]))

# 1の位が0でなく最も少ないメニューを探す
min = 9
minMenu = 0
for i in range(n):
    if lastS[i] < min and lastS[i] != 0:
        minMenu = i
        min = lastS[i]

# 時間を計算する
ans = 0
for i in range(n):
    if i != minMenu:
        if lastS[i] != 0:
            ans += (int(s[i]) - lastS[i]) + 10
        else:
            ans += int(s[i])
    else:
        ans += int(s[i])

print ans

    


Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
int p[200005],n,m,g[200005],ans=0,nc=0;
vector<int> v;
int fa(int x){return (p[x]==x)?x:(p[x]=fa(p[x]));}
void merge(int x,int y){
	int fx=fa(x),fy=fa(y);
	p[fx]=fy;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) p[i]=i;
	for(int i=1;i<=m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		merge(a,b);
	}
	for(int i=1;i<=n;i++){
		g[fa(i)]++;
	}
	for(int i=1;i<=n;i++)
		if(g[i]!=0) v.push_back(g[i]);
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		if(i!=0&&v[i]==v[i-1]) continue;
		ans+=(v[i]-nc);
		nc+=(v[i]-nc);
		//cout<<i<<' '<<ans<<' '<<nc<<endl;
	}
	cout<<ans;
	return 0;
}

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

int bubbleSort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for(int i=0; flag; ++i) {
		flag = 0;
		for(int j=n-1; j>=i+1; --j) {
			if(a[j] < a[j-1]) {
				swap(a[j], a[j-1]);
				flag = 1;
				++sw;
			}
		}
	}
	return sw;
}

int main()
{
	int a[100], n, sw;
	cin >> n;
	for(int i=0; i<n; ++i) cin >> a[i];

	sw = bubbleSort(a, n);

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

	return 0;
}

Measured memory_bytes: 3100
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    input!{n:usize,m:usize,x:i32,y:i32,mut xs:[i32;n],mut ys:[i32;m]}
    xs.push(x); ys.push(y);
    xs.sort(); ys.sort();
    if xs[n] < ys[0] { println!("No War"); } else { println!("War"); }
}

Measured memory_bytes: 4352
#include<stdio.h>
int same(char a[], char b[])
{
   int c = 0;
   for(;a[c]!='\0';c++)
   {
       if(a[c] == b[c])
           continue;
       else
        break;
   }

   if (a[c] == '\0' && b[c] == '\0')
      return 1;
   else
      return 0;
}


int main()
{
    char s[1000]= {'\0'},t[1000]= {'\0'},temp;
    int i,f=0,siz=0,j,c,l;
    scanf("%s%s",s,t);
    for(i=0; s[i]!='\0'; i++)
    {}
    siz=i;
    if(same(s,t)==1)
    {
        f=1;
        printf("Yes\n");
    }
    else
    {
        for(j=0; j<siz; j++)
        {
            s[siz+1]=s[siz-1];
            for(i=0; i<siz; i++)
            {
                s[siz-i]=s[siz-i-1];
            }
            s[0]=s[siz+1];
            s[siz]='\0';
            //printf("%s   %s\n",s,t);
            c=0;
           /* for(l=0; s[l]='\0'; l++)
            {
                //puts("dhukse\n");
                if('s[l]'=='t[l]')
                {
                    puts("dhukse\n");
                    c++;
                }
                //else break;
            }
             printf("c %d\n",c);*/

            if(same(s,t)==1)
            {
                f=1;
                printf("Yes\n");
                break;
            }

            else
                continue;
        }
    }
    if(f!=1)
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        s: chars
    }

    let mut ret = s.len();
    for i in 0..s.len()-1 {
        if s[i] != s[i+1] {
            ret = std::cmp::min(ret, std::cmp::max(i+1, s.len() - i - 1));
        }
    }
    println!("{}", ret);
}


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

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

  int ans=0;
  for(int i=1;i<=X;i++) {
    int num=i;
    for(int j=1;j<=X;j++) {
      num*=i;
      //cout << num << endl;
      if(num<=X){
        ans=max(num,ans);
      }else break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
<?php
  	$balls = array();
  	fscanf(STDIN, "%s %s", $S, $T);
	fscanf(STDIN, "%d %d", $A, $B);
	$balls[$S] = $A;
	$balls[$T] = $B;

	fscanf(STDIN, "%s", $U);
	$balls[$U] -= 1;
	echo $balls[$S] . " " . $balls[$T] ."\n";

	
	


Measured memory_bytes: 4856
#include <stdio.h>


int main() {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    
    if(a==b && a==c) {
        printf("No");
    }else if(a!=b && a!=c && b!=c) {
        printf("No");
    } else {
        printf("Yes");
    }
    
    return 0;
}

Measured memory_bytes: 128
H,W=map(int,input().split())
S=["."*(W+2)]
for _ in range(H):
    S.append("."+input()+".")
S.append("."*(W+2))

G=True
V=[(-1,0),(1,0),(0,-1),(0,1)]
for y in range(H+2):
    for x in range(W+2):
        if S[y][x]=="#":
            F=False
            for (a,b) in V:
                F|=(S[y+b][x+a]=="#")

            G&=F

if G:
    print("Yes")
else:
    print("No")


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    int sum = x + y;
    if (sum % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    int num = sum / 3;
    vector<ll> f(num + 1, 0), fi(num + 1, 0);
    f[0] = 1;
    for (int i = 1; i <= num; i++) {
        f[i] = f[i - 1] * i % MOD;
    }
    fi[num] = modpow(f[num], MOD - 2);
    for (int i = num; i > 0; i--) {
        fi[i - 1] = fi[i] * i % MOD;
    }

    ll ans = 0;
    for (int i = 0; i <= num; i++) {
        int j = num - i;
        if (i + 2 * j != x || i * 2 + j != y) continue;
        (ans += f[num] * fi[i] % MOD * fi[j] % MOD) %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

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

int main() {
	int K,A,B;
  	cin>> K >> A >> B;
  
  	int x=0;
  
  	for(int i=A;i<=B;i++){
     	if(i%K==0) x=1; 
    }
  
  	if(x) cout<<"OK"<<endl;
  	else cout<<"NG"<<endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    while(cin >> n >> m){
        if(n==0&&m==0){
            return 0;
        }
        vector<int> c(m),x(n);
        for(int i=0;i<m;i++){
            cin >> c[i];
        }
        for(int i=0;i<n;i++){
            cin >> x[i];
        }
        vector<vector<int>> dp(n+1,vector<int>(256,inf));
        dp[0][128]=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<=255;j++){
                if(dp[i][j]==inf){
                    continue;
                }
                for(int k=0;k<m;k++){
                    int t=max(0,min(255,j+c[k]));
                    chmin(dp[i+1][t],dp[i][j]+(t-x[i])*(t-x[i]));
                }
            }
        }
        int ans=inf;
        for(int i=0;i<=255;i++){
            chmin(ans,dp[n][i]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 23760
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    // 要素数
    int inputs = sc.nextInt();

    // 配列に格納された要素1つ1つについて、条件を満たさないものをカウントする
    int num;
    int count = 1;
    int min = sc.nextInt();
    for (int i = 1; i < inputs; i++) {
      num = sc.nextInt();
      if (min > num) {
        min = num;
      }
      if (min == num) {
        count++;
      }
    }
    System.out.println(count);
  }
}


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

using namespace std;

int main()
{
    int m,n;
    cin>>m>>n;
    int cnt[m];
    bool found[m];
    int ans=0;
    for(int i=0;i<m;i++)
    {
        cnt[i]=0;
        found[i]=false;
    }
    int ans2=0;
    for(int i=n-1;i>=0;i--)
    {
        int val;
        string s;
        cin>>val>>s;
        val--;
        if(s=="AC" && !found[val])
        {
            found[val]=true;
            ans+=cnt[val];
            ans2++;
        }
        else
        {
            cnt[val]++;
        }
    }
    cout<<ans2<<" "<<ans<<endl;

    return 0;
}


Measured memory_bytes: 768
#include <stdio.h>

int main(void)
{
	double v, t;
	int n;
	
	while (scanf("%lf", &v) != EOF){
		t = v / 9.8;
		for (n = 1; 4.9 * t * t >= 5 * n - 5; n++){
		}
		printf("%d\n", n);
	}
	
	return (0);
}

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

using namespace std;

#define INF 2<<29
#define F first
#define S second

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

int main(){
  int n;
  int one,two;
  int one_p;
  int a[200005];

  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  one=two=0;
  for(int i=0;i<n;i++){
    if(a[i]>one){
      one=a[i];
      one_p=i;
    }else if(a[i]>two){
      two=a[i];
    }
  }
  
  for(int i=0;i<n;i++){
    if(i!=one_p) printf("%d\n",one);
    else printf("%d\n",two);
  }
  
  return 0;
}



Measured memory_bytes: 2432
N = int(input())
min = 999999

A = 0
B = 0

def digitSum(n):
    s = str(n)
    array = list(map(int, list(s)))
    return sum(array)

for i in range(1, N/2+1):
    a = i
    b = N - i

    if min > digitSum(a) + digitSum(b):
        min = digitSum(a) + digitSum(b)   

print(min)


Measured memory_bytes: 4228
K, N = map(int, input().split())
A = list(map(int, input().split()))
B = sorted(A)
l = []

for i in range(N):
    if i == 0:
        c = B[N-1] - B[0]
        d = B[0]+ (K-B[1])
        if c > d:
            l.append(d)
        if c <= d:
            l.append(c)
    if B[i] != 0 and 0 < i < N-1:
        c = (K-B[i])+B[i-1]
        d = B[i]+ (K-B[i+1])
        if c > d:
            l.append(d)
        if c <= d:
            l.append(c)
    if B[i] != 0 and i == N-1:
        c = (K-B[i])+B[i-1]
        d = B[i]+ (K-B[0])
        if c > d:
            l.append(d)
        if c <= d:
            l.append(c)

L = sorted(l)
print(L[0])

Measured memory_bytes: 33172
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n;
int p[maxn];
vector<int> g[maxn];

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    g[i].clear();
  }
  p[0] = -1;
  for (int i = 1; i < n; i++) {
    scanf("%d", &p[i]);
    p[i]--;
    g[p[i]].push_back(i);
  }
  return true;
}

int dp[maxn];

void dfs(int v) {
  vector<int> c;
  for (int i = 0; i < sz(g[v]); i++) {
    dfs(g[v][i]);
    c.push_back(dp[g[v][i]]);
  }
  sort(c.begin(), c.end(), greater<int>());
  dp[v] = 0;
  for (int i = 0; i < sz(c); i++) {
    dp[v] = max(dp[v], c[i] + i + 1);
  }
}

void solve() {
  dfs(0);
  printf("%d\n", dp[0]);
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 14336
#include<iostream>
using namespace std;
int main (void)
{
	long long a, b, c, d;
	cin >> a >> b >> c >> d;
	long long xy [4];
	xy [0] = a * c;
	xy [1] = a * d;
	xy [2] = b * c;
	xy [3] = b * d;
	long max = xy [0];
	for (auto &e: xy)
		if (e > max)
			max = e;
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a[]=new int[3];
        for(int i=0;i<3;i++){
        	a[i]=sc.nextInt();
        }
        Arrays.sort(a);
        if(a[0]==5 &&a[1]==5 &&a[2]==7){
        	System.out.println("YES");
        }else{
        	System.out.println("NO");
        }
    }
}

Measured memory_bytes: 35316
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
//#define spec
using namespace std;

inline ll in() {ll n = 0; char ch = getchar(); bool x = 0;
	while (!isdigit(ch)) x |= (ch == '-'), ch = getchar(); while (isdigit(ch))
	n = (n << 3) + (n << 1) + (ch ^ 48), ch = getchar(); return x ? -n : n;
} inline string instr() {string ret = ""; char ch = getchar();
	while (ch == ' ' || ch == '\n') ch = getchar(); while (ch != ' ' && ch != '\n')
	ret += ch, ch = getchar(); return ret;
}

#ifdef spec
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
#endif

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

	string s = instr();
	ll n = in(), len = s.length();
	if (len == 1)
	{
		printf("%lld\n", n / 2);
		return 0;
	}
	ll t = 1, x = 0;
	for (int i = 1; i < len; i++)
	{
		if (s[i] == s[i - 1]) t++;
		else x += (t / 2), t = 1; 
	}
	if (t == len)
	{
		printf("%lld\n", len * n / 2);
		return 0;
	}
	x += (t / 2);
	x *= n;
	int l = 0, r = 0;
	for (int i = 0; i < len; i++)
		if (s[i] == s[len - 1]) l++;
		else break; 
	for (int i = len - 1; i >= 0; i--)
		if (s[i] == s[0]) r++;
		else break; 
	if (l % 2 && r % 2) x += n - 1;
	printf("%lld\n", x);

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int r;
    scanf("%d",&r);
    printf("%d\n",3*r*r);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		while(true){
			String grade = "";
			int m = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			if(m == -1 && f == -1 && r== -1){
				scan.close();
				break;
			}else if(m == -1 || f == -1){
				grade = "F";
			}else if(80 <= m + f){
				grade = "A";
			}else if(65 <= m + f && m + f < 80){
				grade = "B";
			}else if(50 <= m + f && m + f < 65){
				grade = "C";
			}else if(30 <= m + f && m + f < 50){
				if(50 <= r){
					grade = "C";
				}else{
					grade = "D";
				}
			}else if(m + f < 30){
				grade = "F";
			}
			System.out.println(grade);
		}
	}
}

Measured memory_bytes: 26288
class Card:
    def __init__(self, inf):
        self.num = int(inf[1])
        self.inf = inf

n, card = int(input()), [Card(i) for i in input().split()]
card1 = card[:]

for i in range(n-1):
    for j in range(n-1, i, -1):
        if card[j].num < card[j-1].num:
             card[j], card[j-1] = card[j-1], card[j]
print(" ".join([i.inf for i in card]))
print("Stable")

for i in range(n-1):
    for j in range(i+1, n):
        if j == i+1:
            idx = j
        elif card1[idx].num > card1[j].num:
            idx = j
    if card1[i].num > card1[idx].num:
        card1[i], card1[idx] = card1[idx], card1[i]
print(" ".join([i.inf for i in card1]))
if card == card1:
    print("Stable")
else:
    print("Not stable")



Measured memory_bytes: 5616
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
N,M=gsmi
l=N.times.map{gs.chars}
max=0
#puts l.to_s

# 移動ベクトル l u r d
dx = [-1,0,1,0]
dy = [0,1,0,-1]

N.times do |ii|
  M.times do |jj|
    sx=jj
    sy=ii
    next if l[sy][sx]=='#'
    
    # stから[i][j]までの距離
    d = Array.new(N){Array.new(M,-1)}
    # 操作キュー
    que = [[sy,sx]]
    d[sy][sx]=0
    
    q = nil
    while que.size>0 do
      q = que.shift
    
      4.times do |i|
        x1 = q[1]+dx[i]
        y1 = q[0]+dy[i]
        next if x1<0 || y1<0 || x1>=M || y1>=N
        # 走査済ならスキップ
        next if d[y1][x1]!=-1
    
        if l[y1][x1]!='#'
          que<<[y1,x1]
          d[y1][x1]=d[q[0]][q[1]]+1
        end
      end
    end
    
    m1=0
    N.times do |i1|
      M.times do |i2|
        c=d[i1][i2]
        m1=c if m1<c
      end
    end
    #puts "#{ii},#{jj},#{m1}"
    max=m1 if max<m1
  end
end

puts max


Measured memory_bytes: 2300
import java.io.*;
import java.util.Arrays;
class Main{
    public static void main(String[] args) throws IOException {
        int i,j,k;
        long sum;
        int[][] A = new int[101][101];
        int[][] B = new int[101][101];
        int[] n = new int[990];
        String[] str = new String[990];
        StringBuilder out = new StringBuilder();
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        str = in.readLine().split(" ");
        for(i=0;i<3;i++){
            n[i]=Integer.parseInt(str[i]);   
        }
        for(i=0;i<n[0];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[1];j++){
                A[i][j]=Integer.parseInt(str[j]);
            }
        }
        for(i=0;i<n[1];i++){
            str = in.readLine().split(" ");
            for(j=0;j<n[2];j++){
                B[i][j]=Integer.parseInt(str[j]);
            }
        }
        for(i=0;i<n[0];i++){
            for(j=0;j<n[2];j++){
                sum=0;
                for(k=0;k<n[1];k++){
                    sum += B[k][j]*A[i][k];             
                }
                if(j!=0) out.append(" ");
                out.append(sum);
            }
            out.append("\n");
        }   
        System.out.print(out);   
        System.out.flush();
    }
}

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

typedef vector<int> Adj_list;
typedef vector<Adj_list> Adj_lists;

class Timekeeper{
public:
  int found;
  int complete;

  Timekeeper(){
    found = 0;
    complete = 0;
  }
};
typedef vector<Timekeeper> Timekeepers;

void dfs(const int& i, const Adj_lists& adj_lists, Timekeepers& timekeepers, int& t){
  stack<int> s;
  s.push(i + 1);
  while(!s.empty()){
    // visit top of stack
    int visit = s.top();

    // if this node is not found in past, save the time.
    if(!timekeepers[visit-1].found){
      timekeepers[visit-1].found = ++t;
    }

    // find next adjecent which is not visited yet
    for(const int& adj_list : adj_lists[visit-1]){
      if(!timekeepers[adj_list-1].found){
        s.push(adj_list);
        break;
      }
    }

    // if no adj found, delete this node
    if(visit == s.top()){
      timekeepers[visit-1].complete = ++t;
      s.pop();
    }
  }
}

int main(){

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

  Adj_lists adj_lists(n);
  for(int i=0; i<n; i++){
    int u, k;
    scanf("%d %d", &u, &k);
    Adj_list adj_list(k);
    for(int j=0; j<k; j++){
      int v;
      scanf("%d", &v);
      adj_list[j] = v;
    }
    sort(adj_list.begin(), adj_list.end());
    adj_lists[u-1] = adj_list;
  }

  Timekeepers timekeepers(n);
  int t = 0;
  for(int i = 0; i < n; i++){
    if(!timekeepers[i].found) dfs(i, adj_lists, timekeepers, t);
  }

  for(int i = 0; i < timekeepers.size(); i++){
    printf("%d %d %d\n", i+1, timekeepers[i].found, timekeepers[i].complete);
  }

  return 0;
}



Measured memory_bytes: 3300
#include<stdio.h>

int main()
{
  int n,d,x;
  
  scanf("%d%d%d",&n,&d,&x);
  
  int a[n];
  int i;
  
  for(i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
  }
  
  int ans;
  
  ans=x;
  
  for(i=0;i<n;i++)
  {
    int j=0;
    while(j*a[i]+1<=d)
    {
      ans+=1;
      j++;
    }
  }
  
  printf("%d\n",ans);
  
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		int N = S.length();
		int a = 0,b = 0;
		for( int i=0; i<N; i++ ){
			if( S.charAt(i)=='0' ){
				a++;
			}else{
				b++;
			}
		}
		System.out.println(Math.min(a,b)*2);
	}
}


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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])
typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> rooms;
    for(int n = 0; n < N; n++){
        vector<int> room;
        rooms.push_back(room);
    }
    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
        rooms.at(A-1).push_back(B-1);
        rooms.at(B-1).push_back(A-1);
    }
    set<int> already;
    int ans[N];
    for(int i = 0; i < N; i++){
        ans[i] = -1;
    }
    queue<int> prev;
    prev.push(0);
    while(prev.size()>0){
        int prevroom = prev.front();
        vector<int> nextroom = rooms.at(prevroom);
        for(int i = 0; i < nextroom.size(); i++){
            int roomnum = nextroom.at(i);
            auto it = already.find(roomnum);
            if(it != already.end()){continue;}
            ans[roomnum] = prevroom;
            already.insert(roomnum);
            prev.push(roomnum);
        }
        prev.pop();
    }
    bool all = true;
    for(int i = 1; i < N; i++){
        if(ans[i]==-1){
            all = false;
            break;
        }
    }
    if(all){
        cout << "Yes" << endl;
        for(int i = 1; i < N; i++){
            cout << ans[i]+1 << endl;
        }
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 15444
#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,M;
ll dp[202][8080];
ll mo=998244353;

const int NUM_=400001;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];

ll combi(ll N_, ll C_) {
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

ll modpow(ll a, ll n = mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}
vector<ll> fft(vector<ll> v, bool rev=false) {
	int n=v.size(),i,j,m;
	
	for(i=0,j=1;j<n-1;j++) {
		for(int k=n>>1;k>(i^=k);k>>=1);
		if(i>j) swap(v[i],v[j]);
	}
	for(int m=2; m<=n; m*=2) {
		ll wn=modpow(5,(mo-1)/m);
		if(rev) wn=modpow(wn);
		for(i=0;i<n;i+=m) {
			ll w=1;
			for(int j1=i,j2=i+m/2;j2<i+m;j1++,j2++) {
				ll t1=v[j1],t2=w*v[j2]%mo;
				v[j1]=t1+t2;
				v[j2]=t1+mo-t2;
				while(v[j1]>=mo) v[j1]-=mo;
				while(v[j2]>=mo) v[j2]-=mo;
				w=w*wn%mo;
			}
		}
	}
	if(rev) {
		ll rv = modpow(n);
		FOR(i,n) v[i]=v[i]*rv%mo;
	}
	return v;
}

vector<ll> MultPoly(vector<ll> P,vector<ll> Q,bool resize=false) {
	P=fft(P), Q=fft(Q);
	for(int i=0;i<P.size();i++) P[i]=P[i]*Q[i]%mo;
	return fft(P,true);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	inv[1]=fact[0]=factr[0]=1;
	for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
	for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	
	vector<ll> B(1<<14,0);
	for(i=1;i<=8000;i++) B[i]=factr[i+2];
	
	
	
	cin>>N>>M;
	dp[0][0]=1;
	FOR(i,M) {
		vector<ll> A(1<<14,0),C;
		FOR(j,N+1) A[j]=dp[i][j]*factr[j]%mo;
		C=MultPoly(A,B);
		FOR(j,N+1) (dp[i+1][j]=C[j]*fact[j+2] + dp[i][j]*(1+combi(j+1,2)))%=mo;
	}

	ll ret=1;
	for(j=1;j<=N;j++) (ret+=dp[i][j]*combi(N,j))%=mo;
	
	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);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 23024
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (LL i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (LL i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

LL const MaxSize = 1e5 + 5;
LL const MOD = 1e9 + 7;
LL const BASE = 256;

/*

option 1, pr( good) + 1 - pr(good)

 */

LL N, X;
vector<LL> s;
LL ans[MaxSize][205];
int main() {
	ios_base::sync_with_stdio(false);
	//freopen("/Users/georgeli/A_1.in", "r", stdin);
	cin >> N >> X;
	LP(i,0, N)
	{
		int num;
		cin >> num;
		s.push_back(num);
	}

	sort(s.begin(), s.end());

	LPE(v, 0, 1e5)
	{
		ans[v][0] = v % s[0];
	}

	LP(i, 1, N)
	{
		LPE(v, 0, 1e5)
		{
			ans[v][i] =  ans[v % s[i]][i - 1];
			ans[v][i] += i * ans[v][i - 1];
			ans[v][i] %= MOD;
		}
	}

	cout << ans[X][N - 1] << endl;

	return 0;
}


Measured memory_bytes: 160512