akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        if (N % K == 0) {
            System.out.println(0);
        } else {
            System.out.println(1);
        }
        sc.close();
    }
}

Measured memory_bytes: 21844
list_a = [int(input())]
while list_a[-1] < 1000001:
  if list_a[-1] % 2 == 0:
    temp = int(list_a[-1] / 2)
  else:
    temp = 3 * list_a[-1] + 1
  if temp in list_a:
    print(len(list_a) + 1)
    exit()
  else:
    list_a.append(temp)


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

int main(void) {
  vector<int> num(3);

  cin >> num.at(0) >> num.at(1) >> num.at(2);

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

  cout << num.at(1)-num.at(0) + num.at(2)-num.at(1) << endl;
}

Measured memory_bytes: 256
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd

n = ni()
ans= 0
for i in range(1,n+1):
    d = n//i
    ans+= d*(2*i + (d-1)*i)//2
print(ans)


Measured memory_bytes: 83160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int fx[]={1,-1,0,0},fy[]={0,0,1,-1};
struct node{
	int x,y;
};
int n,m,ans=0;
int d[25][25];
char p[25][25];
bool vis[25][25];
queue<node> q;
int main(){
	memset(p,0x3f,sizeof(p));
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>p[i][j];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(p[i][j]=='#') continue;
			memset(d,0,sizeof(d));
			memset(vis,0,sizeof(vis));
			q.push((node){i,j});
			vis[i][j]=1;
			while(!q.empty()){
				node no=q.front();
				q.pop();
				for(int k=0;k<4;k++){
					int nx=no.x+fx[k],ny=no.y+fy[k];
					if(nx<n&&ny<m&&nx>=0&&ny>=0&&p[nx][ny]=='.'&&!vis[nx][ny]){
						vis[nx][ny]=1;
						d[nx][ny]=d[no.x][no.y]+1;
						ans=max(d[nx][ny],ans);
						q.push((node){nx,ny});
					}
				}
			}
		}
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 3796
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		String S =nextString();
		String T =nextString();

		S+=S;
		String ans = "No";
		for(int i=0;i<T.length();i++){
			if(T.equals(S.substring(i,T.length()+i))){
				ans="Yes";
				break;
			}
		}
		System.out.println(ans);
	}




	public static String[] toStringArray(String s){
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for(int i=0;i<tmp.length;i++){
			tmp[i]=String.valueOf(c[i]);
		}
		return tmp;
	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 23252
#include<stdio.h>


int main(int argc, char const *argv[])
{
	int A,B,C,D,area1,area2;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	area1=1;
	area2=1;
	area1=A*B;
	area2=C*D;
	printf("%d",area1>area2?area1:area2 );
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		String S = sc.next();
		System.out.println(S.charAt(2) == S.charAt(3) && S.charAt(4) == S.charAt(5)? "Yes":"No");
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 21844
a=str(input())
b=str(input())
if len(a)>len(b):
    print("GREATER")
elif len(a)<len(b):
    print("LESS")
elif a==b:
    print("EQUAL")
else:
    for i in range(len(a)):
        if int(a[i]>b[i]):
            print("GREATER")
            break
        elif int(a[i]<b[i]):
            print("LESS")
            break

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

int main(){
  int n;
  long long w;
  cin>>n>>w;
  long long wei[n+5], val[n+5];
  for(int i=0; i<n; ++i)cin>>wei[i]>>val[i];

  const long long inf=1LL<<60;
  long long dp[n+10][100100];
  for(int i=0; i<n+10; ++i)for(int j=0; j<100100; ++j)dp[i][j]=inf;

  for(int j=0; j<100001; ++j){
    if(j<=val[0])dp[0][j]=wei[0];
  }
  dp[0][0]=0;

  for(int i=1; i<n; ++i){
    for(int j=0; j<100001; ++j){
      if(j-val[i]>=0)dp[i][j]=min(dp[i-1][j], dp[i-1][j-val[i]]+wei[i]);
      else dp[i][j]=dp[i-1][j];
    }
  }

  long long ans=0;
  for(int j=0; j<100010; ++j){
    if(dp[n-1][j]<=w)ans=j;
  }  

  cout<<ans<<endl;
}


Measured memory_bytes: 86272
#include <iostream>
using namespace std;
int main(void){
	int A,B;
	cin >> A >> B;
	if(A==1){
		if(B==1)cout << "Draw";
		else cout <<"Alice";
		return 0;
	}
	if(B==1){
		if(A==1)cout <<"Draw";
		else cout <<"Bob";
		return 0;
	}
	if(A==B)cout << "Draw";
	else if(A>B)cout << "Alice";
	else cout <<"Bob";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

    public void solve() {

        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        int k = sc.nextInt();

        Set<String> subStringsSet = new HashSet<>();
        for (int i = 0; i < s.length(); i++) {
            for (int j = 1; j <= 5; j++) {
                if (i + j > s.length()) break;
                subStringsSet.add(s.substring(i, i + j));
//                System.out.println(s.substring(i, i + j));
            }
        }

        ArrayList<String> subStringsList = new ArrayList<>(subStringsSet);
        Collections.sort(subStringsList);

        System.out.println(subStringsList.get(k - 1));
    }

}


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

using namespace std;

typedef long long ll;
#define pb push_back

const int MAX=1e5+5;
const ll MOD=1e9+7;
/*
We have k colors for the root node, for its children we have k-1 colors.
For any other node, we have k-2 choices.
We initialize ans with k as we can select any one of the k colors for the root
node.
We then run a dfs from the root node which was chosen arbitrarily.
In each iteration of the for loop we decrease the value of available colors by 1
as after running dfs on one of its children, we have given it a color, we then have 
one less choice for the other children as all the children of the current node
will be at a distance of two from each other.
parent -> colavail-1 for first child, colavail-2 for second and so on... 
*/

ll ans=1;

vector<vector<int> > adj(MAX);

void solve(int p,int col,int u){
  int colavail=col-1;
  if(p>0){
    --colavail;
  }
  for(auto i:adj[u]){
    if(i==p){
      continue;
    }
    if(colavail<=0){
      ans=0;
      return;
    }
    ans=ans*((ll)colavail);
    ans=ans%MOD;
    colavail-=1;
    solve(u,col,i);
  }
}

int main(){
  int n,k;
  cin>>n>>k;
  for(int i=0;i<n-1;i++){
    int s,d;
    cin>>s>>d;
    adj[s].pb(d);
    adj[d].pb(s);
  }
  ans=k;
  solve(-1,k,1);
  cout<<ans;
}

Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_set>

int main(){
    std::unordered_set<int> s;
    std::vector<int> v;
    int num;
    std::cin >> num;
    int max = 0;
    for(int i = 0; i < num; ++i){
        int val;
        std::cin >> val;
        v.push_back(val);
    }

    int count = 0;
    for(auto itr = v.begin(); itr != v.end(); ++itr){
        int data = *itr;
        if(data < 2) continue;
        if(data == 2){
            count++;
            continue;
        }
        if(data % 2 == 0) continue;
        if(s.find(data) != s.end()){
            count++;
            continue;
        }
        int sqrtNum = std::sqrt(data);
        bool isPrime = true;
        for(int i = 3; i <= sqrtNum; i+= 2){
            if(data % i == 0){
                isPrime = false;
                break;
            }
        }
        if(!isPrime) continue;
        count++;
        s.insert(data);
    }

    std::cout << count << std::endl;
}


Measured memory_bytes: 3256
// finish date: 2019/11/24

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1000000007;
const long long INFll = 100000000000000000;


int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    rep(i, S.length()) {
        S[i] = 'A' + ((S[i] - 'A') + N) % 26;
    }
    cout<<S<<endl;

    return 0;
}


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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
        int n, m; cin >> n >> m;
        vector<pair<int, int>> a(m);
        forn(i, m) 
        {
                int l, r; cin >> l >> r;
                a[i] = {l, r};
        }
        int l = 0, r = INT_MAX;
        for (int i = 0; i < m; ++i)
        {
                if (a[i].first > l) l = a[i].first;
                if (a[i].second < r) r = a[i].second;

        }
        if (l > r) cout << 0 << endl;
        else
        {
                cout << r - l + 1 << endl;
        }
        
}

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


