akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <map>
#include <iostream>
#include <cstdio>
using namespace std;
using ll = long long int;

const int DIGIT = 14 + 1;
const int MAXS = DIGIT * 9 + 1;
map<ll, ll> dp[DIGIT][MAXS][3];

string str;
ll N, sum, prod;

ll solve(int d, int s, int f, ll p) {
    if(d == N) {
        if(s < sum) return 1;
        else if(s == sum and p < prod) return 1;
        else if(s == sum and p == prod) {
            if(f == 1) return 1;
            else return 0;
        }
        else return 0;
    }

    if(dp[d][s][f].count(p)) return dp[d][s][f][p];
    int num = str[d] - '0';
    ll res = 0;
    for(int x=0; x<=9; x++) {
        int ns = s + x;
        int nf = f;
        if(nf == 0 and x < num) nf = 1;
        if(nf == 0 and x > num) nf = 2;
        ll np = p * (x + 1);

        res += solve(d+1, ns, nf, np);
    }
    return dp[d][s][f][p] = res;
}

int main() {
    cin >> str;
    N = str.length(); prod = 1;
    for(int i=0; i<N; i++) {
        int c = str[i] - '0';
        sum += c;
        prod *= (c + 1);
    }

    cout << solve(0, 0, 0, 1) << endl;
    return 0;
}



Measured memory_bytes: 50312
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;



int main(){
	int n;
	long long a[100000];

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

	sort(a,a+n);

	long long p = a[n-1];
	long long r = 0;

	if(p%2==0){
		long long p2 = a[n-1]/2;
		for(int i=0;i<n-1;i++){
			if(abs(r-p2) > abs(a[i]-p2)) r = a[i];
		}
	}else{
		double p2 = (double)a[n-1]/2;
		for(int i=0;i<n-1;i++){
			if(abs((double)r-p2) > abs((double)a[i]-p2)) r = a[i];
		}
	}

	printf("%lld %lld\n", p, r);

	return 0;
}


Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	a := iSScan(n)
	p := 1
	ans := 0
	for _, v := range a {
		if p == 1 {
			p++
			ans += v - 1
		} else if p == v {
			p++
		} else {
			ans += (v - 1) / p
		}
	}
	fmt.Println(ans)
}


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

int ctoi(char c) {
	if (c>='0' && c<='9'){
		return c-'0';
	}
	return 0;
}

int main(){
    char N_char;
    int a = 0;
    
    while(!cin.eof()){
        N_char = cin.get();
        a = (a + ctoi(N_char))%9;
    }

if(a%9 == 0){
    cout << "Yes" << endl;
}else{
    cout << "No" << endl;
}
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
int keta(int num)
{
    int cnt = 0;
    while (num)
    {
        num /= 10;
        cnt++;
    }
    return cnt;
}
int main()
{
    int s;
    cin >> s;
    // cout << keta(s) << endl;
    int ans = 0;
    rep(i, 1, s + 1)
    {
        if (keta(i) % 2 == 1)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int c[3][3];
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cin>>c[i][j];
        }
    }
    int b1=c[0][0],b2=c[0][1],b3=c[0][2];
    int a2=c[1][0]-b1,a3=c[2][0]-b1;
    if(c[1][1]==a2+b2 && c[2][1]==a3+b2 && c[1][2]==a2+b3 && c[2][2]==a3+b3){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c<22){
		cout<<"win"<<endl;
	}else{
		cout<<"bust"<<endl;
	}
	return 0;
}


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

using namespace std;

const int N = 1e6;

