akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int,int> pii;
typedef std::pair<int,double> pid;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;



void solve(){
    ll n;
    cin >> n;
    
    
    ll sum = 0;
    for(ll i = 1; i*i <= n; i++){
        if (n%i == 0){
            ll m = n/i;
            if (m-1>i) sum += m-1;
        }
    }
    
    cout << sum;
    
}



int main(){
    int T;
    T = 1;
    // cin >> T;
    while(T--){
        solve();
        cout << endl;
    }
}





































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

using namespace std;

using ll = long long;

const int N = (int)1e5 + 5, LOG = 60;
int n, x[N], m, a[N], d[N], per[N], jump[N][LOG], finalPos[N], updPos[N], finalD[N];
ll K, ans[N];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", x + i);
    scanf("%d %lld", &m, &K);
    for (int i = 1; i <= m; ++i) scanf("%d", a + i);

    for (int i = 1; i <= n; ++i) d[i] = x[i] - x[i - 1];

    for (int i = 1; i <= n; ++i) per[i] = i;
    for (int i = 1; i <= m; ++i) swap(per[ a[i] ], per[ a[i] + 1 ]);
    for (int i = 1; i <= n; ++i) jump[ per[i] ][0] = i;

    for (int j = 1; j < LOG; ++j) {
        for (int i = 1; i <= n; ++i) jump[i][j] = jump[ jump[i][j - 1] ][j - 1];
    }

    for (int i = 1; i <= n; ++i) finalPos[i] = i;
    for (int j = LOG - 1; j >= 0; --j) if ( (K >> j) & 1) {
        for (int i = 1; i <= n; ++i) updPos[i] = jump[ finalPos[i] ][j];
        swap(finalPos, updPos);
    }

    for (int i = 1; i <= n; ++i) finalD[ finalPos[i] ] = d[i];

    for (int i = 1; i <= n; ++i) cout << (ans[i] = ans[i - 1] + finalD[i]) << '\n';

    return 0;
}