Measured memory_bytes: 3972
from functools import reduce
import bisect

N, X = map(int, input().split())
x = list(map(int, input().split()))

def gcd(a,b):
    while b != 0:
        a,b = b,a%b
    return a

x.sort()
bisect.insort_left(x, X)

# 都市と出発点の区間の長さの最大公約数が解
diff = [abs(x[idx] - x[idx-1]) for idx in range(1,N+1)]
print(reduce(gcd,diff))

Measured memory_bytes: 14748
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
using namespace std;
int n;
pair<int,P> p[100005];
signed main(){
	cin>>n;
	rep(i,n){
		cin>>p[i].second.first>>p[i].second.second;
		p[i].first=p[i].second.first+p[i].second.second;
	}
	sort(p,p+n);
	reverse(p,p+n);
	int ta=0,ao=0;
	rep(i,n){
		if(i%2==0){
			ta+=p[i].second.first;
		}else {
			ao+=p[i].second.second;
		}
	}
	cout<<ta-ao<<endl;
}


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

int main(){
    string s;
    cin>>s;
    bool ok = true;
    rep(i,s.length()){
        if((i+1)%2==0&&s[i]=='R')ok=false;
        if((i+1)%2==1&&s[i]=='L')ok=false;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int n,m,ans,c[3010][3010]={};
int i,j,a[3010],b[3010],d[3010][3010]={};
int main(){
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)scanf("%d %d",&a[i],&b[i]);
  for(i=0;i<n;i++){
    for(j=0;j<=m;j++){
      if(j)c[i][j]=MAX(c[i][j],c[i][j-1]);
      c[i+1][j]=MAX(c[i+1][j],c[i][j]);
      if(j+a[i]<=m)c[i+1][j+a[i]]=MAX(c[i+1][j+a[i]],c[i][j]+b[i]);
    }
    //for(j=0;j<=m;j++)printf("%d ",c[i][j]);printf("\n");
  }//printf("\n");
  /*for(i=0;i<=n;i++){
    for(j=0;j<=m;j++)printf("%d ",c[i][j]);printf("\n");
    }printf("\n");//*/
  for(i=n;i--;i){
    for(j=0;j<=m;j++){
      if(j)d[i+1][j]=MAX(d[i+1][j],d[i+1][j-1]);
      d[i][j]=MAX(d[i][j],d[i+1][j]);
      if(j+a[i]<=m)d[i][j+a[i]]=MAX(d[i][j+a[i]],d[i+1][j]+b[i]);
    }
    //for(j=0;j<=m;j++)printf("%d ",d[i][j]);printf("\n");
  }//printf("\n");
  /*for(i=0;i<=n;i++){
    for(j=0;j<=m;j++)printf("%d ",d[i][j]);printf("\n");
    }printf("\n");//*/
  ans=c[n][m];
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      ans=MAX(ans,c[i][j]+d[i+1][m-j-1]+b[i]);
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 70912
#pragma GCC target ("avx512f")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;

int main()
{
ll n;
cin >> n ;
vector<vector<ll>> g(n);
rep(i, n-1)
{
  ll a, b;
  cin >> a >> b;
  g[a].push_back(b);
  g[b ].push_back(a);
}
ll root;
rep(i,n+1){
  if(i==n){
    cout << 1 << endl;
    return 0;
  }
  if(g[i].size()>2){root=i;break;}
}
vector<vector<ll>> child(n);
vector<ll> par(n);
vector<bool> k(n);
queue<ll> q;
queue<ll> qq;
q.push(root);
par[root]=-1;
//親の定義と葉を見つける
while(!q.empty()){
  ll p=q.front();
  q.pop();
  if(g[p].size()==1 && p!=root){qq.push(p);}
  for(auto r:g[p]){
    if(r==par[p])continue;
    par[r]=p;
    q.push(r);
  }
}
while(!qq.empty()){
  ll p=qq.front();
  qq.pop();
  child[par[p]].push_back(p);//親に値を追加する
  //根の時は例外処理
  if(child[par[p]].size()==g[par[p]].size()){
    //child[par[p]]に子の値が入ってる
    ll cnt=0;
    for(auto r:child[par[p]]){
      if(k[r])cnt++;
    }
    if(cnt<child[par[p]].size())ans+=child[par[p]].size()-1-cnt;
  }
  //全ての葉が親に追加し終わった
  if(child[par[p]].size()==g[par[p]].size()-1 && par[p]!=root){
    //child[par[p]]に子の値が入ってる
    ll cnt=0;
    for(auto r:child[par[p]]){
      if(k[r]){
        cnt++;
        k[par[r]]=1;
      }
    }
    if(cnt<child[par[p]].size())ans+=child[par[p]].size()-1-cnt;
    if(child[par[p]].size()-1-cnt>0)k[par[p]]=1;
    qq.push(par[p]);
  }
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 12020
#include <iostream>
#include <math.h>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
  long long int A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,J=0,K=0,L=0,M=0,N=0,O=0,P=0,Q=0,R=0,S=0;
  cin >> N >> K;
  long long int HH[N];
  long long int sum=0;
  for(int i=0;i<N;i++){
    cin>>HH[i];
  }
  sort(HH, HH + N, greater<int>());
  for(int i=K;i<N;i++){
    sum+=HH[i];
  }
  
  cout << sum <<endl;
  
  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define BR printf("\n")
#define INF 2000000000

class edge{
public:
    int toid;
    int norm;
    int dist;
    edge(int toid,int norm,int dist){
        this -> toid = toid;
        this -> norm = norm;
        this -> dist = dist;
    }
    bool operator < (const edge &E) const {
        return dist < E.dist;
    }
    bool operator > (const edge &E) const {
        return dist > E.dist;
    }
};

vector<edge> V[10000];
int d[10000];
int count_P = 0;
priority_queue<edge,vector<edge>,greater<edge> > PQ;

void Dijksra(int i,int dist,int n){
    PQ.pop();
    d[i] = dist;
    count_P++;
    if(count_P == n) return;
    
    REP1(k,V[i].size()){
        if (d[V[i][k].toid] == INF){
            V[i][k].dist = dist + V[i][k].norm;
            PQ.push(V[i][k]);
        }
    }
    
    while (d[PQ.top().toid] != INF) PQ.pop();
    if (!PQ.empty()) Dijksra(PQ.top().toid,PQ.top().dist,n);
}

int main(){
    INT(N);
    REP1(i,N) d[i] = INF;
    REP1(i,N){
        int from,n;
        scanf("%d %d",&from,&n);
        REP1(j,n){
            int toid,norm;
            scanf("%d %d",&toid,&norm);
            edge E = edge(toid,norm,INF);
            V[i].push_back(E);
        }
    }
    
    PQ.push(edge(0,0,0));
    Dijksra(PQ.top().toid,0,N);
    
    REP1(i,N){
        printf("%d %d\n",i,d[i]);
    }
    
    return 0;
}

Measured memory_bytes: 11852
s[101][26],p[101];n,i,k,o,q;G(){scanf("%s",s[n]);for(i=0;strcmp(s[i],s[n]);i++);}main(m){for(;~scanf("%d",&n);n&&printf("%d\n",p[i])){for(m=n;m;scanf("%s%d",s[m],p+m))m--;for(scanf("%d",&m);G(q=0),m--;q<p[o]?p[o]=q:0)for(o=i,scanf("%d",&k);k--;q+=p[i])G();}}

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

typedef long long int ll;
typedef pair<int,int> pi;
priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap

ll mini(ll a,ll b){	return a<b?a:b;}
ll maxi(ll a,ll b){	return a>b?a:b;}
ll gcd(ll a,ll b){	if(b == 0)	return a;return gcd(b,a%b);}
ll binpow(ll n,ll x){	ll ans = 1;while(x){if(x & 1)	ans *= n;n *= n;x >>= 1;}return ans;}

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

    string s,t;
    cin>>s>>t;

    int a = s.length();
    int b = t.length();

    vector<int> dp[a+1];
    for(int i=0;i<=a;++i)    dp[i].resize(b+1,0);
    vector<int> dptrack[a+1];
    for(int i=0;i<=a;++i)    dptrack[i].resize(b+1,10);


    for(int i=1;i<=a;++i){
        for(int j=1;j<=b;++j){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
                dptrack[i][j] = 0;                
            }
            else if(dp[i-1][j] > dp[i][j-1]){
                dp[i][j] = dp[i-1][j];
                dptrack[i][j] = 1;
            }
            else{
                dp[i][j] = dp[i][j-1];
                dptrack[i][j] = 2;
            }
        }
    }

    vector<char> ans;

    ll x=a,y=b;

    while(dptrack[a][b] != 10){
        if(dptrack[a][b] == 0){
            ans.push_back(s[a-1]);
            a--;
            b--;
        }
        else if(dptrack[a][b] == 1) a--;
        else  b--;
    }

    if(ans.size()){
        while(ans.size()){
            cout<<ans.back();
            ans.pop_back();
        }
    }
    
    cout<<'\n';

    return 0;
}

Measured memory_bytes: 74212
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n,m = map(int,input().split())
if n<2 and m<2:
    print(0)
elif n<2:
    print(combinations_count(m,2))
elif m<2:
    print(combinations_count(n,2))
else:
    print(combinations_count(n,2)+combinations_count(m,2))

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	
#include<list>

using namespace std;

bool solve(vector<int>& A, int n, int i, int m) {
	if (m == 0)return 1;
	if (i >= n)return 0;

	int res = solve(A, n, i + 1, m) || solve(A, n, i + 1, m - A[i]);

	return res;
}

int main() {
	int n;	cin >> n;
	vector<int> A(n); for (int i = 0; i < n; ++i)cin >> A[i];
	int q;	cin >> q;
	vector<int> m(q); for (int i = 0; i < q; ++i) {
		cin >> m[i];
		if (solve(A, n, 0, m[i])) cout << "yes" << endl;
		else cout << "no" << endl;

	}

	return 0;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int pwmd(int a, int n)
{
	if (!n)
		return 1;
	int pt = pwmd(a, n / 2);
	pt *= pt, pt %= mod;
	if (n & 1)
		pt *= a, pt %= mod;
	return pt;
}

int32_t main()
{
	FIO;
	int n, k; cin >> n >> k;
	int ans = 0;
	int dp[k + 1] = {};

	for (int g = k; g >= 1; --g)
	{
		for (int g2 = 2 * g; g2 <= k; g2 += g)
			dp[g] = (dp[g] - dp[g2] + mod) % mod;

		dp[g] = (dp[g] + pwmd(k / g, n)) % mod;
		ans += g * dp[g];
		ans %= mod;
	}

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 4416
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define double long double
#define int long long
#define pb push_back 
#define Z(c) (int)(c).size()
#define L(c) c[Z(c)-1]
#define F first
#define S second
#define nl "\n"
#define mii unordered_map<int,int> 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);++(i))
#define FO fflush(stdout) 
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define tr(it,ct) for(auto &(it) : (ct))
#define pi acos(-1)
#define prt(ct) for(auto &(it) : (ct)) cerr<<it<<" "; cerr<<nl
#define prtp(ct) for(auto &(it) : (ct)) cerr<<it.F<<" "<<it.S<<nl; cerr<<nl

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef pair<pii,pii> ppp;
typedef vector< pii > vp;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> baap;

void swap(char &a,char &b)
{ auto tm=a; a=b; b=tm; }

void mina(int &a,int b)
{ a=(a<b?a:b); }

void maxa(int &a,int b)
{ a=(a>b?a:b); }

  const int mod=1000000007;
  const int mod2=998244353;
  const int INF=4e18;
  const int N=2e5+25;
  const int M=1e6;

 void doit()
 { 
   int n; cin>>n; string s; cin>>s; vi v;
   tr(i,s){
     if(i=='R') v.pb(0);
     else if(i=='G') v.pb(1);
     else v.pb(2); 
   }

   vi ct[3]; rep(i,0,3) ct[i].resize(n+1);

   for(int i=n-1;i>=0;--i){
      rep(j,0,3) ct[j][i]=ct[j][i+1];
      ct[v[i]][i]++;
   }

   int ans=0;

   for(int i=0;i<n;++i){
                             
      for(int j=i+1;j<n;++j){
          if(v[j]==v[i]) continue;
        int id;
        if(v[i]+v[j]==1) id=2;
        else if(v[i]+v[j]==2) id=1;
        else id=0;
        ans+=ct[id][j+1];
        if(j+j-i<n&&v[j+j-i]==id) ans--;
      }
   }

   cout<<ans;
                                
 }

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



   int tc=1;                         
 //  cin>>tc;

  rep(i,1,tc+1)
  { // cout<<"Case #"<<i<<": ";
    
   doit();
   if(i<tc)
   cout<<nl;
  }
  


 return 0; 
}

Measured memory_bytes: 3700
#include <cstdio>
#include <cstring>

#include <map>

#include <algorithm>

using namespace std;

typedef pair<int, int> P;

int x, y, z, n, a, e;

int v[4];

P event[55];

// double dp[55][5050][2];

double dp[55][5050];
int main() {

    while (scanf("%d%d%d",&x,&y,&z)) {

        if (!x&&!y&&!z) break;

        fill(event, event+55, P(0,0));

        memset(dp, 0, sizeof(dp));
        for (int i=0; i<x; i++) scanf("%d",&v[i]);

        for (int i=0; i<z; i++) {

            scanf("%d%d%d",&n,&a,&e);

        //    event[n]=P(a,e);
            event[n]=P((a==1),a==3?-e:e);

        }
        // dp[0][0][0]=1.0;
        dp[0][0]=1.0;
        for (int i=0; i<y; i++) {
/*            if (event[i].first==1) {
                int next=min(y,i+event[i].second);
                for (int j=0; j<5050; j++) {
                    dp[next][j][1]+=dp[i][j][0];
                    for (int k=0; k<x; k++) {
                        int next2=min(y,i+v[k]);
                        dp[next2][j][0]+=dp[i][j][1]/x;
                    }
                }
            } else {
                for (int j=0; j<5050; j++) {
                    if (dp[i][j][0]==0.0&&dp[i][j][1]==0.0) continue;
                    for (int k=0; k<x; k++) {
                        int next=min(y,i+v[k]);
                        if (event[i].first==2) {
                            dp[next][j+event[i].second][0]+=dp[i][j][0]/x;
                            dp[next][j][0]+=dp[i][j][1]/x;
                        } else if (event[i].first==3) {
                            dp[next][max(0,j-event[i].second)][0]+=dp[i][j][0]/x;
                            dp[next][j][0]+=dp[i][j][1]/x;
                        } else {
                            dp[next][j][0]+=(dp[i][j][0]+dp[i][j][1])/x;
                        }
                    }
                }
            }
*/
            for (int j=0; j<5050; j++) {
                if (dp[i][j]==0.0) continue;
                for (int k=0; k<x; k++) {
                    int nv=min(y,i+v[k]);
                    int np=j;
                    if (nv<y) {
                        if (event[nv].first) nv+=event[nv].second;
                        else np+=event[nv].second;
                    }
                    dp[min(y,nv)][max(0,np)]+=dp[i][j]/x;
                }
            }
        }
        double res=0.0;
//        for (int k=0; k<5050; k++) res+=(dp[y][k][0]+dp[y][k][1])*k;
        for (int k=0; k<5050; k++) res+=dp[y][k]*k;
//        printf("%.0f\n",res);
        printf("%d\n",(int)res);

    }

}

Measured memory_bytes: 0
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;
int main()
{
    int n;
    cin >> n;
    double a,b;
    cin >> a >> b;
    double kk;
    cin >> kk;
    vector<double> k;
    double w;
    for(int i=0;i<n;i++){
        cin >> w;
        k.push_back(w);
    }
    sort(k.rbegin(),k.rend());
    double max=a/kk;
    for(int i=1;i<=n;i++){
        double cnt=kk;
        for(int j=0;j<i;j++){
            cnt+=k[j];
        }
        if(cnt/(a+b*i)>max){
            max=cnt/(a+b*i);
        }
    }
    cout << (int)max << endl;
    
    return 0;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int h,w,h0,w0;
  cin >> h >> w >> h0 >> w0;

  cout << (h-h0)*(w-w0) << endl;
  return 0;
}


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

int main(){
    int n;  cin>>n;
    int ans=0;
    int max=1;
    for(int i=0;i<n;i++){
        int x;  cin>>x;
        ans+=x;

        if(x>max)max=x;
    }

    ans-=max/2;

    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	char C;
	string S, T;
	cin >> C;
	if (C >= 'a')cout << "a" << endl;
	else cout << "A" << endl;

	return 0;
}



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

int main() {
  
  int A, B, C, K; cin >> A >> B >> C >> K;
  
  if (K < A + B) {
    cout << min(A, K) << endl;
  }
  else {
    cout << A - (K - (A + B)) << endl;
  }
  
}

Measured memory_bytes: 3640
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}


int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    char a;
    sf(a);
    cout << (char)(a + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
S = input() # 本体
T = input() # 部分文字列

min_hamming = len(T)
for i in range(len(S) - len(T) + 1) :
    # print(S[i:i+len(T)], T, end = " ")
    hamming = 0
    for ch1, ch2 in zip(S[i:i+len(T)], T):
        hamming += 1 if ch1 != ch2 else 0
    # print(hamming)
    min_hamming = min(min_hamming, hamming)

print(min_hamming)

Measured memory_bytes: 9120
#include <iostream>

using namespace std;

int main()
{
   string s,t,r;
   int x,y,i;
   cin>>s>>t>>x>>y>>r;
   if(r==s){
       x-=1;
   }
   else if(r==t)
       y-=1;
    cout<<x<<" "<<y;
}


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

struct node {
        int key;
         struct node *next;
         struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key) {
        NodePointer cur = nil->next;
        while (cur != nil && cur->key != key) {
                cur = cur->next;
        }
        return cur;
}

void init() {
        nil = malloc(sizeof(struct node));
        nil->next = nil;
        nil->prev = nil;
}

void printList() {
        NodePointer cur = nil->next;
        int isf = 0;
        while (1) {
                if (cur == nil) break;
                if (isf++ > 0)  printf(" ");
                printf("%d", cur->key);
                cur = cur->next;
        }
        printf("\n");
}

void deleteNode(NodePointer t) {
        if (t == nil) return;
        t->prev->next = t->next;
        t->next->prev = t->prev;
        free(t);
}

void deleteFirst() {
        deleteNode(nil->next);
}

void deleteLast() {
        deleteNode(nil->prev);
}

void deleteKey(int key) {
        deleteNode(listSearch(key));
}

void insert(int key) {
        NodePointer x;
        x = malloc(sizeof(struct node));
        x->key = key;

        x->next = nil->next;
        nil->next->prev = x;
        nil->next = x;
        x->prev = nil;
}

int main() {
        int key, n, i;
        int size = 0;
        char com[20];
        int np = 0, nd = 0;
        scanf("%d", &n);
        init();
        for (i = 0; i < n; i++) {
                scanf("%s", com);
                if (com[0] == 'i') {
                        scanf("%d", &key);
                        insert(key);
                        np++;
                        size++;
                }
                else if (com[0] == 'd') {
                        if (strlen(com) > 6) {
                                if (com[6] == 'F') deleteFirst();
                                else if (com[6] == 'L') deleteLast();
                        }
                        else {
                                scanf("%d", &key);
                                deleteKey(key); nd++;
                        }
                        size--;
                }
        }

        printList();
        return 0;
}



Measured memory_bytes: 32952
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
}; 


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n); readint(d); readint(a);
        set<tuple<ll,ll,ll>> events;
        forr(i,0,n) {
            readint(xx); readint(hh);
            events.insert(make_tuple(xx,hh,0));
        }
        ll ret = 0, curr = 0;
        while (!events.empty()) {
            auto temp = *events.begin();
            if (get<2>(temp)==0) {
                if (get<1>(temp) > curr)  {
                    ll new_bombs = 1 + (get<1>(temp)-curr)/a - ((get<1>(temp)-curr) % a == 0);
                    curr += new_bombs*a;
                    ret += new_bombs;
                    events.insert(make_tuple(get<0>(temp)+2*d, 10000000007LL, new_bombs));
                }
            }
            if (get<2>(temp)>0) {
                curr -= a*get<2>(temp);
            }
            events.erase(events.begin());
        }

        cout << ret << endl;

    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}

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

