akhauriyash/Code-Regression huggingface dataset:
//
/*
ID: kfoozmi1
LANG: C++
TASK:
*/
#include <bits/stdc++.h>
using namespace std;

#ifdef kfoozminus
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu() {
	cerr << endl;
}

template <typename T>
void faltu(T a[], int n) {
	for(int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename First, typename ... hello>
void faltu(First arg, const hello&... rest) {
	cerr << arg << ' ';
	faltu(rest...);
}
#else
#define dbg(args...)
#endif

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define SQR(a) ((a) * (a))
#define vsort(v) sort(v.begin(), v.end())
#define PQ priority_queue
#define PI acos(-1)
#define EPS 1e-9

#define B1 43
#define B2 43

#define MOD1 1000000007
#define MOD2 1000000009
#define MOD  1000000007

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

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

inline bool checkBit(ll n, int i) { return n & (1LL << i); }
inline ll setBit(ll n, int i) { return n | (1LL << i); }
inline ll resetBit(ll n, int i) { return n & (~ (1LL << i)); }
inline bool EQ(double a, double b) { return fabs(a-b) < EPS; }
inline double dist(double ix, double iy, double jx, double jy) { return sqrt(SQR(ix - jx) + SQR(iy - jy)); }

#define PMX 1000000

int marked[PMX/64+2];

#define mark(x) marked[x>>6] |= (1<<((x&63)>>1))
#define check(x) (marked[x>>6] & (1<<((x&63)>>1)))

bool isPrime(int x)
{
    return (x>1) && ((x==2) || ((x&1) && (!(check(x)))));
}

void seive(int n)
{
    int i, j;
    for(i=3; i*i<=n; i+=2)
    {
        if(!check(i))
        {
            for(j=i*i; j<=n; j+=i<<1)
            {
                mark(j);
            }
        }
    }
}

ll bigMod(ll a, ll b)
{
	ll r = 1;
	while(b) {
		if(b & 1) (r *= a) %= MOD;
		b >>= 1;
		(a *= a) %= MOD;
	}
	return r;
}

#define INF 100000000
#define MX 100007

int main()
{
#ifdef kfoozminus
	//freopen("in", "r", stdin);
#endif
	ll mx, a, b, c, mx1, mx2;
	scanf("%lld %lld %lld", &a, &b, &c);
	mx = max(a, max(b, c));
	if(mx == a) mx1 = b, mx2 = c;
	else if(mx == b) mx1 = a, mx2 = c;
	else mx1 = a, mx2 = b;
	printf("%lld\n", (mx & 1) ? mx1 * mx2 : 0);
        return 0;
}


Measured memory_bytes: 256
from itertools import permutations as pm

def judge(lst):
  a, b, c, d, e, f, g, h, i = lst
  return a + (b * 10 + c) + (d * 100 + e * 10 + f) == (g * 100 + h * 10 + i)

def solve(lst, rest):
  n = len(rest)
  if n == 0:
    return int(judge(lst))
  ans = 0
  for loc in pm(rest, n):
    tmp = lst[:]
    for i in loc:
      tmp[tmp.index(-1)] = i
    ans += judge(tmp)
  return ans

lst = list(map(int, input().split()))
rest = {i for i in range(1, 10)} - set(lst)
print(solve(lst, rest))


Measured memory_bytes: 5644
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,m,n) for(int i = m; i < n; ++i)
#define RFOR(i,m,n) for(int i = n - 1; i >= m; --i)
#define CIN(a) cin >> a
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a << endl
#define COUT2(a, b) cout << a << " " << b << endl
#define COUT3(a, b, c) cout << a << " " << b << " " << c << endl
#define pb push_back
#define PB push_back
#define VINT(v, n) vector<int> v(n); REP(i, n) { v[i] = 0 }
#define VINT2(v, n, m) vector<vector<int> > v(n, vector<int>(m)); REP(i, n) { REP(j, m) { v[i][j] = 0 } }
#define VCHAR(v, n) vector<char>v(n)
#define KIRIAGE(a, b) a += (b - a % b) % b
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;}
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
	int K, S, c = 0;
	CIN2(K, S);
	REP(i, K + 1) {
		REP(j, K + 1) {
			if(S - (i + j) >= 0 && S - (i + j) <= K) ++c;
		}
	}
	COUT(c);
}


Measured memory_bytes: 256
# ABC138D - Ki
import sys

input = sys.stdin.readline
sys.setrecursionlimit(2 * 10 ** 5 + 5)


def dfs(v: int, p: int) -> None:
    x = cnt[v]
    for u in T[v]:
        if u != p:  # p: parent -> skip
            cnt[u] += x  # cumulative sum
            dfs(u, v)


def main():
    # Ai (A[i][0]) may be not a parent of Bi (A[i][1])
    global T, cnt
    N, Q = tuple(map(int, input().split()))  # vertices and queues
    E = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    P = tuple(tuple(map(int, input().split())) for _ in range(Q))
    T = [[] for _ in range(N + 1)]  # tree, N+1: 1-idx
    for a, b in E:
        T[a] += [b]
        T[b] += [a]
    cnt = [0] * (N + 1)
    for p, x in P:
        cnt[p] += x  # increase vertex p by x
    dfs(1, -1)
    print(*cnt[1:])