Measured memory_bytes: 28160
def main():
    s = input()
    s_list = list(s)
    stock = 0
    point = 0
    for i in s_list:
        if i == "g" and stock == 0:
            stock += 1
        elif i == "g" and stock > 0:
            stock -= 1
            point += 1
        elif i == "p" and stock == 0:
            stock += 1
            point -= 1
        elif i == "p" and stock > 0:
            stock -= 1
    print(point)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3956
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;
using namespace literals;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  for (int i = 0; i < N; ++i)
    cin >> s[i] >> t[i];
  string X;
  cin >> X;
  bool stopped = false;
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (stopped)ans += t[i];
    if (s[i] == X)stopped = true;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int len = s.size();
    long long ans = 0;
    for (int bit = 0; bit < (1 << (len - 1)); bit++)
    {
        long long num = 0;
        for (int i = 0; i < len; i++)
        {
            num = num * 10 + s[i] - '0';
            if (bit & (1 << i))
            {
                ans += num;
                num = 0;
            }
        }
        ans += num;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int a;
    cin >> a;
    string s;
    cin >> s;

    if (a >= 3200)
    {
        cout << s << endl;
    }
    else
    {
        cout << "red" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
 
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b)-1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep(i, n) for(int i = (n)-1; i >= 0; i--)
 
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define pii pair<int, int>
#define vi vector<int>
 
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T>& p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T>& vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
constexpr ll MOD = 1000000007;
 
 
 
int main()
{
    ll X;
    cin >>X;
    ll a =0;
    for(a = 1; ; a++){
        if(a *(a+1) >= 2*X){
            break;
        }
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  double N, X, T;
  cin >> N >> X >> T;
  cout << (ll)T*(ll)ceil(N/X) << endl;
  return 0;
}

Measured memory_bytes: 3816
a,b = gets.chomp.split(" ").map(&:to_i)
sa = (a.abs - b.abs).abs
hante = sa
hante = sa + 2 if(a>b and b>0)
hante = sa + 1 if(a>b and b<=0 and a>= 0)
hante = sa + 2 if(a>b and a<0)
hante = sa  if(a<b and a>=0)
if(a<b and a<0 and b>=0)
  hante = sa     if(b  == 0)
  hante = sa + 1 if(b != 0)
end
hante = sa  if(a<b and a<0 and b<0)
puts hante

Measured memory_bytes: 1788
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,n,m;
    cin >>n>>m;
    ans=n*m-(n+m)+1;

    dbg{
        if(true)cout <<"YES"<<endl;
        else cout <<"NO"<<endl;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
//Foods Loved by Everyone

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
const int inf = 2147483647;

int main (){
    int n,m;cin>>n>>m;
    vector<vector<int>> a(n);
    rep(i,0,n){
        int k;cin>>k;
        rep(j,0,k){
            int c;cin>>c;
            a[i].pb(c);
        }
    }
    vector<int> t(m);
    rep(i,0,n){
        rep(j,0,a[i].size()){
            t[a[i][j]-1]++;
        }
    }
    int ans=0;
    rep(i,0,m)if(t[i]==n)ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(6500)

N,M,K=map(int,input().split())

F=[[] for _ in range(N)]
B=[[] for _ in range(N)]
d=[-1]*N

def find(n):
    if d[n]<0:
        return n
    else:
        d[n]=find(d[n])
        return d[n]
def union(a,b):
    a=find(a)
    b=find(b)
    if a==b:return False
    if d[a]<=d[b]:
        d[a]+=d[b]
        d[b]=a
    else:
        d[b]+=d[a]
        d[a]=b
    return True

def same(a,b):
    if find(a)==find(b):return True
    else:return False


for i in range(M):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    union(a,b)
    F[a].append(b)
    F[b].append(a)

for i in range(K):
    a,b=map(int,input().split())
    B[a-1].append(b-1)
    B[b-1].append(a-1)

ans=[0]*N
for i in range(N):
    p=find(i)
    ans[i]=-d[p]-len(F[i])-1
    for b in B[i]:
        if same(i,b):
            ans[i]-=1
for i in ans:
    print(str(i),end=" ")


Measured memory_bytes: 45264
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define forn(i,n) for(int i=0;i<n;i++)
#define mod  1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

void solve() {

	int n;cin>>n;

	if(n==0)cout<<1<<endl;
	else cout<<0<<endl;


}

int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t; cin >> t;/
	int t = 1;

	while (t--) {
		solve();
	}

	return 0;
}

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

int main(){
    int n;
    long long int num =1;
    cin >> n;
    int temp;
    long long int mod = 1e9+7;
    vector<int> vec(n);

    for(int i=2;i<=n;i++){
        temp = i;
        for(int j=2;j<=i;j++){
            while(temp%j==0){
                vec.at(j-1)+=1;
                temp /= j;
            }
        }
    }

    for(int k=2;k<=n;k++){
        num *= (vec.at(k-1)+1);
        num %= mod;
    }

     cout <<  num << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>

int main(void){
	int n, sum;
	bool NGflag;
	// first... テ」ツ?敕」ツ?ョテ・ツウツカテ」ツ?ョテヲツゥツ凝」ツ?ョティツ?静、ツケツ?・ツ環? second... テ」ツ?敕」ツ?ョテ・ツウツカテ」ツ?ョテ・ツョツ敕」ツ?ョテゥツ??
	std::pair<int, int> bridge[30];

	while (true){
		scanf("%d", &n);
		if (n == 0){ break;	}

		// テ・ツ?・テ・ツ環崚」ツつ津・ツ渉療」ツ?妥・ツ渉姪」ツつ?
		for (int i = 0; i < n; i++){ scanf("%d%d", &bridge[i].second, &bridge[i].first); }
		std::sort(&bridge[0], &bridge[n]);

		// ティツィツ暗ァツョツ?
		sum = 0;
		NGflag = false;
		for (int i = 0; i < n; i++){
			sum += bridge[i].second;
			if (sum > bridge[i].first){
				NGflag = true;
				break;
			}
		}

		// テ・ツ?コテ・ツ環?
		if (NGflag){ printf("No\n"); }
		else{ printf("Yes\n"); }
	}

	return 0;
}

Measured memory_bytes: 1008
#include<stdio.h>
 
int MCMP(int);
 
int M[100],m[100][100];
 
int main(){
  int i, n, min;
  scanf("%d",&n);
 
  for(i = 0; i < n; i++) scanf("%d%d", &M[i], &M[i+1]);
 
  min = MCMP(n);
 
  printf("%d\n", min);
  
  return 0;
}
 
 
int MCMP(int n){
  int i, j, k, l, q;
 
  for(i = 1; i <= n; i++) m[i][i] = 0;
  
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n-l+1; i++){
      j = i+l-1;
      m[i][j] = 100000;
      
      for(k = i; k <= j-1; k++){
	q = m[i][k] + m[k+1][j] + M[i-1]*M[k]*M[j];
	
	if(m[i][j] > q) m[i][j] = q;
      }
    }
  }
  return m[1][n];
}



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

using namespace std;

int main() {
	int n, x = 0, max = 0;
	string S;

	cin >> n >> S;

	for (int i = 0; i < n; i++) {
		if (S[i] == 'I')x++;
		else x--;
		if (x > max)max = x;
	}

	cout << max << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    K,X = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    l=[i for i in range(max(X-K+1,-1000000),min(1000000,X+K-1)+1)]
    print(*l)



if __name__ == "__main__":
    main()

Measured memory_bytes: 77388
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,sum=0,ans=1;
  cin>>N;
  vector<int> A(N);
  for(int &i:A)cin>>i;
  sort(A.begin(),A.end());
  for(int i=0;i<N-1;i++){
    sum+=A[i];
    if(sum*2>=A[i+1])ans++;
    else ans=1;
  }
  cout<<ans<<endl;
}

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

using namespace std;

//#define MD 10

int main(){
   int w,h,n;
    cin>>w>>h>>n;
    vector<int> x(n),y(n),a(n);
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i]>>a[i];
    }
    int lx=0,rx=w,dy=0,uy=h;
    for(int i=0;i<n;i++){
        if(a[i]==1){
            lx=max(lx,x[i]);
        }else if(a[i]==2){
            rx=min(rx,x[i]);
        }else if(a[i]==3){
            dy=max(dy,y[i]);
        }else{
            uy=min(uy,y[i]);
        }
    }
    int ans=(rx-lx)*(uy-dy);
    if(rx<=lx || uy<=dy){
        ans=0;
    }
    cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int N,W;
int v[101],w[101];
int dp[101][10001];

int main(){
    cin >> N >> W;
    for(int i=0; i<N; i++) cin >> v[i] >> w[i];
    
    for(int j=0; j<W; j++) dp[0][j] = 0;
    
    for(int i=0; i<N; i++){
        for(int j=0; j<=W; j++){
            if(j < w[i]) dp[i+1][j] = dp[i][j];
            else dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
        }
    }
    cout << dp[N][W] << endl;    
}


Measured memory_bytes: 7056
#include<stdio.h>

int main(){
  int n,a[1000];
  int v;
  int i,j,k;

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

  for(i=0;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;
    for(k=0;k<n;k++){
      printf("%d",a[k]);
      if(k<n-1)
	printf(" ");
    }
    printf("\n");
  }

  
  return 0;
}

Measured memory_bytes: 1820
const fs = require('fs');

const main = () => {

    const input: string = fs.readFileSync('/dev/stdin', 'utf8').trim();
  	const inputArr = input.split("");
    let hugs = 0;
    for (let i = 0; i < Math.ceil(inputArr.length/2); i++) {
        if (inputArr[i] != inputArr[inputArr.length-1-i]) {
            hugs++;
        }
    }
    console.log(hugs);
};

main();


Measured memory_bytes: 7372
#include <stdio.h>

int main(void) {
  int a, b, c, k;
  int max = 0;

  scanf("%d %d %d %d", &a, &b, &c, &k);


  if (k <= a) {
    max = k;
  } else if (k <= a + b) {
    max = a;
  } else {
    max = a - (k - (a+b));
  }

  printf("%d\n", max);
  return 0;
}


Measured memory_bytes: 1736
# エラトステネスの篩
def make_prime_table(N):
    sieve = list(range(N + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(2, int(N ** 0.5) + 1):
        if sieve[i] != i:
            continue
        for j in range(i * i, N + 1, i):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


N = int(input())

prime_table = make_prime_table(100)

d = {}
for i in range(2, N + 1):
    while i != 1:
        d.setdefault(prime_table[i], 0)
        d[prime_table[i]] += 1
        i //= prime_table[i]

# 75 = 5 * 5 * 3
#    = 15 * 5
#    = 25 * 3
#    = 75
n74 = 0
n24 = 0
n14 = 0
n4 = 0
n2 = 0
for k in d:
    if d[k] >= 74:
        n74 += 1
    if d[k] >= 24:
        n24 += 1
    if d[k] >= 14:
        n14 += 1
    if d[k] >= 4:
        n4 += 1
    if d[k] >= 2:
        n2 += 1

result = 0
# x ^ 4 * y ^ 4 * z ^ 2 の約数の個数は75個
result += n4 * (n4 - 1) // 2 * (n2 - 2)
# x ^ 14 * y ^ 4 の約数の個数は75個
result += n14 * (n4 - 1)
# x ^ 24 * y ^ 2 の約数の個数は75個
result += n24 * (n2 - 1)
# x ^ 74 の約数の個数は75個
result += n74
print(result)


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

#define mod 1000000007

int main() {
    string S;
    cin >> S;

    vector<int>pow10mod13(S.size());
    pow10mod13[0] = 1;
    for (int i = 1; i < S.size(); ++i) {
        pow10mod13[i] = pow10mod13[i-1] * 10 % 13;
    }

    vector<int>any; // ?の重み
    any.reserve(S.size());
    int s_mod13 = 0; // ?を全部0にした時のs mod13
    for (int i = 0; i < S.size(); ++i) {
        if(S[i] == '?'){
            any.push_back(pow10mod13[S.size()-i-1]);
        } else{
            s_mod13 += pow10mod13[S.size()-i-1] * (S[i] - '0');
            s_mod13 %= 13;
        }
    }

    // dp[i][j]はanyのi番目(1-indexed)まででj mod13になる場合の数
    vector<vector<ll>> dp(any.size()+1, vector<ll>(13, 0));
    dp[0][0] = 1;
    for (int i = 1; i < any.size() + 1; ++i) {
        for (int j = 0; j < 13; ++j) {
            for (int k = 0; k < 10; ++k) {
                int ka = k * any[i-1] % 13;
                int ja = j + 13 - ka; // ja + ka = j
                ja %= 13;
                dp[i][j] += dp[i-1][ja];
                dp[i][j] %= mod;
            }
        }
    }
    int target = 5 + 13 - s_mod13;
    target %= 13;
    cout << dp[any.size()][target];
    return 0;
}

Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<vector<ll>> v;
ll n, m, q;
void dfs(ll n, char mx, string s){
    if(ll(s.size()) == n){
        vector<ll> vv;
        REP(i, s.size()){
            if(s[i] == 'q') vv.pb(1);
            if(s[i] == 'r') vv.pb(2);
            if(s[i] == 's') vv.pb(3);
            if(s[i] == 't') vv.pb(4);
            if(s[i] == 'u') vv.pb(5);
            if(s[i] == 'v') vv.pb(6);
            if(s[i] == 'w') vv.pb(7);
            if(s[i] == 'x') vv.pb(8);
            if(s[i] == 'y') vv.pb(9);
            if(s[i] == 'z') vv.pb(10);
        }
        v.pb(vv);
        return;
    }
    for(char c=mx; c<='z'-(10-m); c++){
        if(c > mx) dfs(n, c, s+c);
        else dfs(n, mx, s+c);
    }
}

void solve(){
    cin >> n >> m >> q;
    for(char c='q'; c<='z'; c++){
        string s;
        s += c;
        dfs(n, c, s);
    }
    vector<ll> a, b, c, d;
    REP(i, q){
        ll ina, inb, inc, ind;
        cin >> ina >> inb >> inc >> ind;
        a.pb(ina-1); b.pb(inb-1); c.pb(inc); d.pb(ind);
    }
    //cout << v << endl;
    ll res = 0;
    REP(i, v.size()){
        ll tmp = 0;
        REP(j, q){
            if(v[i][b[j]] - v[i][a[j]] == c[j]){
                tmp += d[j];
            }
        }
        //cout << tmp << endl;
        res = max(res, tmp);
    }
    cout << res << endl;
}

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

Measured memory_bytes: 13908
//heep and Wolves

#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
const int INF = 1 << 29;
int main ()
{
    int S,W;
    cin >> S >> W;
    if (S > W) {
        cout << "safe";
    }
    else {
        cout << "unsafe";
    }
    return 0;
}

Measured memory_bytes: 3132
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=100005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int dp[101][N];
int32_t main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    int ar[n+1];
    for(int i=1;i<=n;i++)
    cin>>ar[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        dp[i-1][j]=(dp[i-1][j]+dp[i-1][j-1])%mod;
        for(int j=0;j<=k;j++)
        {
            dp[i][j]=dp[i-1][j];
            if((j-ar[i]-1)>=0)
            dp[i][j]=(dp[i][j]-dp[i-1][j-ar[i]-1]+mod)%mod;
        }
    }
    cout<<dp[n][k];
}

Measured memory_bytes: 82560
def read():
    N, H, W = list(map(int, input().strip().split()))
    A = []
    B = []
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, H, W, A, B


def solve(N, H, W, A, B):
    count = 0
    for i in range(N):
        if A[i] >= H and B[i] >= W:
            count += 1
    return count


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
    int a,b,c,d;
    
    scanf("%d%d%d%d",&a,&b,&c,&d);
    
    if (d==1){
    
    printf("1\n");
    } else {
        printf("0\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
/*
*/
#include<bits/stdc++.h>
using namespace std;
#define maxn 300010
#define ll long long
#define pii pair<ll,ll>
int a[maxn]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51} ;
int main()
{
	ios::sync_with_stdio(false);
	ll n,m;cin>>n>>m;
	if(n==1||m==1) cout<<1<<endl;
	else
	cout<<(n*m+1)/2<<endl;
	return 0;
}



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

int main() {
  int x,y;
  cin>>x>>y;
  bool ans=false;
  for(int t=0;t<=x;t++){
    int k=x-t;
    if(2*t+4*k==y)ans=true;
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main() {
  string s;
  cin >> s;
  vector<char> S = {s[0],s[1],s[2],s[3]};
  sort(S.begin(),S.end());
  if((S[0]==S[1])&&(S[2] == S[3])&&(S[1] != S[2])) {
  	cout << "Yes" << endl;
  }
  else {
  	cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;

int m,n,w,h;

char b[102][102];
bool v[102][102];

void dfs(int y,int x){
    if(v[y][x]){cout<<"LOOP"<<endl;return;}
    v[y][x]=1;
    if(b[y][x]=='>')
        return dfs(y,x+1);
    if(b[y][x]=='v')
        return dfs(y+1,x);
    if(b[y][x]=='<')
        return dfs(y,x-1);
    if(b[y][x]=='^')
        return dfs(y-1,x);
    if(b[y][x]=='.')
        cout<<x<<" "<<y<<endl;
}
int main(){
    
    while(cin>>h>>w,w||h){
        for(int i=0;i<h;i++)
            cin>>b[i];
        memset(v,0,sizeof(v));
        dfs(0,0);
    }
}

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

int main() {
  int a;
  int b;
  
  cin >> a >> b;
  
  if (a + b >= 24) {
    cout << a + b - 24 << endl;
  }
  else if (a + b < 24) {
    cout << a + b << endl;
  }
}


Measured memory_bytes: 256
grid = [list(map(int, input().split())) for _ in range(3)]


for i in range(3):
    c = grid[i][0]
    for j in range(3):
        grid[i][j] -= c

ans = 'Yes' if grid[0] == grid[1] and grid[1] == grid[2] else 'No'
print(ans)


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

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

const int mod = 1e9 + 7;

int N, M, S, T;
vector<pii> adj[100010];
ll Sdist[100010], Tdist[100010];
priority_queue<pair<ll, int> > pq;

void dijkstra(int st, ll *dist) {
    for(int i = 0; i < N; i++) dist[i] = 1e18;
    pq.push(make_pair(0, st));
    dist[st] = 0;
    while(!pq.empty()) {
        int u = pq.top().second;
        ll ud = -pq.top().first;
        pq.pop();

        if(ud > dist[u]) continue;

        for(int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i].first;
            ll vd = adj[u][i].second;

            if(dist[v] > ud + vd) {
                dist[v] = ud + vd;
                pq.push(make_pair(-dist[v], v));
            }
        }
    }
}

int Sdp[100010], Tdp[100010], vis[100010];

void Sdfs(int u, int dest) {
    vis[u] = 1;
    if(u == dest) {
        Sdp[u] = 1;
        return;
    }
    Sdp[u] = 0;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i].first;
        int d = adj[u][i].second;

        if(Sdist[u] + d == Sdist[v]) {
            if(!vis[v]) Sdfs(v, dest);
            Sdp[u] += Sdp[v];
            Sdp[u] %= mod;
        }
    }
}
void Tdfs(int u, int dest) {
    vis[u] = 1;
    if(u == dest) {
        Tdp[u] = 1;
        return;
    }
    Tdp[u] = 0;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i].first;
        int d = adj[u][i].second;

        if(Tdist[u] + d == Tdist[v]) {
            if(!vis[v]) Tdfs(v, dest);
            Tdp[u] += Tdp[v];
            Tdp[u] %= mod;
        }
    }
}

int main() {
    scanf("%d %d %d %d", &N, &M, &S, &T);
    S--; T--;

    for(int i = 0; i < M; i++) {
        int u, v, d; scanf("%d %d %d", &u, &v, &d);
        u--; v--;

        adj[u].push_back(pii(v, d));
        adj[v].push_back(pii(u, d));
    }

    dijkstra(S, Sdist);
    dijkstra(T, Tdist);
    Sdfs(S, T);

    memset(vis, 0, sizeof(vis));
    Tdfs(T, S);

    int ans = 1LL * Sdp[S] * Sdp[S] % mod;

    for(int i = 0; i < N; i++) if(Sdist[i] == Tdist[i]) {
        int tmp = 1LL * Sdp[i] * Tdp[i] % mod;

        ans += mod - 1LL * tmp * tmp % mod;
        ans %= mod;
    }

    for(int u = 0; u < N; u++) {
        for(int i = 0; i < adj[u].size(); i++) {
            int v = adj[u][i].first;
            int d = adj[u][i].second;

            if(Sdist[u] + d == Sdist[v] && Tdist[v] + d == Tdist[u] && !(Tdist[u] <= Sdist[u] || Sdist[v] <= Tdist[v])) {
                int tmp = 1LL * Tdp[u] * Sdp[v] % mod;

                ans += mod - 1LL * tmp * tmp % mod;
                ans %= mod;
            }
        }
    }

    printf("%d", ans);
}


Measured memory_bytes: 18044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll N;
  cin >> N;
  ll A,B,C,D;
  cin >> A >> B >> C >> D;
  ll st = (N - 1) * D;
  if (A+st < B || A-st > B) {
    cout << "NO" << endl;
    return 0;
  }
  ll d = D-C;
  ll blank = (2*D) - (N*d) - 1;
  if (blank <= 0) {
    cout << "YES" << endl;
    return 0;
  }
  ll left = A + st - ((N-1) * d);
  ll right = A + st;
  left %= 2*D - d;
  right %= 2*D - d;
  ll per = B % (2*D - d);
  if (left > right) {
    right += 2*D - d;
  }
  ll per2 = per + 2*D - d;
  if (left <= per && per <= right) {
    cout << "YES" << endl;
    return 0;
  } else if (left <= per2 && per2 <= right) {
    cout << "YES" << endl;
    return 0;
  } else {
    cout << "NO" << endl;
    return 0;
  }
  return 0;
}

Measured memory_bytes: 256
def bubbleSort(A,N):
    flag = True
    count = 0
    while flag:
        flag = False
        for j in range(N-1,0,-1):
            if A[j] < A[j-1]:
                v = A[j]
                A[j] = A[j-1]
                A[j-1] = v
                count += 1
                flag = True
    return count

n = int(input())
x = input().split()
y=[]
for i in range(n):
    y += [int(x[i])]
    
count = bubbleSort(y,n)
for j in range(n-1):
    print(y[j],end=' ')
print(y[n-1])
print(count)



Measured memory_bytes: 5612
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if(s < t){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3604
package main

import "fmt"

func main() {
	var (
		a, b int
		s    string
	)
	for {
		fmt.Scanln(&a, &s, &b)
		if s == "?" {
			break
		}
		ans := 0
		switch s {
		case "+":
			ans = a + b
		case "-":
			ans = a - b
		case "/":
			ans = a / b
		case "*":
			ans = a * b
		}
		fmt.Println(ans)
	}
}


Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
 
ll MOD = 1000000007;
ll INF =1<<29;
ll dp[100100];
 
int main() {
     int n,m,c;
     cin >> n >> m >>c;
     int ans = 0;
     vector<int> b(m);
     rep(i,m) cin >> b[i];
     rep(i,n){
        int count = 0;
        vector<int> a(m);
        rep(i,m){ cin >> a[i];
        count+=a[i]*b[i];}
        if(count+c>0) ans ++;
     }
     cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    map<char, char> mp{{'A', 'T'}, {'T', 'A'}, {'C', 'G'}, {'G', 'C'}};

    char c;
    cin >> c;
    print(mp[c]);

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    N, A, B = [int(x) for x in input().split()]
    X = [int(x) for x in input().split()]

    ans = 0
    for i, j in zip(X, X[1:]):
        ans += min((j - i) * A, B)

    print(ans)

    
    
    

if __name__ == '__main__':
    main()





Measured memory_bytes: 14252
#include <cstdio>
#include <bitset>
std::bitset<405> mask[405];
int x[100005], y[100005];
bool fail[405];
int main()
{
	// freopen("AGC016-E.in", "r", stdin);
	int n, m, ans = 0;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		scanf("%d%d", x + i, y + i);
		x[i]--;
		y[i]--;
	}
	for (int i = 0; i < n; i++)
	{
		mask[i].set(i);
		for (int j = m - 1; j >= 0 && !fail[i]; j--)
		{
			if (mask[i].test(x[j]) && mask[i].test(y[j]))
				fail[i] = true;
			else if (mask[i].test(x[j]) ^ mask[i].test(y[j]))
			{
				mask[i].set(x[j]);
				mask[i].set(y[j]);
			}
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
			ans += !fail[i] && !fail[j] && !(mask[i] & mask[j]).count();
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1024
// IOI 2021
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
 
////////////////////////////////////////////////////////////////////
 
const int N = 2e5 + 5;

int A[N];

int main() {
 
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));

	int n; cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i];
	if (A[0] != 0) die(-1);
	for (int i = 1; i < n; i++) if (A[i] - A[i - 1] > 1) die(-1);
	ll res = 0;
	for (int i = 1; i < n; i++) if (A[i] == A[i - 1] + 1) res++; else res += A[i];
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 4424
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
#define inf 101010
typedef pair<int,int> pii;
typedef pair<double,pii> pp;

int main(void){
    int n,m,p,a,b;
    while (cin>>n>>m>>p>>a>>b && n) {
        a--, b--;
        vector<int> t(n);
        for (int i = 0; i < n; i++) cin >> t[i];
        vector<vector<pii> > g(m, vector<pii>());
        for (int i = 0; i < p; i++) {
            int x,y,z;
            cin>>x>>y>>z;
            x--, y--;
            g[x].push_back(make_pair(y,z));
            g[y].push_back(make_pair(x,z));
        }
        
        vector<vector<double> > d(m, vector<double>(1<<n, inf));
        priority_queue<pp, vector<pp>, greater<pp> > que;
        que.push(make_pair(0.0, make_pair(a, (1<<n)-1)));
        
        double ans = inf;
        while (!que.empty()) {
            pp p = que.top(); que.pop();
            double cost = p.first;
            int cur = p.second.first, bit = p.second.second;
            if (cur == b) {
                ans = cost;
                break;
            }
            
            for (int i = 0; i < g[cur].size(); i++) {
                int to = g[cur][i].first, len = g[cur][i].second;
                for (int j = 0; j < n; j++) {
                    if (bit & 1<<j) {
                        double x = len / (double)t[j];
                        int nbit = bit & ~(1<<j);
                        if (cost+x >= d[to][nbit]) continue;
                        d[to][nbit] = cost+x;
                        que.push(make_pair(cost+x, make_pair(to, nbit)));
                    }
                }
            }
        }
        if (ans == inf) cout << "Impossible" << endl;
        else printf("%.8lf\n",ans);
    }
}

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

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  
  int p = x2+(y1-y2);
  int q = y2+(x2-x1); 
  int r = x1+(y1-y2);
  int s = y1+(x2-x1);
  cout << p << " " <<  q << " " << r << " " << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
     int k;
      cin>>k;
      long long int sum=0;
      for(int i=1;i<=k;i++)
      {
          for(int j=1;j<=k;j++)
          {
              for(int z=1;z<=k;z++)
              {
                  sum+=__gcd(__gcd(i,j),z);
              }
              
          }
      }
      cout<<sum<<endl;
      
    }

Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);

	int h,w,n,a;
	cin >> h;
	cin >> w;
	cin >> n;
	if (h < w) a = n / w;
	a = (n - 1) / max(h, w) + 1;  
	cout << a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INFTY 10000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
const int di[4] = {-1,0,1,0};
const int dj[4] = {0,-1,0,1};
 
int main(){
   string s,t;cin>>s>>t;
   int cnt=0;
   rep(i,s.size()){
       if(s[i]!=t[i])cnt++;
   }
   cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,y;
    cin>>n>>y;
    int coun;
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
          coun=y-10000*i-5000*j;
          if(coun%1000==0&&coun/1000>=0&&coun/1000==n-i-j){
            cout<<i<<" "<<j<<" "<<coun/1000<<endl; 
            return 0;
          }
      }
    }
    cout<<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