#define MAX_N 100
#define MAX_M (MAX_N * MAX_N)

typedef struct EDGE {
	int to;
	struct EDGE *next;
} edge;

int size;
edge buff[MAX_M];
edge *adj[MAX_N];

void add_edge(int u, int v) {
	edge *e = buff + size++;
	e->to = v;
	e->next = adj[u];
	adj[u] = e;
}

typedef int data_t;
data_t queue[MAX_N];
int head, tail;

void enqueue(data_t data) {
	queue[tail++] = data;
}

data_t dequeue() {
	return queue[head++];
}

bool empty() {
	return head == tail;
}

int dist[MAX_N];

void bfs(int s) {
	edge *e;

	memset(dist, -1, sizeof(dist));
	dist[s] = 0;
	enqueue(s);

	while(!empty()) {
		const int u = dequeue();
		for(e = adj[u]; e != NULL; e = e->next) {
			if(dist[e->to] == -1) {
				dist[e->to] = dist[u] + 1;
				enqueue(e->to);
			}
		}
	}
}

int main() {
	int n;
	int u, k;
	int i, j;
	int v;

	scanf("%d", &n);
	for(i = 0; i < n; ++i) {
		scanf("%d %d", &u, &k);
		for(j = 0; j < k; ++j) {
			scanf("%d", &v);
			add_edge(u - 1, v - 1);
		}
	}

	bfs(0);
	for(u = 0; u < n; ++u) {
		printf("%d %d\n", u + 1, dist[u]);
	}

	return EXIT_SUCCESS;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int n;
lint W, w[110], ans;
vector<lint> v[4];

void dfs(int cur, lint tW, lint tV){
    if(cur == 4){
        chmax(ans, tV);
        return;
    }
    rep(i, v[cur].size()){
        if(tW + (w[0]+cur) * i > W) break;
        dfs(cur+1, tW + (w[0]+cur) * i, tV + v[cur][i]);
    }
}

int main(){
    scanf("%d%lld", &n, &W);
    rep(i, n){
        lint tv;
        scanf("%lld%lld", &w[i], &tv);
        v[w[i]-w[0]].push_back(tv);
    }
    rep(i, 4){
        sort(v[i].begin(), v[i].end(), greater<>());
        v[i].insert(v[i].begin(), 0);
        partial_sum(v[i].begin(), v[i].end(), v[i].begin());
    }
    dfs(0, 0, 0);
    printf("%lld\n", ans);
}

Measured memory_bytes: 3752
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll n,m;
 sc(n);sc(m);
 vector<ll>l;
 ll b;
 rep(i,0,n){sc(b);push(l,b);}
 sort(l);
  
 rrp(i,n,n-m)ans+=l[i];
 pr(ans);
return 0;}

Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
		int a;
		cin >> a;
		int b;
		cin >> b;
		int c;
		cin >> c;

		if ( b >= c && c >= a )
		cout << "Yes" << endl;
		else
		cout << "No" << endl;
}