int readInt ()
{
    bool minus = false;
    int result = 0;
    char ch;
    ch = getchar();
    while (true)
    {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus = true;
    else result = ch-'0';
    while (true)
    {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus)
        return -result;
    else
        return result;
}
char readChar()
{
    char result = getchar();
    while (isspace(result)) {
        result = getchar();
    }
    return result;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r)
{
    return uniform_int_distribution<int>(l, r)(rng);
}
main() {
    int n = readInt(), k = readInt();
    int ans = 0;
    while (n--) {
        int x = readInt();
        ans += (x >= k);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  if(N >= 1000){
    cout << "ABD" << endl;
  }else{
    cout << "ABC" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    int N;
    int A;
    int B;
    int C;
    int D;
    byte[] S;

    private void run() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        A = scanner.nextInt() - 1;
        B = scanner.nextInt() - 1;
        C = scanner.nextInt() - 1;
        D = scanner.nextInt() - 1;
        S = scanner.next().getBytes();

        int time = 0;
        if (!check()) {
            System.out.println("No");
            return;
        }

        boolean ok = check2(time, A, B, C, D);
        if (ok) {
            System.out.println("Yes");
            return;
        } else {
            System.out.println("No");
            return;
        }
    }

    private boolean check() {
        for (int i = A; i < C - 1; i++) {
            if (S[i] == 35 && S[i + 1] == 35) {
                return false;
            }
        }
        for (int i = B; i < D - 1; i++) {
            if (S[i] == 35 && S[i + 1] == 35) {
                return false;
            }
        }
        return true;
    }

    private boolean check2(int time, int a, int b, int c, int d) {
        if (b == d) {
            if (c > d && (S[b - 1] == 35 || S[b + 1] == 35)) {
                return false;
            }
            return true;
        } else if (S[b] == 35) {
            return false;
        } else if (S[b - 1] != 35 && S[b + 1] != 35 && b - 1 != a) {
            return true;
        }
        return check2(time, a, b + 1, c, d) ||
                check2(time, a, b + 2, c, d);
    }
}

Measured memory_bytes: 32424
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    string s,t; cin>>s>>t;
    ll ans=1,n=s.size();
    vector<vector<ll>> pos(26,vector<ll>(1,n+1));
    rep(i,n) pos[s[i]-'a'].push_back(i+1);
    rep(i,26) sort(al(pos[i]));
    ll cnt1=0,cnt2=0;
    rep(i,t.size()){
        ll ind=t[i]-'a';
        ll l=0,r=pos[ind].size()-1,ce;
        if(r==0){
            ans=-1; break;
        }
        while(l!=r){
            ce=(l+r)/2;
            if(pos[ind][ce]>cnt2) r=ce;
            else l=ce+1;
        }
        if(pos[ind][l]!=n+1) cnt2=pos[ind][l];
        else{
            cnt1++; cnt2=pos[ind][0];
        }  
    }
    cout<<(ans!=-1 ? cnt1*n+cnt2 : ans)<<endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

struct UnionFind{
  vector<int> v;
  UnionFind(int n) : v(n, -1) {}
  void init(){ for(int i = 0;i < v.size();i++)v[i]=-1; }
  int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);
    v[x] += v[y]; v[y] = x;
    return true;
  }
  bool root(int x) { return v[x] < 0; }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -v[find(x)]; }
};

int n,m;
int p[100010],idx[100010];