if __name__ == "__main__":
    main()

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define pb push_back
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
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);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

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

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int H, W, D;
    int d[90001];
    int px[90001], py[90001];
    cin >> H >> W >> D;

    int A[H][W];
    rep(i, H){
        rep(j, W){
            cin >> A[i][j];
            px[A[i][j]] = j;
            py[A[i][j]] = i;
        }
    }

    int Q;
    cin >> Q;
    int L[Q], R[Q];
    rep(i, Q) cin >> L[i] >> R[i];


    for(int i=D+1; i <= H*W; ++i)
        d[i] = d[i-D] + abs(px[i] - px[i-D]) + abs(py[i] - py[i-D]);

    rep(i, Q)
        cout << d[R[i]] - d[L[i]] << endl;





    return 0;
}


Measured memory_bytes: 3328
s = list(input())
out = "No"
R = []
L = []
for k,i in enumerate(s):
  if (k%2) == 0:
    R.append(i)
  else:
    L.append(i)

if ("R" in L) or ("L" in R):
  pass
else:
  out = "Yes"
print(out)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = 1;
    int flag = 0;
    rep(i,n-1){
        if(flag==1){
            if(a[i]>a[i+1]){
                ans++;
                flag = 0;
            }
        }
        else if(flag==2){
            if(a[i]<a[i+1]){
                ans++;
                flag = 0;
            }
        }
        else{
            if(a[i]<a[i+1]) flag = 1;
            else if(a[i]>a[i+1]) flag = 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<(n);i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll
// #define MAX 20
#define INF (int)1e18

template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.F<<','<< P.S<<')';}


signed main()
{
	fio
	inp(n) inp(m)
	if(n==m)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	printclock;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

namespace mp = boost::multiprecision;

int main(){
    mp::cpp_dec_float_100 a,b,c;
    cin >> a >> b >> c;
    if(mp::sqrt(a) + mp::sqrt(b) < mp::sqrt(c)) puts("Yes");
    else puts("No");
    return 0;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
ABs = [list(map(int, input().split())) for _ in range(N)]
ABs = sorted(ABs, key=lambda ab: ab[0])

m = 0
c = 0
for AB in ABs:
    a, b = AB
    for _ in range(b):
        m += a
        c += 1
        if c >= M:
            break
    else:
        continue
    break

print(m)


Measured memory_bytes: 29796
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=200100;
int n,a[maxn],q;
struct node
{
	int l,r;
}c[maxn];
bool cmp(node a,node b)
{
	if(a.l==b.l) return a.r>b.r;
	return a.l<b.l; 
}
struct tree
{
	int l,r,mi;
	tree *ls,*rs;
	tree()
	{
		ls=rs=NULL;
		l=r=mi=0;
	}
	void update()
	{
		mi=min(ls->mi,rs->mi);
	}
	void build(int lx,int rx)
	{
		l=lx;r=rx;
		if(l==r) {mi=(l==0)?0:maxn;return;}
		int mid=(l+r)>>1;
		(ls=new tree)->build(lx,mid);
		(rs=new tree)->build(mid+1,rx);
		update();
	}
	void mdf(int pl,int c)
	{
		if(l==r) {mi=min(mi,c);return;}
		int mid=(l+r)>>1;
		if(pl<=mid) ls->mdf(pl,c);
		else rs->mdf(pl,c);
		update();
	}
	int qry(int lx,int rx)
	{
		if(l==lx&&r==rx) return mi;
		int mid=(l+r)>>1;
		if(rx<=mid) return ls->qry(lx,rx);
		else if(lx>mid) return rs->qry(lx,rx);
		else return min(ls->qry(lx,mid),rs->qry(mid+1,rx));
	}
}*xtr;
int main()
{
	scanf("%d",&n);
	int num=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);	
		num+=(1-a[i]);
	}
	(xtr=new tree)->build(0,n);	
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
		scanf("%d%d",&c[i].l,&c[i].r);	
	sort(c+1,c+q+1,cmp);	
	c[0].l=1;
	for(int i=1;i<=q;i++)
	{
		for(int j=c[i-1].l;j<c[i].l;j++)
			xtr->mdf(j,xtr->qry(j-1,j-1)+2*a[j]-1);
		xtr->mdf(c[i].r,xtr->qry(c[i].l-1,c[i].r));	
	}
	for(int j=c[q].l;j<=n;j++)
		xtr->mdf(j,xtr->qry(j-1,j-1)+2*a[j]-1);
	printf("%d",num+xtr->qry(n,n));
	return 0;
}


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

using namespace std;

#define ll long long

int main()
{
	int n;
	cin >> n;
	double p[n], temp;
	for(int i = 0; i < n; i++)
		cin >> p[i];
	double vect[n][n+1];
	vect[0][0] = 1-p[0];
	vect[0][1] = p[0];
	for(int i = 1; i < n+1; i++)
	{
		for(int j = 0; j < i+2; j++)
		{
			temp = 0;
			if(j>0)
				temp += vect[i-1][j-1]*p[i];
			if(j<i+1)
				temp += vect[i-1][j]*(1-p[i]);
			vect[i][j] = temp;
		}
	}
	double ans = 0;
	for(int i = n/2+1; i < n+1; i++)
	{
		ans += vect[n-1][i];
	}
	cout << setprecision(10) << ans;
}

Measured memory_bytes: 70144
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,n,i,j=0;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=0;i<k;i++)
    {
        j+=a[i];
    }

        cout<<j<<endl;
}



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


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

	if (S == "SSS") {
		cout << 0 << endl;
		return 0;
	}

	if (S == "SSR" or S == "SRS" or S == "RSS" or S == "RSR") {
		cout << 1 << endl;
		return 0;
	}

	if (S == "SRR"  or S == "RRS") {
		cout << 2<< endl;
		return 0;
	}

	if (S == "RRR") {
		cout << 3 << endl;
		return 0;
	}

}


