akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
P = [ [] for i in range(N+1) ]

wa = 0
ac = 0

for i in range(M):
  p, s = input().split()
  p = int(p)
  P[p].append(s)

for i in range(1, N+1):
  tmp_ac = 0
  tmp_wa = 0

  for s in P[i]:
    if s == "WA" and not tmp_ac > 0:
      tmp_wa += 1
    elif s == "AC" and not tmp_ac > 0:
      tmp_ac += 1

  if tmp_ac > 0:
    wa += tmp_wa
    ac += tmp_ac

print(ac, wa)

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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];
    
    int sum=0;
    for(int i=0; i<N; i++){
        sum += a[i]-1;
    }
    
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1e9+7;
const ll inf = (LLONG_MAX>>2);
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  //cout << fixed;
  //cout.precision(40);
  ll h,w,a,b;
  cin >> h >> w >> a >> b;
  for(ll i = 0; i < b; ++i){
    for(ll j = 0; j < a; ++j) cout << 1;
    for(ll j = a; j < w; ++j) cout << 0;
    cout << '\n';
  }
  for(ll i = b; i < h; ++i){
    for(ll j = 0; j < a; ++j) cout << 0;
    for(ll j = a; j < w; ++j) cout << 1;
    cout << '\n';
  }
  return 0;
}

Measured memory_bytes: 1280
#! /usr/bin/env python
#-*- coding: utf-8 -*-

''' ?????????????????? '''

# O(n^2)


def bubble_sort(A, N):
    swap_num = 0  # ?????????????????°

    for i in range(N - 1):
        for j in range(N - 1, i, -1):
            if A[j] < A[j - 1]:
                # swap
                temp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = temp
                swap_num += 1

    return (A, swap_num)


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    # A = [5, 2, 4, 6, 1, 3]
    # N = len(A)
    array_sorted, swap_num = bubble_sort(A, N)
    print(' '.join(map(str, array_sorted)))
    print(swap_num)

Measured memory_bytes: 7732
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		ProblemA solver = new ProblemA();
		solver.solve(1, in, out);
		out.close();
	}

	static class ProblemA {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			String s = in.next();
			out.println(s.substring(0, 4) + " " + s.substring(4));
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

	}
}



Measured memory_bytes: 8400
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define LLIandI pair<long long int , int>
#define ll long long

int main(void){
    char S[100002];
    scanf("%s",S);
    int ans1=0,ans2=0;
    rep(i,strlen(S)){
        if(S[i]-'0'==i%2)ans1++;
        else ans2++;
    }
    printf("%d\n",min(ans1,ans2));
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int x, y, z;
  std::cin >> x >> y >> z;
  int i;
  for (i = 1; (i * y) + ((1 + i) * z) <= x; i++)
    ;
  std::cout << --i << std::endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

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

    int n;
    cin >> n;
    
    int m;
    m=sqrt(n);
    n=m*m;
    cout << n;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 1000005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,a[MAXN];
int p[MAXN];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) p[a[i]]=i;
    for(int i=1;i<=n;i++) printf("%d%c",p[i],i==n?'\n':' ');
    return 0;
}

Measured memory_bytes: 5248
<>;@D=(1)x2e6;$s=.5;($x^=$_)?$P[$x]+=($D[$x]+=$P[$x]*($%-$c[$x]))%=$=:($%++,$s=$s*2%($==1e9+7)),$c[$x]=$%for split$",<>;$s+=$_ for@P;print$x?$D[$x]:$s%$=

Measured memory_bytes: 189184
#include<bits/stdc++.h>
#define U [7<<15]={}
#define G )+((c=A[a]+A[P[a]]+C[a])%k?c:0)-M(
typedef long long L;using namespace std;map<L,L>T U;
L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c;char s U;
L M(L f){return f?B[f]+M(f^f&-f):0;}
L S(L a,L i){for(a=M(i++G i);i<2e5;i+=i&-i)B[i]+=a;}
L W(L f){X[f]=n;S(f=H[f],O[f]=++b);f&&W(f);}
L D(L f){L d;Z[f]=1;for(map<L,L>::iterator I=T[f].begin();I!=T[f].end();I++)
  d=I->first,!Z[d]?P[d]=f,E[d]=E[f]+1,C[d]=I->second,D(d),Z[f]+=Z[d],!H[f]|Z[H[f]]<Z[d]?H[f]=d:0:0;}