Measured memory_bytes: 256
n = gets.to_i
w = gets.split.map(&:to_i)
ans = 1e9
0.upto(n-2) do |i|
    w1 = w[0..i]
    w2 = w[i+1..n-1]
    s1 = w1.inject(:+)
    s2 = w2.inject(:+)
    ans = (s1-s2).abs if (s1-s2).abs < ans
end
puts ans

Measured memory_bytes: 1788
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main(){
char a[200000];
int i=0,cnt=0,start=0,e=0,sum=0;
scanf("%s",&a);
while(a[i]!=0){
cnt+=1;
i++;
}
i--;
for(i=cnt;i>0;i--){
if(a[i]=='Z'){
e=i;
break;
}
}
for(i=0;i<200000;i++){
if(a[i]=='A'){
start=i;
break;
}
}
sum=(e-start)+1;
printf("%d",sum);
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string str;
  int Q;
  cin >> str >> Q;
  deque<char> deq;
  for (auto c : str) deq.push_back(c);
  bool rev = false;

  for (int i = 0; i < Q; i++) {
    int t;
    cin >> t;
    if (t == 1) rev ^= 1;

    if (t == 2) {
      int f;
      char c;
      cin >> f >> c;

      if ((f - 1) ^ rev) {
        deq.push_back(c);
      } else {
        deq.push_front(c);
      }
    }
  }

  if (!rev) {
    for (auto it = deq.begin(); it != deq.end(); ++it) cout << *it;
  } else if (rev == 1) {
    for (auto it = deq.rbegin(); it != deq.rend(); ++it) cout << *it;
  }
  cout << '\n';

  return 0;
}