Measured memory_bytes: 3624
n = int(input())
list = [1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,
       24,25,27,28,30,32,35,36,40,42,45,48,49,54,
       56,63,64,72,81]

if n in list:
  print('Yes')
else:
  print('No')

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

const ll MOD = 998244353;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, s;
	cin >> n >> s;

	vl a(n);
	FOR(i,0,n) cin >> a[i];
	
	ll res = 0;
	vl dp(s+1);
	
	FOR(i,0,n) {
		vl ndp = dp;
		if (a[i] <= s) ndp[a[i]] = (ndp[a[i]] + i+1) % MOD;
		FOR(j,a[i],s+1) {
			ndp[j] = (ndp[j] + dp[j-a[i]]) % MOD;
		}

		dp = ndp;
		res = (res + dp[s]) % MOD;
	}
	cout << res << endl;
}



Measured memory_bytes: 384
s = gets.chomp
k = gets.to_i
a = 0
t = s.dup
t.size.pred.times do |i|
  if t[i] == t[i + 1]
    a += 1
    t[i + 1] = '0'
  end
end
b = 0
t = s.dup * 2
t.size.pred.times do |i|
  if t[i] == t[i + 1]
    b += 1
    t[i + 1] = '0'
  end
end
c = 0
t = s.dup * 3
t.size.pred.times do |i|
  if t[i] == t[i + 1]
    c += 1
    t[i + 1] = '0'
  end
end
d = 0
t = s.dup * 4
t.size.pred.times do |i|
  if t[i] == t[i + 1]
    d += 1
    t[i + 1] = '0'
  end
end
if a == b - a
  puts a * k
elsif b - a == c - b
  puts a + (k - 1) * (b - a)
elsif a == (c - b) && (b - a) == (d - c)
  puts a * k / 2 + (b - a) * k / 2 if k.even?
  puts a * (k + 1) / 2 + (b - a) * (k - 1) / 2 if k.odd?
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  string S; cin>>S;
  int N=S.size();
  int count1=0,count2=0;
  int ans=0;
  rep(i,0,N){
    if(S[i]=='<'){
      if(i>0&&S[i-1]=='>'){
        ans+=max(0ll,(count1-1)*count1/2);
        ans+=max(0ll,(count2-1)*count2/2);
        ans+=max(count1,count2);
        count1=0;
        count2=0;
      }
      count1++;
    }
    else{
      count2++;
    }
  }
  ans+=max(0ll,(count1-1)*count1/2);
  ans+=max(0ll,(count2-1)*count2/2);
  ans+=max(count1,count2);
  cout<<ans<<endl;
  }


Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
signed main()
{
    IOS
    int n; cin>>n;
    int arr[n],brr[n];
    for(int i=0;i<n;i++){
      cin>>arr[i];
      brr[i] = arr[i];
    }
    sort(brr,brr+n);
    int l1 = brr[n-1],l2 = brr[n-2];
    if(l1 == l2)
    {
      for(int i=0;i<n;i++) cout<<l1<<endl;
    }
  else{
    for(int i=0;i<n;i++)
    {
      if(arr[i] == l1) cout<<l2<<endl;
      else cout<<l1<<endl;
    }
  }
    return 0;
}