int main(){
  cin>>n>>m;
  rep(i,n){
    cin>>p[i];
    p[i]--;
    idx[p[i]]=i;
  }
  UnionFind uf(n);
  rep(i,m){
    int x,y;
    cin>>x>>y;
    x--;y--;
    uf.unite(x,y);
  }
  int res=0;
  rep(i,n){
    if(uf.same(i,idx[i]))res++;
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 1408
n,m = map(int,input().split())
k = []
s = []

for i in range(m):
  k.append(list(map(int,input().split())))
  s.append(k[i].pop(0))
p = list(map(int,input().split()))

light_on = 0
switch_on = 0
ans = 0
for i in range(2**n):
  light_on = 0
  for j in range(m):
    switch_on = 0
    for K in range(s[j]):
      if (i >> k[j][K]-1) &1:
        switch_on += 1
    if switch_on%2 == p[j]:
      light_on += 1
  if light_on == m:
    ans  += 1
print(ans)

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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  int B[M], A[N][M];
  
  for (int i = 0; i < N + 1; ++i) {    
    if (i == 0) {
      for (int j = 0; j < M; ++j) {
        cin >> B[j];
      }      
    } else {      
      for (int j = 0; j < M; ++j) {
        cin >> A[i-1][j];
      } 
    }   
  }
  
  int answer = 0;
  for (int i = 0; i < N; ++i) {
    int sum = C;
    for (int j = 0; j < M; ++j) {
      sum += B[j] * A[i][j];
    }
    if (sum > 0) 
      answer++;
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")

def main():
    N = I()
    A = LI()

    forward = list(itertools.accumulate(A, math.gcd))
    backward = list(itertools.accumulate(A[::-1], math.gcd))[::-1]

    ans = max(backward[1], forward[-2])

    for i in range(1, N - 1):
        ans = max(ans, math.gcd(forward[i - 1], backward[i + 1]))
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 103516
n, y = map(int, input().split())
ans =[-1, -1, -1]
for i in range(n+1):
    for j in range(n-i+1):
        k = n - i - j
        if i * 10 + j * 5 + k == y / 1000:
            ans = [i, j, k]
            print(i, j, k)
            exit()
ans = [str(a) for a in ans]
print(' '.join(ans))

Measured memory_bytes: 40684
N,Y=list(map(int,input().split()))

flg=1               #N枚のお札の合計金額がY円となることがありえない場合
for i in range(N+1):
    for j in range(N-i+1):
        k=N-(i+j)
        if 10000*i+5000*j+1000*k==Y:
            flg=0
            x=i
            y=j
            z=k
if flg==1:
    print('-1 -1 -1')
else:
    print(x,end=" ")
    print(y,end=" ")
    print(z)



Measured memory_bytes: 3060
def resolve():
	w, h, n = map(int, input().split())
	r = [[True]*w for _ in range(h)]
	for i in range(n):
		x, y, a = map(int, input().split())
		if a == 1:
			for j in range(h):
				for k in range(x):
					r[j][k] = False
		if a == 2:
			for j in range(h):
				for k in range(x, w):
					r[j][k] = False
		if a == 3:
			for j in range(y):
				for k in range(w):
					r[j][k] = False
		if a == 4:
			for j in range(y, h):
				for k in range(w):
					r[j][k] = False
	ans = 0
	for i in range(h):
		for j in r[i]:
			if j:
				ans += 1
	print(ans)
resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  string ans(N, '?');
  bool isok = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ans[s] != '?' && ans[s] != '0' + c) {
      isok = false;
    }
    ans[s] = '0' + c;
  }
  if (!isok || (N > 1 && ans[0] == '0')) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < N; i++)
      if (ans[i] == '?') {
        ans[i] = '0' + (i || N == 1 ? 0 : 1);
      }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3596
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int p[100000];
int s[100000];

int parent(int a) {
    if (p[a] != a)
        p[a] = parent(p[a]);
    return p[a];
}

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

    int n = gi();
    for (int i = 0; i < n; i++) {
        p[i] = i;
        s[i] = 1;
    }

    int m = gi();
    stack<pii> e;
    for (int i = 0; i < m; i++)
        e.push({gi()-1, gi()-1});

    ll v = ll(n) * ll(n-1) / 2LL;
    stack<ll> res;
    for (int i = 0; i < m; i++) {
        res.push(v);
        int na = e.top().first;
        int nb = e.top().second;
        e.pop();
        int pa = parent(na);
        int pb = parent(nb);
        if (pa != pb) {
            v -= ll(s[pa]) * ll(s[pb]);
            if (s[pa] < s[pb]) {
                p[pa] = pb;
                s[pb] += s[pa];
            } else {
                p[pb] = pa;
                s[pa] += s[pb];
            }
        }
    }

    for (int i = 0; i < m; i++) {
        cout << res.top() << endl;
        res.pop();
    }

    return 0;
}


Measured memory_bytes: 3072
#!/usr/bin/env python3

def main():
    A,B,K = map(int, input().split())
    if A >= K:
        A = A - K
    else:
        B = B - (K - A) 
        A = 0
        if B < 0:
            B = 0


    print('{} {}'.format(A,B))

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int q;
    cin >> q;
    string front;
    string back;
    bool reversed = false;

    for (size_t i = 0; i < q; ++i)
    {
        int t, f;
        char c;
        cin >> t;
        if (t == 1)
        {
            if (reversed)
            {
                reversed = false;
            }
            else
            {
                reversed = true;
            }
            continue;
        }
        cin >> f >> c;
        if (f == 1)
        {
            if(reversed)
            {
                back.push_back(c);
            }
            else
            {
                front.push_back(c);
            }
            continue;
        }
        if (reversed)
        {
            front.push_back(c);
        }
        else
        {
            back.push_back(c);
        }
    }
    reverse(front.begin(), front.end());

    front.append(s).append(back);

    if (reversed)
    {
        reverse(front.begin(), front.end());
    }
    cout << front << endl;

    return 0;
}

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