Measured memory_bytes: 976
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {

//	入力の読み込み
		Scanner sc = new Scanner(System.in);
		int shurui = sc.nextInt();  //商品の種類数
		double select = sc.nextInt();  //選びたい商品数
		double sum = 0;  //総投票数
		int shouhin[] = new int[shurui];  //商品配列

//	お菓子1つずつに得票数を記入
		for(int i=0 ; i<shurui ; i++) {
			int tokuhyou = sc.nextInt();
			shouhin[i] += tokuhyou;
			sum += tokuhyou;
		}

//	総投票数がわかったので基準値を求める
		double kijun = (sum/(4*select));

//	並列の中身を開けてみて、選べる商品をカウント
		int count = 0;
		for(int i : shouhin) {
			if(i >= kijun) {
				count ++;
			}
		}

//	選べる商品がM個以上あるかどうか
		System.out.println(count >= select ? "Yes" : "No");
	}
}

Measured memory_bytes: 27080
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, at;

  cin >> n;

  vector<int> x,ans;

  for (int i = 0; i < n; i++) {
    cin >> at;
    x.push_back(at);
  }


  vector<int> yy=x;
  sort(x.begin(),x.end());
  // reverse(x.begin(),x.end());
  int c = (n/2) -1;
  for(auto y:yy){
    int aaa;
    if(x[c]<y)
    {  aaa=x[c];
    }
    
    else
    {      aaa=x[c+1];
        }

    ans.push_back(aaa);
  }



  for(auto an:ans)
    cout<<an<<endl;
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N, n;
      cin >> N;
      for(int i = 0; i < N; i++){
        int A, m;
        cin >> A;
        m = 0;
        while(A % 2 == 0){
          A /= 2.0;
          m++;
        }
        if(i == 0){
          n = m;
        }else if(n > m){
          n = m;
        }
      }
      cout << n << endl;
    }

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int test(double e){
	if(e<0.2) return 3;
	if(e<0.6) return 2;
	if(e<1.1) return 1;
	else return 0;
}