Measured memory_bytes: 4736
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n, m;
  int dp[100001] = {0};
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    dp[a] = -1;
  }

  int mod = 1000000007;
  
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    if (dp[i] == -1) {
      continue;
    }
    if (i-1 >= 0 && dp[i-1] != -1) {
      dp[i] =  (dp[i] + dp[i-1]) % mod;
    }
    if (i-2 >= 0 && dp[i-2] != -1) {
      dp[i] = (dp[i] + dp[i-2]) % mod;
    }
  }
  cout << dp[n] << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    int i;
    int j;
    int tmp;
    int ans;
    
    cin >> n;
    vector<int> nums(n);
    i = -1;
    while (++i < n)
        cin >> nums.at(i);
    ans = 0;
    i = -1;
    while (++i < n)
    {
        j = i;
        while (++j < n)
        {
            if (nums.at(i) < nums.at(j))
            {
                tmp = nums.at(i);
                nums.at(i) = nums.at(j);
                nums.at(j) = tmp;
            }
        }
        if (i % 2 == 0)
            ans += nums.at(i);
        else
            ans -= nums.at(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
using DataStructures
const double = Float64
const int = Int64

parseint(x) = parse(int, x)
readint() = map(parseint, split(readline()))

function main()
  N,M,K = readint()

  G = Vector{Vector{int}}(undef,N)
  for i in 1:N
    G[i] = Vector{int}(undef,0)
  end

  arlady = zeros(int,N)

  for i in 1:M
    A,B = readint()
    append!(G[A],[B])
    append!(G[B],[A])
    arlady[A] += 1
    arlady[B] += 1
  end
  
  # 繋がり確認
  Gr = Vector{int}(undef,N)
  #arlady = zeros(undef,N)
  ninsuu = zeros(int,N) 
  checked = Vector{Bool}(undef,N)
  checked .= false
  Q = Queue{int}()

  for i in 1:N 
    checked[i] && continue

    enqueue!(Q,i)
    while !isempty(Q)
      p = dequeue!(Q)
      checked[p] && continue
      checked[p] = true
      Gr[p] = i
      ninsuu[i] += 1

      for q in G[p]
        checked[q] && continue
        enqueue!(Q,q)
      end

    end
  end

  for i in 1:K
    C,D = readint()
    Gr[C] != Gr[D] && continue
    arlady[C]+=1
    arlady[D]+=1
  end

  for i in 1:N
    print(ninsuu[Gr[i]]-1-arlady[i], " ")
  end
  println()
end

main()

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int dp[1010][(1<<12) + 10];

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    vector<int> c(m, 0);

    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        int ci;
        for (int j = 0; j < b[i]; ++j) {
            cin >> ci;
            ci--;
            c[i] += (1<<ci);
        }
    }

    for (int i = 0; i <= m; ++i) {
        for (int j = 0; j < (1<<12); ++j) {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < (1<<n); ++j) {
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            dp[i+1][j|c[i]] = min(dp[i+1][j|c[i]], dp[i][j] + a[i]);
        }
    }

    cout << (dp[m][(1<<n)-1] == INF ? -1 : dp[m][(1<<n)-1]) << endl;
}

Measured memory_bytes: 16256
from itertools import accumulate, combinations
from collections import Counter
import math

N, M =[int(i) for i in input().split()]
A = [int(i) for i in input().split()]

A.insert(0, 0)
a = list(accumulate(A))
for i in range(N+1):
    a[i] = a[i]%M

b = Counter(a)
m = b.most_common()
ans = 0

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

for x in m:
    if x[1] >= 2:
        ans += combinations_count(x[1], 2)
print(ans)

Measured memory_bytes: 19788
#include<cstdio>
int main(){
    char s[101];
    long long k;
    scanf("%s%lld",s,&k);
    int num1=0;
    while(s[num1]=='1')num1++;
    if(k<=(long long)num1)printf("1");
    else printf("%c",s[num1]);
    return 0;
}

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

#define Max 999999

int main(){
	std::vector<bool>is_prime(Max+1,true);
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=Max;i++){
		if(is_prime[i]){
			for(int j=i*2;j<=Max;j+=i)is_prime[j]=false;
		}
	}
	int n;
	while(std::cin>>n){
		int count=0;
		for(int i=2;i<=n;i++){
			if(is_prime[i])count++;
		}
		std::cout<<count<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1320
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

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

   vector<int> a(n,0);

   rep(i,n){
      cin>>a[i];
   }

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

   cout<<a[n/2]-a[n/2-1];
  
return 0;
}



Measured memory_bytes: 640
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;
int g1[N];
int g2[N];
int a[N];
int gcd(int n, int m)
{
	return m == 0 ? n : gcd(m, n % m);
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		g1[i] = gcd(a[i], g1[i - 1]);
	}
	for (int i = n; i > 0; i--)
		g2[i] = gcd(a[i], g2[i + 1]);
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ans = max(ans, gcd(g1[i - 1], g2[i + 1]));
	}
	cout << ans << endl;
	return 0;
}

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

int main(){

  int a,b,c;
  
  while(1){

    int n;
    int d;
  
    scanf("%d %d %d",&a,&b,&c);
    if(a==0 && b==0 && c==0) break;
    scanf("%d",&n);
    
    d = min(a*a+b*b , min(a*a+c*c , b*b+c*c));
    
    for(int i=0;i<n;i++){
      int r;
      int f=1;
      
      scanf("%d",&r);
      r = (2*r)*(2*r);
      if(r<=d) f=0;

      //printf("%d %d ",r,d);
      
      if(f) printf("OK\n");
      else printf("NA\n");
    }


  }
  return 0;
}

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