typedef long long int ld;
typedef unsigned long long int lu;
typedef vector< int > vi;
typedef vector < ld > vd;
typedef set <ld> sd;
typedef vector< vi > vvi;
typedef vector< vd > vvd;
typedef pair< int,int > ii;
typedef pair< ld,ld > id;
#define sz(a) ld((a).size())
#define test(t) ll t;cin>>t;while(t--)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define Vi vector
#define pr pair
#define mpr make_pair
#define fi first
#define se second
#define isnum(a) (a>=48 && a<=57)
#define isS(a) (a>='a' && a<='z')
#define isU(a) (a>='A' && a<='Z')
#define toS(a) (isU(a)?a+32:a)
#define toU(a) (isS(a)?a-32:a)
#define toC(a) a&15

set <ld> s[100005];
ld d[100005];

vector<char> prime (100000+1, true);
void sieve(ld n)
{	
	//O(nloglogn) time
	prime[0] = prime[1] = false;
	for (ld i=2; i<=n; ++i)
	{
		if (prime[i])
		{
			s[i].insert(i);			
			for (ld j=2*i; j<=n; j+=i)
			{
				prime[j] = false;
				s[j].insert(i);
			}
		}
	}
}
#define forn(i,e) for(int i = 0; i < e; i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define reprev(i,a,b) for(i=a;i>=b;i--)