int main(){
	int ansA[4]={},ansB[4]={};
	double A,B;
	while(cin>>A>>B){
		ansA[test(A)]++; ansB[test(B)]++;
	}
	for(int i=0;i<4;i++) printf("%d %d\n",ansA[i],ansB[i]);
	return 0;
}

Measured memory_bytes: 1208
/*
 *	Argorithms and Data Structures
 *	Lectuire 7 
 *	Rooted Trees
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 100000

typedef struct{
	int id_parent;
	int depth;
	int degree;
	char type[15];
	int *id_child;
} Node;

Node *node;

int depth(int);

int main(void){

	int i,j;

	int n_node, id;
	scanf("%d",&n_node);
	node = malloc(sizeof(Node) * n_node);

	/* Initialization */
	for(i=0;i<n_node;i++){
		node[i].id_parent = -1;
		strcpy(node[i].type,"root");
	}
	
	/* Input */
	for(i=0; i<n_node; i++){
		scanf("%d", &id);
		scanf("%d", &node[id].degree);
		
		/*
			(node[a])'s ID is a
			node[a] has (node[a].degree) children
		*/
		node[id].id_child = malloc( sizeof(int) * node[id].degree );
		for(j=0; j<node[id].degree; j++) {
			scanf("%d", &node[id].id_child[j]);		// You are my child.
			node[ node[id].id_child[j] ].id_parent = id;		// I am your father.
		}
	}

	for(id=0; id<n_node; id++){
		/* node[a]'s type is */
		if( node[id].id_parent != -1 ){
			if( node[id].degree > 0 )
				strcpy( node[id].type, "internal node");
			else
				strcpy( node[id].type, "leaf");
		}

		/* node[a]'s depth is */
		node[id].depth = depth( id );
	}

	/* Output */
	for(id=0; id<n_node; id++){
		printf("node %d: parent = %d, depth = %d, %s, [",
				id, node[id].id_parent, node[id].depth, node[id].type );

		for(i=0; i<node[id].degree ; i++){
			printf("%d", node[id].id_child[i]);
			if( i == node[id].degree -1 )
				break;
			printf(", ");
		}
		printf("]");
		free(node[id].id_child);


		//if(id == n_node-1) break;

		printf("\n");
	}
	free(node);


	return 0;
}

int depth( int id ){
	if (node[id].id_parent == -1)
		return 0;
	return 1 + depth( node[id].id_parent ); 
}

//free id_child

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



int main(){
    long long int n, m;
    cin >> n >> m;
    vector<long long int> dp(n+1, -1);
    dp[0] = dp[1] = 1;
    
    for (long long int i = 0; i < m; i++){
        long long int  peldano; cin >> peldano;
        dp[peldano] = 0;
    }
    
    for (long long int  i = 2; i <= n; i++){
        if (dp[i] != 0) dp[i] = (dp[i-1] + dp[i-2])%1000000007;
    }

    cout << dp[n] << endl;
    return 0;
}



Measured memory_bytes: 4048