int main()  {
  int a, b; cin >> a >> b;
  vector<int> data;
    data = { 0, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 };
  int A=data[a], B=data[b];
  
  if(A==B){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

using namespace std;

class Solution {
public:
	void solve() {
		int n;
		cin >> n;
		while (n) {
			if (n % 10 == 7) {
				cout << "Yes\n";
				return;
			}
			n /= 10;
		}
		cout << "No\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

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

int main() {
	int N,a,c=0;
	cin >> N;
	
	rep(i,N) {
		cin >> a;
		if(i%2==0 && a%2)
			++c;
	}
	cout << c << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

int mv(int a,int b){
   int x = (a-b)*(a-b);
   return x;
}

int main(){
   int n;scanf("%d",&n);
   int x[100];for(int i = 0;i < n;i++)scanf("%d",&x[i]);
   int ans = inf;
   for(int j = 0;j < 100;j++){
      int _ans = 0;
      for(int i = 0;i < n;i++){
         //printf("  x[i]:%d i:%d",x[i],i);
         _ans += mv(x[i],j);
         //printf("  %d\n",_ans);
      }
      //printf("%d:%d\n",j,_ans);
      ans = MIN(_ans,ans);
   }
   printf("%d\n",ans);
   //printf("%d\n",mv(1,2));
}


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

using ll = long long;

using namespace std;

int main() {
    int n;
    ll k;
    cin >> n >> k;
    ll best = 0, a[n];
    for (auto &ai:a) {
        cin >> ai;
        best = max(best, ai);
    }
    ll l = 0, r = best;
    while (r - l > 1) {
        ll m = (l + r + 1) / 2;
        ll sum = 0;
        for (auto &ai:a) {
            sum += (ai - 1) / m;
        }
        if (sum <= k) {
            r = m;
        } else {
            l = m;
        }
    }
    cout << r << '\n';
    return 0;
}

Measured memory_bytes: 5192
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
typedef long long int ll;
ll u(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll d(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
ll f(ll a){
  return a*(a+1)/2;
}
int main(void){
  char s[500001];
  scanf("%s",s);
  ll a[500000],flg=(s[0]=='>'&&s[strlen(s)-1]=='<'),cnt1=1,cnt2=0,ans=0;
  FOR(strlen(s)-1){
    if(s[i]-s[i+1]){
      a[cnt2]=cnt1;
      cnt2++;
      cnt1=1;
    }else{
      cnt1++;
    }
  }
  a[cnt2]=cnt1;
  cnt2++;
  a[cnt2]=1;
  if(flg){
    ans+=f(a[0])+f(a[cnt2-1]);
    cnt2-=2;
  }
  for(ll i=0;i<cnt2;i+=2){
    if(flg){
      i++;
      flg--;
    }
    ans+=f(max(a[i],a[i+1]))+f(min(a[i],a[i+1])-1);
  }
  PRL(ans);
  return 0;
}


Measured memory_bytes: 4480
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/abc114/tasks/abc114_c
# C - 755
"""
need to consider the case that ticket is not enough to lower everything
"""

N = gi()
nps = []
ns = []

for i in range(N):
    a = gi()
    if a < 0:
        ns.append(-a)
    else:
        nps.append(a)

ns.sort()
nps.sort()

base = sum(ns) + sum(nps)

if len(ns) % 2:
    ans = base - 2 * ns[0]
    if len(nps):
        ans = max(ans, base - 2 * nps[0])
else:
    ans = base

print(ans)

Measured memory_bytes: 24036
import sys
def gcd(a, b):
  if a < b:
    a, b = b, a
  a, b = b, a % b
  if b == 0:
    return a
  else:
    return gcd(a, b)

N, X = map(int, input().split())
x = sorted(list(map(lambda x:int(x) - X, input().split())))
y = []

if N == 1:
  print (abs(x[0]))
  sys.exit()
elif N == 2:
  print (gcd(abs(x[0]), abs(x[1])))
  sys.exit()
for i in range(N-1):
  y.append(x[i+1]-x[i])

ans = y.pop()
while y:
  ans = gcd(ans, y.pop())
print (ans)

Measured memory_bytes: 14480
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	map<int, int> mp;
	rep(i,n) mp[v[i]]++;

	if (mp.size() == 2) {
		bool b1 = false;
		bool b2 = true;
		for (auto p: mp) {
			if (p.first == 0) b1 = true;
			if (p.second != n * 2 / 3 && p.second != n / 3) b2 = false;
		}
		if (b1 && b2 && n % 3 == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	if (mp.size() == 3) {
		bool b = true;
		int x = 0;
		for (auto p: mp) {
			x ^= p.first;
			if (p.second != n / 3) b = false;
		}
		if (b && !x && n % 3 == 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	if (mp.size() == 1) {
		if (mp[0] == n) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 7104
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;

ll A, B, C;

int main()
{
  scanf( "%lld%lld%lld", &A, &B, &C );

  ll tmp = std::min( A+B, C-1 );

  printf( "%lld\n", tmp+1+B );
  
  return 0;
}

Measured memory_bytes: 128
l=list(map(int,input().split()))

for i in range(3):
    if l[i]%2==1:
        print(0)
        exit()

if l.count(l[0])==3:
    if l[0]%2==0:
        print(-1)
        exit()
    else:
        print(0)
        exit()

count=0
while True:
    temp=list(map(lambda x:x%2,l))
    all=sum(temp)
    if all==3:
        print(count+1)
        exit()
    elif all==2:
        print(count)
        exit()
    elif all==1:
        print(count)
        exit()
    l=list(map(lambda x:x//2,l))
    count+=1



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

int h[1500],w[1500];
int hl[1500001],wl[1500001];

int main(){
  int n,m;
  while(cin>>n>>m &&(n||m)){
    long long co=0;
    for(int i=0;i<n;i++) cin>>h[i];
    for(int i=0;i<m;i++) cin>>w[i];
    for(int i=0;i<=1500000;i++) hl[i]=wl[i]=0;

    for(int i=0;i<n;i++){
      int sum=0;
      for(int j=i;j<n;j++){
	sum+=h[j];
	hl[sum]++;
      }
    }
    for(int i=0;i<m;i++){
      int sum=0;
      for(int j=i;j<m;j++){
	sum+=w[j];
	wl[sum]++;
      }
    }	
    for(int i=0;i<=1500000;i++) co+=hl[i]*wl[i];
    cout <<co<<endl;
  }

  return 0;
}

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

int main() {
    int n, y;
    cin >> n >> y;
    bool flag = false;
    for (int i = 1; i <= n + 1; i++) {
        for (int j = i + 1; j <= n + 2; j++) {
            int sum = 10000 * (i - 1) + 5000 * (j - i - 1) + 1000 * (n + 2 - j);
            if (sum == y) {
                printf("%d %d %d\n", i - 1, j - i - 1, n + 2 - j);
                goto OUT;
            }
        }
    }
    printf("-1 -1 -1\n");
    OUT:
    return  0;
}

Measured memory_bytes: 3692
def s():
 n=int(input())+1
 e=[input().split()for _  in[0]*~-n]
 p=[int(e[0][0])]+list(int(x[1])for x in e)
 m=[[0]*n for _ in[0]*n]
 for i in range(n):
  for r in range(n-i-1):
   c=r+i+1
   for j in range(r+1,c):
    x=m[r][j]+m[j][c]+p[r]*p[j]*p[c]
    if 1>m[r][c]or m[r][c]>x:m[r][c]=x
 print(m[r][c])
if'__main__'==__name__:s()


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

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

    int x[m];

    for (int i = 0; i < m; i++)
        cin >> x[i];

    sort(x, x+m);

    if (m > n) {
        int d[m-1];
        for (int i = 0; i < m-1; i++) {
            d[i] = x[i+1] - x[i];
        }
        sort(d, d + m - 1);
        int ans = 0;
        for (int i = 0; i < m - n; i++)
            ans += d[i];
        cout << ans << endl;
    }
    else {
        cout << 0 << endl;
    }
}


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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    for (int i = 0; i < 3; i++) {
        for (int j = i + 1; j < 3; j++) {
            if (s[i] != s[j]) {
                cout << "Yes" << '\n';
                exit(0);
            }
        }
    }
    cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int a[5],b[5],go[5],have[3];
int main(){
	for(int i=1;i<=3;i++)
		cin>>a[i]>>b[i],go[a[i]]++,go[b[i]]++;
	for(int i=1;i<=4;i++)
		if(go[i]==1)
			have[1]++;
		else if(go[i]==2)
			have[2]++;
	if(have[1]==2&&have[2]==2)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

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

ll A, B, C, D;

int main(){
  cin >> A >> B >> C >> D;

  ll nb = B - B / C - B / D + B / (C * D / gcd(C, D));
  ll na = (A - 1) - (A - 1) / C - (A - 1) / D + (A - 1) / (C * D / gcd(C, D));

  cout << nb - na << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n, m;
int prime2(int x) {
  int c = 0;
  while(x % 2 == 0) {
    x /= 2;
    c++;
  }

  return c;
}

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

ll lcm(ll a, ll b) {
  if(a < b) swap(a, b);
  return a * b / gcd(a, b);
}

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

  cin >> n >> m;

  vector<int> a(n);
  REP(i, n) cin >> a[i];

  int t = prime2(a[0]);

  REP(i, n) if(t != prime2(a[i])) {
    cout << 0 << endl;
    return 0;
  }

  ll lc = a[0] / 2;
  REP(i, n) {
    lc = lcm(lc, a[i] / 2);
    if(lc > m) {
      cout << 0 << endl;
      return 0;
    }
  }

  cout << ((m / lc + 1) / 2) << endl;
}


Measured memory_bytes: 3716
from itertools import permutations
def resolve():
    N = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))

    ls = list(permutations(range(1, N+1)))
    ans = abs(ls.index(P) - ls.index(Q))
    print(ans)
    return

resolve()

Measured memory_bytes: 13840
fun main(args: Array<String>) {
    var N = readLine()!!.toInt()
    var S = (1..N).map{
        readLine()!!.toList().map{x->x.toInt()-'a'.toInt()}
    }
    var min_arr = IntArray(26,{50}) // n<50
    S.map{s->
        var frq = IntArray(26,{0})
        s.map{i->frq[i]++}
        (0..25).map{i->
            min_arr[i] = Math.min(min_arr[i],frq[i])
        }
    }
    for(i in 0..25){
        repeat(min_arr[i]){
            print((i+'a'.toInt()).toChar())
        }
    }
}

Measured memory_bytes: 33740
#include <stdio.h>
#define MAX 100000
typedef struct node{
  int pare;
  int left;
  int right;
}Node;

Node a[MAX];
int depth[MAX];
void searchdep(int,int);
int main(){
  int n,i,num,sum,j,tmp,k;
  scanf("%d",&n);
  for(i = 0 ;i<n ;i++){
    a[i].left = -1;
    a[i].right =-1;
    a[i].pare = -1;
  }
  
    for(i = 0 ;i<n ;i++){
      scanf("%d %d",&num,&sum);
      for(j = 0;j<sum;j++){
	scanf("%d",&tmp);
	if(j ==0) a[num].left = tmp;
	else {a[k].right= tmp;}
	  k=tmp;
	  a[k].pare = num;
      }
    }

    for(i =0;i<n;i++){
      if( a[i].pare == -1){
	searchdep(i,0);
      }

    }
    for(i =0 ;i<n;i++){
      if(a[i].pare ==-1){
	printf("node %d: parent = %d, depth = %d, root, ",i,a[i].pare,depth[i]);
	  printf("[");
	for(j = 0,tmp = a[i].left;tmp!=-1;j++,tmp = a[tmp].right){
	  if(j==0){
	  printf("%d",tmp);
	  }
	  else printf(", %d",tmp);
	    }
	printf("]\n");
      }
      else if(a[i].left !=-1 &&a[i].pare != -1){
	printf("node %d: parent = %d, depth = %d, internal node, ",i,a[i].pare,depth[i]);
	printf("[");
      for(j = 0,tmp = a[i].left;tmp!=-1;j++,tmp = a[tmp].right){
	  if(j==0){
	  printf("%d",tmp);
	  }
	  else printf(", %d",tmp);
	
	    }
	printf("]\n");
      }
      else if(a[i].left ==-1){
      	printf("node %d: parent = %d, depth = %d, leaf, []\n",i,a[i].pare,depth[i]);
    }
    }
    return 0;
}
      
void searchdep(int c ,int b){
  depth[c] = b;
  if(a[c].right !=-1){
    searchdep(a[c].right,b);
  }
  if(a[c].left != -1){
    searchdep(a[c].left,b+1);
  }
}



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

int main()
{
    int nb;
    cin >> nb;
    if((nb % (111)) == 0)
    {
        cout << nb;
    }
    else
    {
        if(nb - ((nb /100)*100) < ((nb / 100 )*11))
        {
            nb = nb / 100;
            nb = nb * 111;
            cout << nb;
        }
        else
        {
            nb = nb / 100;
            nb = (nb + 1) * 111;
            cout << nb;
        }
    }
}

Measured memory_bytes: 256
program main
  
  implicit none
  integer(8) :: x, i, j
  
  read(*,*) x

  i = 100
  j = 0
  do 
    j = j + 1
    i = i + i/100 
    if( i >= x ) then
      exit
    end if
  end do
  print*, j
   
end program main


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

/**
 *
 * @author k15115kk
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try{
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String str = reader.readLine();
             String[] arr = str.split(" ");
            int a = Integer.parseInt(arr[0]);
            int b = Integer.parseInt(arr[1]);
            int c = Integer.parseInt(arr[2]);
            
            if(a < b && b < c){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
        }catch(IOException e){
            e.printStackTrace();
        }
    }
    
}

Measured memory_bytes: 24196
import java.io.*;
import java.util.*;
 
public class Main{
	
	String S;
	Map<String, String> map;
	public void solve(){
		S = next();
		map = new HashMap<>();
		map.put("A", "T");
		map.put("C", "G");
		map.put("G", "C");
		map.put("T", "A");
		
		String ans = "";
		
		for(int i = 0; i < S.length(); i++) {
			for(int j = i + 1; j <= S.length(); j++) {
				String sum = S.substring(i, j);
				if(valid(sum) && sum.length() > ans.length()) {
					ans = sum;
				}
			}
		}
		
		out.println(ans.length());
	}
	
	private boolean valid(String s) {
		for(int i = 0; i < s.length(); i++) {
			if(!map.containsKey(s.substring(i, i + 1))) {
				return false;
			}
		}
		return true;
	}
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

Measured memory_bytes: 23252
#その前のstrと違って、けど一番短いのを足していけばいいだけ。
S = input()
L = [alphabet for alphabet in S]
i = 0
k = 1
before = ''
res = 0
while i+k <= len(L):
  if L[i:i+k] != before:
    res += 1
    before = L[i:i+k] # "before" updated
    i = i+k #next a of L[a:b]
    k = 1 #initialised
  else:
    k += 1
print(res)

Measured memory_bytes: 5096
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
using namespace std;
int q;

int main()
{
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

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

ll cnt;

void merge(vector<ll> &A, ll left, ll mid, ll right) {
  ll lm = mid - left, mr = right - mid;
  vector<ll> LM(lm + 1, 1e10);
  vector<ll> MR(mr + 1, 1e10);
  for (ll i = 0; i < lm; i++) {
    LM[i] = A[left + i];
  }
  for (ll i = 0; i < mr; i++) {
    MR[i] = A[mid + i];
  }

  ll l = 0, r = 0;
  for (ll i = left; i < right; i++) {
    cnt++;
    if (LM[l] <= MR[r]) {
      A[i] = LM[l]; l++;
    } else {
      A[i] = MR[r]; r++;
    }
  }
}

void mergeSort(vector<ll> &A, ll left, ll right) {
  if (left + 1 < right) {
    ll mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

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

  cnt = 0;
  ll N; cin >> N;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];
  mergeSort(A, 0, N);

  cout << A[0]; for (int i = 1; i < A.size(); i++) { cout << ' ' << A[i]; }
  cout << '\n' << cnt << '\n';
  return 0;
}


Measured memory_bytes: 10652
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  string str;

  cin >> str;

  for(int i = str.size()-1; i >= 0; i--) cout << str[i];
  cout << endl;
}

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

using namespace std;
typedef long long ll;

int main()
{
	ll n;
	cin>>n;
	vector<string>vec(n);
	set<string>v;
	for(int i=0;i<n;i++){
		cin>>vec[i];
		v.insert(vec[i]);
	}
	cout<<v.size();
}

Measured memory_bytes: 25016
import sys

H, W = map(int, input().split())
S = [list(sys.stdin.readline().strip()) for _ in range(H)]

dx = [1, 0, -1, 0]
dy = [0, -1, 0, 1]

for i, row in enumerate(S):
    for j, s in enumerate(row):
        if s == ".":
            continue
        ok = False
        for k in range(4):
            nx = j + dx[k]
            ny = i + dy[k]
            if not(0 <= nx < W and 0 <= ny < H):
                continue
            if S[ny][nx] == "#":
                ok = True
        if ok is False:
            print("No")
            exit()

print("Yes")


Measured memory_bytes: 9176
N, M = list(map(int, raw_input().split()))
K = []

array = []
for i in xrange(M): array.append(0)
for i in xrange(N):
    inputs = list(map(int, raw_input().split()))
    K = inputs[0]
    for j in xrange(K):
        array[inputs[j+1]-1] += 1

count = 0
for i in xrange(M):
    if array[i] == N: count += 1

print str(count)

Measured memory_bytes: 2568
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int n; cin >> n;
  vector<vector<int>> v(n, vector<int>(26, 0));
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    for(int j = 0; j < s.size(); j++){
      v[i][(int)(s[j] - 'a')]++;
    }
  }
  for(int i = 0; i < 26; i++){
    int minv = v[0][i];
    for(int j = 1; j < n; j++){
      minv = min(v[j][i], minv);
    }
    for(int j = 0; j < minv; j++) cout << (char)('a' + i);
  }
  cout << endl;
  return;
}

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


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

// #define multitest 1
#ifdef WIN32
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.first << ", " << p.second << ']';
	return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
	std::cerr << name << " { ";
	for (const auto &v : arg)
		cerr << v << ' ';
	cerr << " }\n";
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
auto TimeStart = chrono::steady_clock::now();

const int nax = 2e5 + 10;
using ld = long double;
using point = complex<ld>;
int n;
vector<point> Points;

bool cmp(point a, point b)
{
	return arg(a) < arg(b);
}

void solve()
{
	cin >> n;
	int x, y;
	for (int i = 0; i < n; ++i)
	{
		cin >> x >> y;
		Points.pb(point(x, y));
	}
	ld ans = 0;
	sort(Points.begin(), Points.end(), cmp);
	for (int len = n; len <= n; ++len)
	{
		for (int i = 0; i < n; ++i)
		{
			point p(0, 0);
			int ctr = i;
			for (int j = 0; j < len; ++j)
			{
				p += Points[ctr];
				ctr = (ctr + 1) % n;
				ans = max(ans, norm(p));
			}
		}
	}
	cout << fixed << setprecision(15) << sqrtl(ans);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
#ifdef WIN32
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>

using namespace std;

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

vector<string> ans;
int n;
string a = "abcdefghijklmnopqrstuvwxyz";


void dfs(string s, int num, int k, char c){
    s += c;
    // cout << 2 << endl;
    // cout << num << endl;
    // cout << n << endl;
    if (num == n){
        ans.push_back(s);
        return;
    }
    
    for (int i = 0; i < k; i++){
        dfs(s, num + 1, k, a[i]);
    }
    dfs(s, num + 1, k + 1, a[k]);
}

int main(){
    cin >> n;
    string t = "";
    // cout << 1 << endl;
    dfs(t, 1, 1, a[0]);
    // cout << 1 << endl;
    rep(i, ans.size()){
        cout << ans[i] << endl;
    }
    // cout << ans.size() << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<long int> A;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    if(a%2==0){
      A.push_back(a);
    }
  }
  int count = 0;
  for(long int h: A){
    while(h%2==0){
      h/=2;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define np next_permutation
#define pq priority_queue
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    char c;
    scanf("%c",&c);
    if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o') puts("vowel");
    else puts("consonant");
    return 0;
}

Measured memory_bytes: 256