using namespace std;
typedef long long ll;

void YesNo(bool x) {
    cout << (x ? "Yes" : "No") << endl;
}

int main() {
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    cout << (h - x) * (w - y) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) (((a%MOD+MOD)%MOD+(b%MOD+MOD)%MOD)%MOD)
#define MUL(a, b) ((((a%MOD+MOD)%MOD)*((b%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }
template<typename I> int ACC(I f, I l, int i){ return accumulate(f, l, i); }


int N;
int a[200010];
int b[200010];
VI ans;


signed main(){
    cin >> N;
    repe(i, 1, N) cin >> a[i];

    reper(i, N, 1){
        int s = 0;
        repif(j, 2, i*j <= N) s += b[i*j];
        if(s%2 != a[i]) b[i] = 1, ans.pb(i);
    }

    cout << SZ(ans) << endl;
    rep(i, 0, SZ(ans)){
        if(i == SZ(ans)-1) cout << ans[i] << endl;
        else cout << ans[i] << ' ';
    }

    return 0;
}

Measured memory_bytes: 4852
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int T = scan.nextInt();
        int X = scan.nextInt();
        double answer = (double) T/X;
        System.out.printf("%.9f", answer);
    }
}


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

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

    vector<int> count(2,0);
    for(int j : {0, 1}){
        int target = j;
        for(int i=0; i<S.size(); i++){
            int val = S[i] - '0';
            if(target == val){
                count[j] += 1;
            }
            target = (target == 0)? 1:0;
        }
    }
    int ans = *min_element(count.begin(), count.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;
/*
ll bin(ll i,ll j){
	ll mid=(i+j)/2;
	if(a[mid]==x)reutrn mid;
	else if(ans>x)return bin(i,mid-1);
	else return bin(mid+1,j);
}/*
ll power(ll base,ll power){
    ll res=1;
    base=base%mod;
    while(power>0){
    	if(power&1){
    		res=(res*base)%mod;
		}
		power=power>>1;
		base=(base*base)%mod;
	}
	return res;
}
*/
/*
int nCr(int x, int y){
	if(y>x)return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=mod;
	num*=invfact[x-y];
	num%=mod;
	return num;
}
*/
/*bool prime[n+1];
void SieveOfEratosthenes(int n){
	rep(i,0,n+1)prime[i]=true
    for (int p=2;p*p<=n;p++)
        if (prime[p])
            for (int i=p*p;i<=n;i+=p)prime[i]=false;
}*/
/*
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
*/
int solve(){
    int x,y,p,q,r;
    cin>>x>>y>>p>>q>>r;
    ll a[p],b[q];
    vector<ll> vec;
    rep(i,0,p)cin>>a[i];sort(a,a+p);reverse(a,a+p);
    rep(i,0,q)cin>>b[i];sort(b,b+q);reverse(b,b+q);
    rep(i,0,r){
    	ll k;
    	cin>>k;
    	vec.pb(k);
	}
	rep(i,0,x)vec.pb(a[i]);
	rep(i,0,y)vec.pb(b[i]);
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	ll sum=0;
	rep(i,0,x+y){
		sum+=vec[i];
	}
	cout<<sum<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


Measured memory_bytes: 8048
import java.util.Arrays;
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();
        int[] h = new int[N];
        for (int i = 0; i < h.length; i++) {
            h[i] = sc.nextInt();
        }
        Arrays.sort(h);
        final int INF = (int)Math.pow(10, 9) + 7;
        int dif = INF;
        for (int i = 0; i < h.length - K + 1; i++) {
            dif = Math.min(dif, h[K - 1 + i] - h[i]);
        }
        System.out.println(dif);
        sc.close();
    }
}

Measured memory_bytes: 50040
const getGCD = (a, b) => {
    if (b === 0) return a;
    else if (a === 0) return b;
    return getGCD(b, a%b);
    
}

const getDivisors = (n) => {
    let ret = []
    for(let i=1; i*i<=n; i++) {
        if(n%i===0) {
            ret.push(i)
            if(i!==n/i)
              ret.push(n/i)
        }
    }
    return ret
}

const isPrime = (n) => {
    for(let i=2; i*i<=n; i++) {
        if(n%i===0)return false
    }
    return true
}