L K(L f){a=X[f];n=X[b];return a-n?M(O[E[a]<E[n]?a=n,n=b,b=f,n:f]G O[a])+K(P[a]):abs(M(O[f])-M(O[b]));}
main(){for(cin>>n>>k;--n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
       for(D(a=b=0);n<*Z;a=H[P[++n]]-n?n:0)!b|a?W(a):0;//for(;!b|a;S(a=H[a],O[a]=++b))X[a]=n;
       for(cin>>a;cin>>s>>a>>b;S(H[a],O[a]),S(a,O[a]-1))*s&2?cout<<K(a)<<endl,0:A[a]+=b;}

Measured memory_bytes: 38112
#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <algorithm> //sort()
#include <math.h>

using namespace std;

vector<uint64_t> divisors(uint64_t n);

long a, b, c, d, i, j, k, n;


int main(){
//////////////////////////////////////////////////////


    //cout << "Hello, World!" << endl;

    cin >> n;

    
    vector<uint64_t> div;


    div = divisors(n);

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

    // for (uint64_t  i = 0 ; i < div.size() ; i ++ )
    // {
    //     cout << "div[" << i << "]=" << div[i] << endl;
    // }

    uint64_t sum = 0;
    uint64_t cnt = 0;
    uint64_t root = sqrt(n);
    for ( uint64_t  i = 1 ; i < div.size() ; i ++ )
    {
        if ( div[i] <= root )continue;
        if ( div[i] == div[i - 1] + 1 )continue;
        cnt ++;
        sum += div[i] - 1;
    }

   // vector<uint64_t> anss(cnt);

    // cnt = 0;
    // for ( uint64_t  i = 1 ; i < div.size() ; i ++ )
    // {
    //     if ( div[i] <= root )continue;
    //     if ( div[i] == div[i - 1] + 1 )continue;
    //     anss[cnt] = div[i] - 1;
    //     cnt ++;
    // }

    // for (uint64_t  i = 0 ; i < anss.size() ; i ++ )
    // {
    //     //cout << "anss[" << i << "]=" << anss[i];

    //     uint64_t syo = n / anss[i];
    //     uint64_t amr = n % anss[i];
    //     if ( syo == amr )cout << "[o]" ;
    //     else cout << "[x]" ;
    //     //cout << " " << syo << "..." << amr;

    //     //cout << endl;
    // }

    // uint64_t root = sqrt(n);
    // for (uint64_t  i = 0 ; i < anss.size() ; i ++ )
    // {
    //     if (anss[i] > root)
        
    //     cout << "anss[" << i << "]=" << anss[i];

    //     uint64_t syo = n / anss[i];
    //     uint64_t amr = n % anss[i];
    //     if ( syo == amr )cout << "[o]" ;
    //     else cout << "[x]" ;
    //     cout << " " << syo << "..." << amr;

    //     cout << endl;
    // }


    // cout << "n:" << n << endl;

    // vector<long> input(n);
    // for (int i = 0 ; i < n ; i ++ )
    // {
    //     cin >> input[i];
        // cout << "input[" << i << "]=" << input[i] << endl;
    // }

    // sort(input.begin() , input.end());

    // uint64_t max = numeric_limits<uint64_t>::max();



    // long sum = 0;
    // for ( int m = n - 1 ; i  ; i -- )
    // {
    //     sum += i;
    // }

    



   //cout <<  "cnt:" << cnt << endl;



    cout <<  sum << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


vector<uint64_t> divisors(uint64_t n)
{
    vector<uint64_t> res;
    for(uint64_t i = 1; i*i <= n; ++i) {
        if(n % i != 0) continue;
        res.push_back(i);
        if(n/i == i) continue; // 上の行で追加済み。
        res.push_back(n/i);
    }
    return res;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef   long long int ll;
using namespace std;
int main ()
{
     ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    ll n,r;cin>>n>>r;
    if (n>=10) cout<<r<<endl;
    else {
        cout<<100*(10-n)+r<<endl;
    }
}





Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long x4 = 0;
  long x2 = 0;
  long odd = 0;

  long N;
  cin >> N;
  rep (i, N) {
    long a;
    cin >> a;
    if (a % 4 == 0) x4++;
    else if (a % 2 == 0) x2++;
    else odd++;
  }

  long to_cover = odd;
  if (x2 > 0) to_cover++;
  if (x4 >= to_cover - 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const ll  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1000000007;

/*vll adj[MAXN];ll visit[MAXN]={};
ll dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
ll dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
*/
// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m,k,d,w;
string s,t;
//vll a,b;
// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN(ll _) {
	cin >> n >> k;
	ll ans = 0;
	ll val = n/k;

	ans += val * val * val;

	if(k%2==0) {
		k/=2;
		ll val1 = n/k - val;
		ans += val1 * val1 * val1;
	}

	cout<<ans;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	for(ll i=1;i<=T;i++) {
		MAIN(i);
	}
	return 0;
}



Measured memory_bytes: 3624
# coding=utf-8
# Date: 2020-01-08
# Author: lee215
get = lambda: int(raw_input().strip())
getl = lambda: raw_input().strip()
gets = lambda: list(map(int, raw_input().strip().split()))
getss = lambda n: [gets() for _ in range(n)]


H, N = gets()
AB = getss(N)
AB.sort(key=lambda a_b: -a_b[0] * 1.0 / a_b[1])

a0, b0 = AB[0]
dp = [0] + [float('inf')] * (H + a0)

cur = 0
while cur <= H + a0:
    dp[cur] = cur // a0 * b0
    cur += a0


for a, b in AB[1:]:
    for i in range(a, H + a0 + 1):
        dp[i] = min(dp[i], dp[i - a] + b)
print(min(dp[H:]))


Measured memory_bytes: 33132
n = int(input())
for i in range(1, n + 1):
  if i % 3 == 0:
    print(" {}".format(i), end = "")
  else:
    x = i
    while x:
      if x % 10 == 3:
        print(" {}".format(i), end = "")
        break
      x //= 10
print()



Measured memory_bytes: 5872
//#define LOCAL
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string>
#include<math.h>
#include<map>
#include<random>
#include<stack>
using namespace std;
using lld = long long int;
using llu = unsigned long long int;
using pii = pair<int, int>;
using pli = pair<lld, int>;
using pil = pair<int, lld>;
using pll = pair<lld, lld>;
using piii = pair<pii, pii>;
using pdii = pair<int, pii>;
int n, m;
pii a[1000009];
int mark[1000009];
bool test() {
	int i, j, k;
	for (i = 0; i <= n; i++) {
		mark[i] = 0;
	}
	for (k = 0; k < m; k++) {
		i = a[k].second - a[k].first;
		if (i < 0)i += n;
		mark[i]++;
		mark[n - i]++;
	}
	int cnt = 0;
	for (i = 1; i <= n; i++) {
		if (mark[i] > 1) {
			cnt++;
			//printf("fail at %d %d\n", i, mark[i]);
		}
	}
	//printf("cnt : %d\n", cnt);
	for (k = 0; k < cnt / 2; k++) {
		a[m - k - 1].second--;
	}
	for (i = 0; i <= n; i++) {
		mark[i] = 0;
	}
	for (k = 0; k < m; k++) {
		i = a[k].second - a[k].first;
		if (i < 0)i += n;
		mark[i]++;
		mark[n - i]++;
	}
	if (mark[a[m - cnt / 2 - 1].second - a[m - cnt / 2 - 1].first] > 1) {
		a[m - cnt / 2 - 1].second--;
	}
	return cnt;
}
int main() {
	int i, j, k, l;
	int t = 1, tv = 0;
	while (t--) {
		scanf("%d %d", &n, &m);
		if (n % 2 == 1) {
			for (i = 1, j = n, k = 0; k < m; k++, i++, j--) {
				a[k] = pii(i, j);
			}
		}
		else {
			bool ting = 0;
			for (i = 1, j = n, k = 0; k < m; k++, i++, j--) {
				a[k] = pii(i, j);
			}
			if (test()) {
				test();
			}
		}
		for (k = 0; k < m; k++) {
			printf("%d %d\n", a[k].first, a[k].second);
		}
	}
}

Measured memory_bytes: 2740
#include<iostream>
#include <cstddef>
#include<set>
#include<stack>
#include <deque>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<cmath>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#define  ll  long long
#define ull unsigned long long
#define  sl(a)  scanf("%lld",&a)
#define  si(a)  scanf("%d",&a)
#define mem(n,m) memset(n,m,sizeof(n))
#define PI acos(-1)
#define pb    push_back
#define pf    push_front
#define vll   vector<ll>
#define pll   pair<ll,ll>
#define mp  make_pair
#define vpll vector< pair <ll,ll> >
#define vplpll vector<pair<ll,pair<ll,ll> > >
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S(X) ( (X) * (X) )
#define forab(i, a, b) for(i = a; i <= b; i++)
#define forn(i, n) for(i = 0; i < n; i++)
#define print(a,b) printf("Case %lld: %lld\n",a,b)
using namespace std;
ll powd(ll a,ll b){if(b==1){return a;}if(b%2==1){return powd(a,b-1)*a;}else{ll x=powd(a,b/2); return x*x;}}
ll powm(ll a,ll b,ll m){if(b==0){return 1;}if(b==1){return a%m;}if(b%2==1){return ((powm(a,b-1,m)%m)*(a%m))%m;}else{ll x=powm(a,b/2,m); return ((x%m)*(x%m))%m;}}
ll gcd(ll a,ll b){if(a==0){return b;}return gcd(b,a%b);}
int main()
{
    ll s,d,t;
    sl(s);
    sl(d);
    sl(t);
    double ans=(double)s/(t*1.0);
    if(ans<=(double)d)
    {
        //cout<<ans<<endl;
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3760
use std::io::*;
//use std::str::FromStr;

fn main() {
    let stdin = stdin();
    let mut lock = stdin.lock();
    let mut str1 = String::new();
    lock.read_line(&mut str1).unwrap();
    let text: Vec<_> = str1.trim().chars().collect();
    let mut c = 0usize;
    'main: for a in (1..text.len()/2).rev() {
        for b in (0..a) {
            if text[b] == text[a + b] {
                if b >= a - 1 {
                    c = a;
                    break 'main;
                }
                continue;
            } else {
                break;
            }
        }

    }
    println!("{}", c * 2);
    /*
    let leng = text.len() - 1;
    let mut k = 0usize;
    'main: for (i, _) in text.iter().enumerate().rev() {
        if i % 2 == 1 || i == leng {
            continue 'main;
        }
        'inner: for (j, _) in text.iter().enumerate() {
            if j % 2 == 1 {
                continue 'main;
            } else {
                if (i/2 + j >= leng) {
                    k = i;
                    break 'main;
                }
                if text[i/2 + j] == text[j] {
                    continue 'inner;
                } else {
                    break 'inner;
                }
            }
        }
        
    }
    println!("{}", k);
    //println!("{}", vec[0] + vec[1]);
    */
}


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

int main() {
	int N, S = 0;
	cin >> N;
	int n = N;
	while (n != 0) {
		S += n % 10;
		n /= 10;
	}
	if (N % S == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define vl vector<ll>
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {

    ll N;
    cin >> N;
    N--;

    string ans = "";
    while(N >= 0) {
        int a = N % 26;
        char c = 'a' + a;
        ans = c + ans;
        N /= 26;
        N--;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int N = sc.nextInt();
        int x=0;
        int s,f;
        
        for(int i=0;i<N;i++){
        	s = sc.nextInt();
        	f = sc.nextInt();
        	if((b>s) && (f>a)){
        		System.out.println(1);
        		x =1;
        		return;
        	}
        }
        if(x==0){System.out.println(0);}
    }
}

Measured memory_bytes: 26500
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
#define MOD 1000000007
const double pi=acos(-1); // value of pi


bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}


bool isPrime(ll n) {
    if(n%2==0 && n!=2) {
        return false;
    }
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

ll binary_exp(ll x, ll n, ll mod)
{
    if (n == 0) {
        return 1;
    } else if (n == 1) {
        return x % mod;
    } else {
        ll temp = binary_exp(x, n / 2, mod);
        temp = (temp * temp) % mod;

        if (n % 2 == 0) {
            return temp;
        } else {
            return ((x % mod) * temp) % mod;
        }
    }
}

map<ll, list<ll>> m;
// map<ll, ll> m;

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    //cin >> t;
    while(t--) {
        ll n, k, x, y, ans=0;
        cin >> n >> k;
        for(ll i=0; i<k; i++) {
            cin >> x >> y;
            m[x].push_back(y);
            m[y].push_back(x);
        }
        bool v[n+1];
        for(ll i=0; i<=n; i++) {
            v[i]=0;
        }
        list<ll> s;
        for(int i=1; i<=n; i++) {
            if(!v[i]) {
                ans++;
                s.push_front(i);
                while(!s.empty()) {
                    x=s.front();
                    s.pop_front();
                    v[x]=1;
                    for(auto j=m[x].begin(); j!=m[x].end(); j++) {
                        if(!v[*j]) {
                            s.push_front(*j);
                        }
                    }
                }
            }
        }
        cout << ans-1 << endl;
    }
}


Measured memory_bytes: 17320
#include<algorithm>
#include <bits/stdc++.h>
#include <math.h>
#include <queue>
using namespace std;
int main(void){
	int a,b,c;
	cin>>a>>b>>c;
	if(c>=a&&c<=b) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

fn keta(z: u64) -> Vec<usize> {
    (0..40).map(|i| if z & (1 << i) > 0 { 1 } else { 0 }).collect()
}

fn binum(xs: &Vec<u64>, z: u64) -> usize {
    xs.iter().filter(|&x| x & z > 0).count()
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let k: u64 = sc.cin();
    let xs: Vec<u64> = (0..n).map(|_| sc.cin()).collect();

    let mut free = vec![vec![0, 0]; 40];
    for i in 0..40 {
        let h = binum(&xs, 1 << i);
        free[i][0] = h;
        free[i][1] = n - h;
    }

    let ks = keta(k + 1);
    let mut ans = 0;

    for i in 0..40 {
        if ks[i] == 0 { continue; }
        let mut f = 0;
        for j in 0..i {
            f += max(free[j][0], free[j][1]) * (1 << j);
        }
        f += free[i][0] * (1 << i);
        for j in (i+1)..40 {
            f += free[j][ks[j]] * (1 << j);
        }
        ans = max(ans, f);
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 12324
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll mod=1e9+7;
 
using namespace std;

int main(){
	int q=1;
	//cin>>q;

	while(q--){
		ll n,k,ans=0;
		cin>>n>>k;
		
		n=n%k;
		ans=min(n,abs(n-k));

		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
N,M=map(int,input().split())
dp=[0]*(10**5+1)
table=[0]*(10**5+1)
for i in range(M):
    a=int(input())
    table[i]=a

dp[0]=1

count=0
if table[count]==1:
    dp[1]=0
    count+=1
else:
    dp[1]=1

for i in range(N-1):
    if i+2==table[count]:
        dp[i+2]=0
        count+=1
    else:
        dp[i+2]=dp[i+1]+dp[i]


print(dp[N]%1000000007)

Measured memory_bytes: 460788
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <iomanip>
using namespace std;
int n;
int cnt[3]={0};
vector<vector<vector<double>>>dp;
double cal(int a,int b,int c)
{
  int sum=a+b+c;
  if(a+b+c==0)return 0;
  double res=0;
  if(a>0){res+=dp[(sum+1)%2][b][c]*a;}
  if(b>0){res+=dp[sum%2][b-1][c]*b;}
  if(c>0){res+=dp[sum%2][b+1][c-1]*c;}
  res+=n;
  res=res/sum;
  //cout<<res;
  return res;
}
int main()
{
  ios::sync_with_stdio(false);
  std::cout<<fixed<<setprecision(10);
  cin>>n;

  for(int i=0;i<n;i++)
  {
    int tmp;
    cin>>tmp;
    cnt[tmp-1]++;
  }
  dp=vector<vector<vector<double>>>(2,vector<vector<double>>(n+1,vector<double>(n+1,-1)));
  for(int i=0;i<n+1;i++)
  {
    for(int j=i;j>=0;j--)
    {
      for(int k=j;k>=0;k--)
      {
        dp[i%2][j-k][i-j]=cal(k,j-k,i-j);
      }
    }
  }
  cout<<dp[n%2][cnt[1]][cnt[2]]<<endl;
  return 0;

}


Measured memory_bytes: 2432
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy


def odd(n): return n & 1


def even(n): return not odd(n)


def comb(n, m):
    r = 1
    for i in range(1, n+1):
        r *= i
    for i in range(1, m+1):
        r //= i
    for i in range(1, n-m+1):
        r //= i
    return r


N, P = map(int, input().split())
A = [int(n) % 2 for n in input().split()]
cnt0 = len([a for a in A if a == 0])
cnt1 = len([a for a in A if a == 1])
ans = 0
if odd(P):
    for i in range(cnt1 + 1):
        if odd(i):
            ans += comb(cnt1, i)
else:
    for i in range(cnt1 + 1):
        if even(i):
            ans += comb(cnt1, i)
ans *= pow(2, cnt0)
print(ans)


Measured memory_bytes: 9888
import math
m = 0
V = 0

while True:
    n = int(input())
    if n == 0:
        break
    else:
        S = list(map(int,input().split()))
        for i in range(n):
            m += S[i]
        m /= n
        for j in range(n):
            V += (S[j] - m ) ** 2
        V /= n
    print(V ** 0.5)
    m = 0
    V = 0



Measured memory_bytes: 5720
#include<iostream>
#include<ctype.h>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
int s,n,w,e;
int main(){
	string S;
	cin>>S;
	for(int i=0;i<S.length();++i){
		if(S[i]=='S')s=1;
		if(S[i]=='N')n=1;
		if(S[i]=='E')e=1;
		if(S[i]=='W')w=1;
	}
	if(s!=n || e!=w)cout<<"No\n";
	else cout<<"Yes\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cfloat>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;
using llong = long long;

llong n;
double p[105];
vector<vector<int>> g;
vector<vector<int>> rg;
vector<int> vs;
int cmp[105];
bool used[105];
double pp[105];
double mem[105];
int indeg[105];

//--- @see ant p.286
void dfs(int v) {
    used[v] = true;
    for (int i = 0; i < g[v].size(); i++) {
        if (!used[g[v][i]]) dfs(g[v][i]);
    }
    vs.push_back(v);
}

void rdfs(int v, int k) {
    used[v] = true;
    cmp[v] = k;
    for (int i = 0; i < rg[v].size(); i++) {
        if (!used[rg[v][i]]) rdfs(rg[v][i], k);
    }
}

int scc() {
    memset(used, 0, sizeof(used));
    vs.clear();
    for (int v = 1; v <= n; v++) {
        if (!used[v]) dfs(v);
    }
    memset(used, 0, sizeof(used));
    int k = 0;
    for (int i = vs.size() - 1; i >= 0; i--) {
        if (!used[vs[i]]) rdfs(vs[i], k++);
    }
    return k;
}
//===

double solve() {
    int m = scc();

    for (int i = 1; i <= n; i++) {
        pp[cmp[i]] *= p[i];
    }

    for (int i = 1; i <= n; i++) {
        for (auto u:g[i]) {
            if (cmp[i] != cmp[u]) indeg[cmp[u]]++;
        }
    }

    double ans = 1;
    for (int i = 0; i < m; i++) {
        if (indeg[i] == 0) ans *= (1 - pp[i]);
    }

    return ans;
}

int main() {
    while (cin >> n, n) {
        g.clear(); rg.clear();
        g.resize(n + 1); rg.resize(n + 1);
        for (int i = 0; i < 105; i++) pp[i] = 1;
        for (int i = 0; i < 105; i++) indeg[i] = 0;
        
        for (int i = 1; i <= n; i++) {
            llong m;
            llong a;
            cin >> p[i];
            cin >> m;
            for (int j = 0; j < m; j++) {
                cin >> a;
                g[i].push_back(a);
                rg[a].push_back(i);
            }
        }

        printf("%.*lf\n", DBL_DIG, solve());
    }
}



Measured memory_bytes: 3396
#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)
#define _ << " " <<
#define sz(x) ((int) x.size())

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

bool cmp(const point &A, const point &B) {
  return A.second < B.second;
}

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


  int n; cin >> n;

  ll sol = 0;
  vector<point> v;

  bool eq = true;

  int mn = 1e9 + 5;

  REP(i, n) {
    int a, b; cin >> a >> b;

    sol += a;

    if(a > b) {
      eq = false;
      mn = min(mn, b);
    }
  }

  if(eq) cout << 0;
  else cout << sol - mn;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();

		int count = 0;
		for(int numA = 0;numA <= a;numA++) {
		    for(int numB = 0;numB <= b;numB++) {
		        int numC = (x - (500 * numA + 100 * numB)) / 50;
		        int total = 500 * numA + 100 * numB + 50 * numC;
		        if(numC >= 0 && numC <= c && total == x) count++;
		    }
		}

		System.out.println(count);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
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;}
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<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};


int main(){
    ll n, ans = 0; cin >> n;
    rep(i, n){
        ll l, r; cin >> l >> r;
        ans += r-l+1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3532
#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)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int H, W;
string S[20];
int d[20][20];

int solve(int sy, int sx, int ey, int ex) {
	fill(d[0], d[H], INF);
	d[sy][sx] = 0;
	queue<pii> que;
	que.emplace(sy, sx);
	
	while (!que.empty()) {
		pii cur = que.front(); que.pop();
		int y = cur.fi, x = cur.se;
		
		int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
		REP(i, 4) {
			int nx = x + dx[i], ny = y + dy[i];
			if (nx < 0 || nx >= W || ny < 0 || ny >= H || S[ny][nx] == '#') continue;
			if (chmin(d[ny][nx], d[y][x] + 1)) que.emplace(ny, nx);
		}
	}
	
	return d[ey][ex];
}

int main() {
	cin >> H >> W;
	REP(i, H) cin >> S[i];
	
	int ans = -1;
	REP(i, H) REP(j, W) REP(k, H) REP(l, W)
		if (S[i][j] == '.' && S[k][l] == '.') chmax(ans, solve(i, j, k, l));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e9;
typedef pair<int, int> pi;
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll a, b, c, d;
    ll ans = (ll)-1e18;
    cin >> a >> b >> c >> d;
    ans = max({ ans,b * d,a * c,a * d,b * c });
    cout << ans;
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

  int n, p[51];
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> p[i];
  }
  int cnt=0;
  for(int i=0; i<n; i++){
    if(p[i]!=i+1){
      cnt++;
    }
  }
  if(2<cnt){
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }

	return 0;
}

Measured memory_bytes: 256
#define USE_MATH_DEFINES 1
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 998244353ll
#define INF 1000000000000000000ll
#define EPS 1e-9

#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock

typedef long long         ll;
typedef long double       ld;
typedef pair <ll,ll>      pl;
typedef tuple <ll,ll,ll>  tl;

ll N, K, D, C;
bool snacc[300005];

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> N >> K;
	memset(snacc, 0, sizeof snacc);
	for (ll i = 1; i <= K; i++) {
		cin >> D;
		for (ll j = 1; j <= D; j++) {
			ll x;
			cin >> x;
			snacc[x] = true;
		}
	}
	
	C = 0;
	for (ll i = 1; i <= N; i++) {
		if (!snacc[i]) C++;
	}
	
	cout << C;
	
    return 0;
}














Measured memory_bytes: 3928
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

#include <bits/stdc++.h>
using namespace std;



int main() {
    long long N;
    cin >> N;
    long long sum = 0;
    for(int i=1; i<=N; i++){
        if(i%3==0 || i%5==0){
            continue;
        }
        sum += i;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;

  pair<int, int> ans = make_pair(100, 0);

  for (int i = 0; i < f / 100 / a + 1; ++i)
  {
    for (int j = 0; j < f / 100 / b + 1; ++j)
    {
      if (i == 0 && j == 0)
        continue;
      int water = i * a * 100 + j * b * 100;
      for (int k = 0; k < e * water / 100 + 1; ++k)
      {
        for (int l = 0; l < e * water / 100 + 1; ++l)
        {
          int nacl = k * c + l * d;
          if (water + nacl <= f && nacl <= e * water / 100 && 1.0 * ans.second / ans.first * 100 < 1.0 * nacl / (nacl + water) * 100)
          {
            ans = make_pair(water + nacl, nacl);
          }
        }
      }
    }
  }
  if (ans.first == 100)
    ans.first *= a;
  cout << ans.first << ' ' << ans.second << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

// 5
public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int C = sc.nextInt();

        int[] B = new int[M];
        int[][] A = new int[N][M];
        
        for(int i = 0; i < M; i++)
        	B[i] = sc.nextInt();
        for(int i = 0; i < N; i++)
        	for(int j = 0; j < M; j++)
        		A[i][j] = sc.nextInt();

        int ans = 0;
        for(int i = 0; i < N; i++) {
            int ans_pat = 0;
            for(int j = 0; j < M; j++)
                ans_pat += A[i][j] * B[j];

            if(ans_pat + C > 0) ++ans;
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 37732
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  vector<int> ps(N), cs(N);
  F0R(i, N) {
    cin >> ps[i];
    ps[i]--;
  }
  F0R(i, N) {
    cin >> cs[i];
  }

  i64 result = INT64_MIN;

  vector<i64> ls; // 1周したときのスコア
  vector<int> bs; // 1周の長さ
  vector<int> as(N, -1);  // index->index of ls

  F0R(start, N) {
    //debug(start);

    // 1周スコア計算
    if (as[start] < 0) {
      int a = start, n = 0;
      i64 s = 0;
      while (as[a] < 0) {
        n++;
        as[a] = ls.size();
        s += cs[a];
        a = ps[a];
      }
      ls.push_back(s);
      bs.push_back(n);
    }

    i64 score = 0;
    int a = start;
    F0R(i, min(bs[as[start]], K)) {
      score += cs[a];
      i64 b = (K - i - 1) / bs[as[start]];
      if (ls[as[a]] > 0 && b > 0) {
        chmax(result, score + ls[as[a]] * b);
      }
      else {
        chmax(result, score);
      }
      a = ps[a];
    }

  }
  //Print(ls);
  //Print(bs);
  //Print(as);
  cout << result;
}
#endif


Measured memory_bytes: 3724
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a , b , c;
    cin >> a >> b >> c;
    char d = a[0] - 32 , e = b[0] - 32 , f = c[0] - 32;
    cout << d << e << f;
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll n; cin >> n;
	vector<ll> x(n), y(n), h(n);
	REP(i, n) cin >> x[i] >> y[i] >> h[i];

	ll t;
	for (t = 0; t < n; ++t)
		if (h[t] > 0) break;

	auto f = [&x, &y, &h](ll X, ll Y, ll H, ll index)
			 {
				 return max(H - abs(X-x[index]) - abs(Y-y[index]), 0ll);
			 };
	

	ll X, Y, H;
	for (X = 0; X <= 100; ++X)
	{
		for (Y = 0; Y <= 100; ++Y)
		{
			H = h[t] + abs(x[t] - X) + abs(y[t] - Y);
			//std::cout << "X : " << X << std::endl;
			// std::cout << "Y : " << Y << std::endl;
			bool ok{true};
			for (ll i = 0; i < n; ++i)
			{
				if (h[i] != f(X, Y, H, i))
					ok = false;
			}

			if (ok && H >= 1) goto exit;
		}
	}

 exit:
	std::cout << X << " " << Y << " " << H << std::endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long k = sc.nextLong();
    long ans = 0;
    for(long j = k + 1; j <= n; j++) {
      long t = n / j;
      long r = n - t * j;
      long a = (j - k) * t + Math.max(0, r - k + 1);
      ans += a;
    }
    if(k == 0) ans -= (n - k);
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
  int n,ans=0;
  int sh;
  cin>>n;
  vector<int> l(n);
  for(int i=0;i<n;i++){cin>>l[i];}
  sort(l.begin(),l.end());
  for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
          sh=l[i]+l[j];
          auto it =lower_bound(l.begin(),l.end(),sh);
          ans+=it-l.begin()-j-1;
      }
  }
  cout<<ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long
set < ll> primes;
 
int n,m;

bool isvalid(int x,int y)
{
    return (x>=0 && x<n && y>=0 && y<m);
}
int dx[]={0,0,1,-1,-1,1,1,-1};
int dy[]={1,-1,0,0,-1,1,-1,1};
void Sieve(ll n) 
{ 
    bool prime[n+1];
	for(ll i=0;i<n+1;++i)
		prime[i]=true;
    for (ll p=2;p*p<=n;++p) 
    {
        if (prime[p] == true) 
        {  
            for (ll i=2*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    }  
    for(ll p=2; p<=n; p++) 
       if (prime[p]) 
		primes.insert(p);  
}

ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
        return gcd(b % a, a); 
} 
ll powermod(ll x, ll y){
    if(y==0)
    return 1;
        
    if(y%2==0)
    return (powermod(x,y/2)*powermod(x,y/2))%mod;
    else
    return (((powermod(x,y/2)*powermod(x,y/2))%mod)*x)%mod;
}

void solve()
{
   int n;
   cin>>n;
   int a[n+1];
   int ans=0;
   for(int i=1;i<=n;i++)
   {
       cin>>a[i];
       if(i%2 and a[i]%2)ans++;
   }
   cout<<ans;
}
 
 

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
	int t=1;
	//cin>>t;
	while(t--)solve();
	    
   
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
using namespace std;
int main(int argc, char *argv[])
{
  for(;;) {
    int n, k, s;
    cin >> n >> k >> s;
    if(n == 0 && k == 0 && s == 0) break;
    int cnt = 0;
    for(int i = 0; i < 1<<n; i++) {
      int c = 0, ss = 0, ii = i;
	  while(ii != 0) {
		int x = ii & -ii;
		ii ^= x;
		ss += __builtin_ffs(x);
		c++;
	  }
      if(c == k && s == ss) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}



Measured memory_bytes: 2996
def determine_string_code(bracket_string):
  brackets_left = 0 # )
  brackets_right = 0 # (
  for char in bracket_string:
    if char == "(":
      brackets_right += 1
    else:
      if brackets_right > 0:
        brackets_right -= 1
      else:
        brackets_left += 1
  return (brackets_left, brackets_right)

def build_left(in_list):
  in_list.sort(key=lambda x: x[0])
  final_res = (0, 0)
  for res in in_list:
    if res[0]>final_res[1]:
      final_res = (final_res[0]+res[0]-final_res[1], res[1])
    elif res[0]<final_res[1]:
      final_res = (final_res[0], res[1]+final_res[1]-res[0])
    else:
      final_res = (final_res[0], res[1])
  return final_res

def build_right(in_list):
  in_list.sort(key=lambda x: x[1])
  final_res = (0, 0)
  for res in in_list:
    if final_res[0]>res[1]:
      final_res = (res[0]+final_res[0]-res[1], final_res[1])
    elif final_res[0]<res[1]:
      final_res = (res[0], final_res[1]+res[1]-final_res[0])
    else:
      final_res = (res[0], final_res[1])
  return final_res

n = int(input())
residues = list()
for _ in range(n):
  new_string = input()
  residues.append(determine_string_code(new_string))
first_half = list()
second_half = list()
for res in residues:
  if res[1] > res[0]:
    first_half.append(res)
  else:
    second_half.append(res)
first_res = build_left(first_half)
second_res = build_right(second_half)
if first_res[0] == 0 and second_res[1] == 0 and first_res[1] == second_res[0]:
  print("Yes")
else:
  print("No")

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

const int maxn = 1100;
const long long inf = (long long)1e18 + 1e9;

long long a[maxn];
long long b[maxn];
long long s[maxn];
vector<int> v[2];
vector<int> res;
int n;

inline void merge(int i, int j) {
	for(int k = j - 2; k >= i + 2; k -= 2) res.push_back(k);
	res.push_back(i + 1);
}

inline void print(const vector<int>& v) {
	int sz = v.size();
	for(int i = n - 1; i > v[sz - 1]; -- i) res.push_back(i);
	for(int i = sz - 1; i >= 1; -- i) merge(v[i - 1], v[i]);
	for(int i = 0; i < v[0]; ++ i) res.push_back(0);
	cout << res.size() << "\n";
	for(auto x : res) cout << x + 1 << "\n";
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 0; i < n; ++ i) {
		cin >> a[i];
		if(a[i] > 0) v[i & 1].push_back(i);
	}
	long long ans1 = 0, ans2 = 0;
	for(auto x : v[0]) ans1 += a[x];
	for(auto x : v[1]) ans2 += a[x];
	if(ans1 > ans2) {
		cout << ans1 << "\n";
		print(v[0]);
	} else {
		if(ans2 == 0) {
			ans2 = -inf; int pos;
			for(int i = 0; i < n; ++ i) {
				if(ans2 < a[i]) {
					ans2 = a[i];
					pos = i;
				}
			}
			v[1].push_back(pos);
		}
		cout << ans2 << "\n";
		print(v[1]);
	}
	return 0;
}


Measured memory_bytes: 256