#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
ld gcd(ld a, ld b) { if(b == 0) return a; return gcd(b, a % b); }
ld fastpowMOD(ld a, ld p,ld MOD){ if(p==0) return 1; ld z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
ld fastpow(ld a, ld p){ if(p==0) return 1; ld z = fastpow(a,p/2); z = (z*z); if(p%2) z = (z*a); return z; }
ld a,b;

ld search1(ld a[], ld f,ld n)
{
	ld left=1;
	ld right=n+1;
	while(right-left>1)
	{
		ld mid = left + (right-left)/2;
		if(a[mid]<f)
		{
			left=mid;
		}
		else right=mid;
	}
	return a[left];
}

int main(){
	ld n,k,i,j;
	cin >> n >> k;
	ld ar[n];
	rep(i,0,n)cin >> ar[i];
	ld dp[k+1];
	memset(dp,0,sizeof(dp));
	dp[0]=-1;
	REP(i,1,k)
	{
		dp[i] = -1;
		rep(j,0,n)
		{
			if(ar[j]>i)break;
			if(dp[i-ar[j]]==-1){dp[i]=1;break;}
		}
	}
	if(dp[k]==-1)cout << "Second" << endl;
	else if(dp[k]==1)cout << "First" << endl;
	return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

string S;

signed main(){
	cin>>S;
	int l=0,r=S.size()-1;
	int ans=0;
	while(l<r){
		if(S[l]==S[r]){
			l++,r--;
		}
		else if(S[l]=='x'){
			l++;
			ans++;
		}
		else if(S[r]=='x'){
			r--;
			ans++;
		}
		else{
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
int books[10010]={0};
int dp[10000][1000];

#define INF 999999
void dfs(int x,int y);
char stage[16][16];
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};
int main(){
    char x;
    bool f = ~false;
	while(1){
		for(int i = 0; i < 12; i++){
			scanf("%s",stage[i]);
		}
		int ans = 0;
		for(int i = 0; i < 12; i++){
			for(int j = 0; j < 12; j++){
				if(stage[i][j] == '1'){
                    dfs(j,i);
                    ans++;
				}
			}
		}
		printf("%d\n",ans);
		memset(stage,0,sizeof(stage));
		x = getchar();
		x = getchar();
		if(x == EOF)break;
	}
	return 0;
}
void dfs(int x,int y){
	stage[y][x] = '0';
	for(int i = 0; i < 4; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if(nx < 0 || nx > 11 || ny < 0 || nx > 11)continue;
		if(stage[ny][nx] == '1'){
            stage[ny][nx] = '0';
            dfs(nx , ny);
		}
	}
	return ;
}

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

using namespace std;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

    //ios::sync_with_stdio(0);
    //cin.tie(0);
    int n;
    cin>>n;
    double vec[n];
    double sum=0,rec;
    for(int i=0;i<n;i++){
        cin>>vec[i];
        rec=1000/vec[i];
        sum=sum+rec;
    }
    double ans;
    ans=1000/sum;
    cout<<ans<<endl;



	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline char CH()
{
  static char buf[100000],*ptr1=buf,*ptr2=buf;
  return ptr1==ptr2&&(ptr2=(ptr1=buf)+fread(buf,1,100000,stdin),ptr1==ptr2)?EOF:*ptr1++;
}
static inline int IN(void)
{
  int x=0,f=0,c=CH();while(c<48||c>57){f^=c==45,c=CH();}
  while(c>47&&c<58){x=x*10+c-48,c=CH();}return f?-x:x;
}
static inline void OUT(int x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline int min(const int a,const int b){return a<b?a:b;}
int main(void)
{
  int N=IN(),a=0,d,p,q,xy,que[250000],vacant[262144];
  unsigned char dist[262144];
  rep(i,N)
  {
    xy=(N+2)*(i+1)+1;
    unsigned char across=min(i,N-1-i),down=3;
    rep(j,across){dist[xy++]=down++;}
    rep(j,N-2*across){dist[xy++]=across+3;}
    rep(j,across){dist[xy++]=--down;}
  }
  rep(i,N*N)
  {
    xy=IN();xy+=((xy-1)/N)*2+N+2;a+=dist[xy];p=0,q=0;
    que[p++]=xy;vacant[xy]=1;
    while(p>q)
    {
      xy=que[q++],d=dist[xy]-vacant[xy]+1;
      if(dist[xy-N-2]>d){dist[xy-N-2]=d;que[p++]=xy-N-2;}
      if(dist[xy+N+2]>d){dist[xy+N+2]=d;que[p++]=xy+N+2;}
      if(dist[xy-1]>d){dist[xy-1]=d;que[p++]=xy-1;}
      if(dist[xy+1]>d){dist[xy+1]=d;que[p++]=xy+1;}
    }
  }
  OUT(a-3*N*N);return puts(""),0;
}

Measured memory_bytes: 3736
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		String N = sc.next();
		int count = 1;
		char c = N.charAt(0);
		
		for(int i = 1; i < 4; i++){
			if(N.charAt(i) == c){
				count++;
				if(count == 3){
					System.out.println("Yes");
					return;
				}
			} else {
				count = 1;
				c = N.charAt(i);
			}
		}
		
		System.out.println("No");
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);
        
        String[] a = sc.nextLine().split(" ");
        int[] men = new int[a.length];
        for (int i = 0; i < a.length; i++) {
            men[i] = Integer.parseInt(a[i]);
        }

        Dice dice = new Dice(men);

        String[] words = sc.nextLine().split("");
        for (String w : words) {
            if ( w.equals("N") ) { 
                dice.turnN(); 
            } else if ( w.equals("E") ) { 
                dice.turnE(); 
            } else if ( w.equals("S") ) { 
                dice.turnN(); 
                dice.turnN(); 
                dice.turnN(); 
            } else if ( w.equals("W") ) { 
                dice.turnE(); 
                dice.turnE(); 
                dice.turnE(); 
            }
        }

        System.out.println(dice.top);
    }
}

class Dice {
    int top, front, right, left, back, bottom;

    public Dice(int[] men){
        this.top = men[0];
        this.front = men[1];
        this.right = men[2];
        this.left = men[3];
        this.back = men[4];
        this.bottom = men[5];
    }

    void turnN() {
        int tmp = this.top;
        this.top = this.front;
        this.front = this.bottom;
        this.bottom = this.back;
        this.back = tmp;
    }
    void turnE() {
        int tmp = this.top;
        this.top = this.left;
        this.left = this.bottom;
        this.bottom = this.right;
        this.right = tmp;
    }
}



Measured memory_bytes: 26356