const main = (arg) => {
    let [a,b] = arg.split(" ").map(Number)
    let gcd = getGCD(a,b)
    // console.log(gcd)
    let divs = getDivisors(gcd)

    divs.sort((a,b)=>a-b)
    // console.log(divs)
    let ans=0
    for(let i=0; i<divs.length; i++) {
        if(isPrime(divs[i])) ans++
    }
    console.log(ans)
    
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 33432
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include <string>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
ll mod=1e9+7;
int main(){
 	int n,a,b,c,d; cin >>n>>a>>b>>c>>d;
 	a--; b--; c--; d--;
 	string s; cin >>s;
 	int field[200200];
 	for(int i=0;i<s.size();i++){
 		if(s[i]=='#')field[i]=0;
 		else field[i]=1;
 	}
 	field[a]=2; field[b]=3;
 	bool Flag=0; bool Flag1=0;
 	int cnt=0;
 	if(c<d){
 		while(!Flag||!Flag1){
 			if(a==c){
 				Flag=true;
 			}
 			if(b==d){
 				Flag1=true;
 			}
 			if(field[b+1]==1&&!Flag1){
 				b++;
 				field[b-1]=1;
 				field[b]=3;
 				cnt=0;
 			}
 			else if(field[b+2]==1&&!Flag1&&b+1!=d){
 				b+=2;
 				field[b-2]=1;
 				field[b]=3;
 				cnt=0;
 			}
 			else if(field[a+1]==1&&!Flag){
 				a++;
 				field[a-1]=1;
 				field[a]=2;
 				cnt=0;
 			}
 			else if(field[a+2]==1&&!Flag&&a+1!=c){
 				a+=2;
 				field[a-2]=1;
 				field[a]=2;
 				cnt=0;
 			}
 			if(cnt>1){
 				cout << "No" << endl;
 				return 0;
 			}
 			cnt++;
 		}
 	}
 	else if(c>d){
 		while(!Flag||!Flag1){
 			if(a==c){
 				Flag=true;
 			}
 			if(b==d){
 				Flag1=true;
 			}
 			if(field[a+1]==1&&!Flag){
 				a++;
 				field[a-1]=1;
 				field[a]=2;
 				cnt=0;
 			}
 			else if(field[a+2]==1&&!Flag&&a+1!=c){
 				a+=2;
 				field[a-2]=1;
 				field[a]=2;
 				cnt=0;
 			}
 			else if(field[b+1]==1&&!Flag1){
 				b++;
 				field[b-1]=1;
 				field[b]=3;
 				cnt=0;
 			}
 			else if(field[b+2]==1&&!Flag1&&b+1!=d){
 				b+=2;
 					field[b-2]=1;
 				field[b]=3;
 				cnt=0;
 			}
 			if(cnt>1){
 				cout << "No" << endl;
 				return 0;
 			}
 			cnt++;
 		}
 	}
 	cout << "Yes" << endl;
 }

Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define MAX_E 1000000
#define MAX_V 100000
#define INF 1e9
typedef long long ll;
using namespace std;
/*??????????????????????????? O(V*E)*/

//??????from????????????to???????????????cost??????
struct edge{int from, to, cost;};
edge es[MAX_E]; //???
ll d[MAX_V];   //???????????¢
int V,E;        //V???????????°???E????????°

//s???????????????????????????????????????????????¢????±???????.
void Bellman_Ford(int s){
  for(int i=0; i<V ;i++) d[i]=INF;
  d[s]=0;
  while(true){
    bool update=false;
    for(int i=0; i<E ;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to]> d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	update = true;
      }
    }
    if(!update) break;
  }
}

//true??????????????????????????¨??????
bool find_negative_loop(){
  memset(d,0,sizeof(d));

  for(int i=0; i<V ;i++){
    for(int j=0; j<E ;j++){
      edge e = es[j];
      if(d[e.to] > d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	
	//n??????????????´??°???????????????????????????????????¨?????????
	if(i == V-1) return true;
      }
    }
  }
  return false;
}

int main(){
  cin>>V;
  for(int i=0;i<V;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0,v,c;j<k;j++){
      cin>>v>>c;
      es[E++]=(edge){u,v,c};
    }
  }
  Bellman_Ford(0);
  for(int i=0;i<V;i++)
    cout<<i<<' '<<d[i]<<endl;
  /*  for(int i=0;i<V;i++){
    Bellman_Ford(i);
    cout <<i<<" "<<d[0]<<endl;
  }*/
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int x,n,a;
  int p[1000]={};
  cin>>x>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    p[a]=1;
  }
  int num=0,ab=x;
  for(int i=-10000;i<=10000;i++){
    if(ab>abs(x-i)&&p[i]==0){
      ab=abs(x-i);
      num=i;
    }
  }
  cout<<num<<"\n";
}

Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}



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

    ll N;
    cin >> N;

    ll ans = 1;

    for(ll i = 1; i <= N ; i++){
        for(ll j = 2; j<=N ; j++){

            ll a = pow(i, j);
            if(a > N) continue;
            ans = max(ans, a);
        }
    }
    cout << ans << endl;

	//cout << fixed << setprecision(16) << ans << endl;
	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define pb              push_back
#define se              second
#define mp              make_pair
#define fi              first
#define del(a,vec)      vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f,l,v)   binary_search(f,l,v)
#define iter(a,b)       vector<int>::iterator a,b
#define lower(v,num)    lower_bound (v.begin(), v.end(), num);
#define upper(v,num)    upper_bound (v.begin(), v.end(), num); 
#define removecopy(a)   unique(a.begin(), a.end()); 
#define vi              vector<int> 
#define pi              pair<int,int>    
#define vpi             vector<pi>      
#define mlbb            ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)    
int mod =1000000007;
namespace Rahul{
    bool isPrime(int n) 
    {if (n <= 1)  return false; if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; }
    int pow (int x, int n,int mod) {//calculate x^n
    if (n == 0) return 1;
 
    int res = pow (x, n / 2,mod);
 
    res = (res * res) % mod;
    if (n % 2) res = (res * x ) % mod;
 
    return res;
    }
    int _gcd(int a,int b)
    {
        if(a==0)
            return b;
        else    
            return _gcd(b%a,a);
    }
    //s.erase(s.find(2)) where s={1,2,3,3,2}; 
};
using namespace Rahul;
int32_t main()
{
        
	     mlbb;   
     unordered_map<int,int>cn;
     unordered_map<int,int>wn;
     int k,n;
     cin>>k>>n;
    int wa,ac;
    ac=wa=0;
    
     for(int i =0 ; i < n ; i ++){
         
         int a; string b;
         cin>>a>>b;
         
         if(b=="AC")
            {
                cn[a]=1;
            }
         if(b=="WA" && cn[a]==0){
             
             wa++;
             wn[a]++;
         }    
            
            
     }
     for(int i=1;i<=k;i++)  {
         if(cn[i]) ac++;
         
         if(cn[i]==0)
         wa -=wn[i];
     }
     cout<<ac<<" "<<wa<<endl;
}


Measured memory_bytes: 8520
#include<iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <math.h>
#include <stack>
#include <cctype>
using namespace std;
#define int long long
#define pi 2*acos(0.0)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)

signed main()
{

	string abc = "abcdefghijklmnopqrstuvwxyz";
	vector<int> cc(abc.length(), 0);
	string s;
	cin >> s;
	REP(i, s.length()){
		REP(j, abc.length()){
			if (s[i] == abc[j]){ cc[j]++; break; }
		}
	}
	bool clear = true;
	REP(i, abc.length()){
		if (cc[i] % 2 == 1){
			clear = false;
			break;
		}
	}
	if (clear == false) cout << "No" << endl;
	else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>

using namespace std;
using ll = long long;
 
int main(){
    int n;
    cin >> n;

    string s;
    cin >> s;   

    int len = s.size();

    vector<int> a(n);
    vector<ll> num(3);
    num[0] = 0;
    num[1] = 0;
    num[2] = 0;
    
    

    for(int i=0;i<len;i++){
        if(s[i] == 'R') {
            a[i] = 0;
            num[0]++;
        }
        if(s[i] == 'G'){
            a[i] = 1;
            num[1]++;
        } 
        if(s[i] == 'B') {
            a[i] = 2;
            num[2]++;
        }
    }
    ll ans = num[0]*num[1]*num[2];

    int k;

    for(int j=0;j<n;j++){
        for(int i=0;i<j;i++){
            k = j + j - i;
            if(k < n){
                if(a[i] == a[j] || a[i] == a[k] || a[j] == a[k]) continue;
                ans--;
            }
        }
    }
    cout << ans << endl;
}   

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

int main(){
	int n, r;
	cin >> n >> r;
	
	if(n >= 10)
		cout << r << endl;
	else
		cout << (100*(10-n))+r << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





class BIT
{
private:
    ll b;    // bit.size() < 2^n になる最小の2^n
    vector<ll> bit;
public:
    BIT(ll n);   // nは要素数
    ll sum(ll i); // iまでの合計
    void add(ll i, ll x); // i番目にxを加算
    ll lower_bound(ll x); // x番目に小さい値を返す
};

BIT::BIT(ll n){
    bit.resize(n + 1);
    
    b = 1;
    while(b <= n){
        b <<= 1;
    }
}

ll BIT::sum(ll i){
    ll sum = 0;
    
    for(i++; i > 0; i -= i & -i){
        sum += bit[i];
    }
    
    return sum;
}

void BIT::add(ll i, ll x){
    for(i++; i < bit.size(); i += i & -i){
        bit[i] += x;
    }
}

ll BIT::lower_bound(ll x){
    ll res = 0;
    
    for(ll i = b; i > 0; i >>= 1){
        if(res + i < bit.size() && bit[res + i] < x){
            x -= bit[res + i];
            res += i;
        }
    }
    
    return res;
}


int main() {
    ll n;
    cin >> n;
    vector<char> c(2 * n);
    vector<ll> a(2 * n);
    REP(i, 2 * n){
        cin >> c[i] >> a[i];
    }
    vector<ll> ww(n + 1), bb(n + 1);
    vector<vector<ll>> wb(n + 1, vector<ll>(n + 1)), bw(n + 1, vector<ll>(n + 1));
    BIT w_bit(n + 1), b_bit(n + 1);
    REP(i, 2 * n){
        if(c[i] == 'W'){
            ww[a[i]] = w_bit.sum(n) - w_bit.sum(a[i]);
            wb[a[i]][0] = b_bit.sum(n);
            for(ll j = 1; j <= n; j++){
                wb[a[i]][j] = b_bit.sum(n) - b_bit.sum(j);
            }
            w_bit.add(a[i], 1);
        }
        else{
            bb[a[i]] = b_bit.sum(n) - b_bit.sum(a[i]);
            bw[a[i]][0] = w_bit.sum(n);
            for(ll j = 1; j <= n; j++){
                bw[a[i]][j] = w_bit.sum(n) - w_bit.sum(j);
            }
            b_bit.add(a[i], 1);
        }
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, INF));
    dp[0][0] = 0;
    for(ll w = 0; w <= n; w++){
        for(ll b = 0; b <= n; b++){
            if(w < n) dp[w + 1][b] = min(dp[w + 1][b], dp[w][b] + ww[w + 1] + wb[w + 1][b]);
            if(b < n) dp[w][b + 1] = min(dp[w][b + 1], dp[w][b] + bb[b + 1] + bw[b + 1][w]);
        }
    }
    cout << dp[n][n] << endl;
}

Measured memory_bytes: 94336
h, w = gets.split.map(&:to_i)
board = Array.new(h) { gets.chomp }

sum = 0
visited = Hash.new { |hs, k| hs[k] = {} }

h.times do |y|
  w.times do |x|
    next unless board[y][x] == '#'
    next if visited[y][x]

    n_black = 0
    n_white = 0
    stack = [[x, y, false]]
    while !stack.empty?
      xx, yy, white = stack.pop

      next if xx < 0 || xx >= w || yy < 0 || yy >= h

      if white
        next unless board[yy][xx] == '.'
      else
        next unless board[yy][xx] == '#'
      end

      next if visited[yy][xx]
      visited[yy][xx] = true

      if white
        n_black += 1
      else
        n_white += 1
      end

      stack << [xx - 1, yy, !white]
      stack << [xx + 1, yy, !white]
      stack << [xx, yy- 1, !white]
      stack << [xx, yy + 1, !white]
    end
    sum += n_black * n_white
  end
end

puts(sum)

Measured memory_bytes: 56692
#include<cstdio>
#include<cstring>
#include<cctype>
#include<iostream>

using namespace std;
int main(void)
{
	while(1)
	{
		char a[10000] = {0};
		if(gets(a) == NULL) break;
		int as = strlen(a);
		for(int i = 0;i < 26;i++)
		{
			if(strstr(a,"this") || strstr(a,"that") || strstr(a,"the")) break;
			for(int j = 0;j < as;j++)
			{
				if(isalpha(a[j]) != 0)
				{
					if(a[j] < 'z')
					{
						a[j]++;
					}
					else
					{
						a[j] = 'a';
					}
				}
			}
		}
		printf("%s\n",a);
	}
	return 0;
}

Measured memory_bytes: 1112
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long K;
cin>>K;
int ans=0;
if(K%2 == 0 || K%5 == 0)
 ans =-1;
else
{
    long long num =7%K;
    ans++;
    while(num)
    {
        num = (num*10 + 7)%K;
        ans++;
    }
}

cout<<ans<<endl;
return 0;
}

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

using namespace std;

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

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

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

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


ll cnt(ll n){
	n--;
	ll res=1;
	ll cur=1,digit=1;
	while(10*cur<=n){
		res+=9*cur*digit;
		cur*=10;
		digit++;
	}
	res+=(n-cur+1)*digit;
	return res;
}

int main(void){
	ll k,n;
	while(cin >> n >> k,n){
		ll l=0,r=inf;
		while(r-l>1){
			ll m=(l+r)/2;
			if(cnt(m)<=n)
				l=m;
			else
				r=m;
		}
		string candiate="";
		for(ll i=l;i<=l+100;i++) candiate+=to_string(i);
		ll index=n-cnt(l);
		cout << candiate.substr(index,k) << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<map>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=5e5+10;
const ll mod=1e9+7;
ll suf[maxn],a[maxn];

int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=n;i>=1;i--) suf[i]=(suf[i+1]+a[i])%mod;
	ll ans=0;
	for(int i=1;i<=n;i++) ans=(ans+(a[i]*suf[i+1])%mod)%mod;
	cout<<ans; 
	return 0;	
} 

Measured memory_bytes: 6284
N, M = map(int, input().split())
for i in range((M + 1) // 2):
	print(i + 1, i + (M - 2 * i) + 1)
for i in range(M - (M + 1) // 2):
	print(M + 1 + i + 1, M + 1 + i + (M - 1 - 2 * i) + 1)

Measured memory_bytes: 75004
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll D, N;
  cin >> D >> N;

  ll ans = 1;
  while(D > 0){
    ans *= 100;
    D--;
  }

  if(N < 100)
    cout << ans * N << endl;
  else
    cout << ans * 101 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long int n;	cin >> n;	n;

  vector<int>	name;
  while(n){
    if(n%26==0){
      name.push_back(26);
      n-=26;
    }else{
      name.push_back(n%26);
      n-n%26;
    }
    n/=26;
  }
     
  reverse(name.begin(),name.end());
  for(int c:name){
    cout << char(c-1+'a');
  }
}

Measured memory_bytes: 3628