akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
#define YMAX 250001
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
struct UnionFind{
  vector<int> par;
  vector<int> sizes;
  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (sizes[x] < sizes[y]) swap(x, y);
    par[y] = x;
    sizes[x] += sizes[y];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return sizes[root(x)];
  }
};
int main(){
	int N,M;
	int A[100001],B[100001];
	scan(N);scan(M);
	rep(i,M){
		scan(A[i]);scan(B[i]);
		A[i]--;B[i]--;
	}
	UnionFind uf(N*2);
	rep(i,M){
		uf.unite(A[i],B[i]+N);
		uf.unite(A[i]+N,B[i]);
	}
	bool bipartite = true;
	rep(i,N){
		if(uf.same(i,N+i)) bipartite = false;
	}
	if(bipartite){
		int B=0,W=0;
		rep(i,N){
			if(uf.same(0,i)) B++;
			else W++;
		}
		prin((ll)B*W-M);
	}
	else{
		prin((ll)N*(N-1)/2-M);
	}
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
int main()
{
//    cout << cos(0) << endl;
//    cout << cos(pi/4) << endl;
//    cout << cos(pi/2) << endl;
//    cout << cos(pi) << endl;
    double x,y;
    double h,m;
    cin >>x>>y>>h>>m;
    long double tri = (h*60+m-m*12+720);
    cout << fixed << setprecision(13);
    long double d = x*x+y*y-2*x*y*cos(pi*tri/360.0);
    cout << (long double)sqrt(d) << endl;
    return 0;
}


Measured memory_bytes: 4188
# coding:utf-8

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
# print(c)
black = 0
ans = 0

for bit_h in range(2**h):
    for bit_w in range(2**w):
        black = 0
        for i in range(h):
            if not ((bit_h >> i) & 1):
                continue
            for j in range(w):
                if not ((bit_w >> j) & 1):
                    continue
                if c[i][j] == '#':
                    black += 1
        if black == k:
            ans += 1
print(ans)

Measured memory_bytes: 9064
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

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

    int n; cin >> n;

    vector<int> ans(n);

    for (int i = 0; i < n; ++i) {
        int u; cin >> u;
        ans[u - 1] = i + 1;
    }

    for (int i = 0; i < n; ++i)
        cout << ans[i] << " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 1280
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int N,M;
vi a,b,d;
string S;
set<int>e;
void input(){
	cin>>N;
	d.resize(N+1);
	rep(i,N){
		cin>>d[i];
		e.insert(d[i]);
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	int cnt=0;
/*	rep(i,N){
		rep(j,N){
			rep(k,N){
				if(i==j||j==k||k==j)continue;
				if(d[i]<d[j]&&d[j]<d[k])
					cnt++;
			}
		}
	}*/
	P(e.size())
	return 0;
}



Measured memory_bytes: 256
#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> P;
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 SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

int main(void){
    int N; cin >> N;
    vector<ll> A(N); REP(i,N){cin >> A[i]; A[i] -= i+1;}
    SORT(A);
    ll ans=0;
    if(N%2){
        ll b = A[(N-1)/2];
        REP(i,N) ans += abs(b-A[i]);
    }
    else{
        ll b1=A[N/2], b2=A[N/2-1], ans1=0, ans2=0;
        REP(i,N) ans1 += abs(b1-A[i]);
        REP(i,N) ans2 += abs(b2-A[i]);
        ans = min(ans1,ans2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
def main():
    n = int(input())
    a = list(map(int, input().split()))
      
    l = set()    
    free = 0
    for aa in a:
        if aa // 400 >= 8:
            free += 1
        else:
            l.add(aa // 400)
    print(max(1,len(l)), len(l) + free)
        
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    int n, k; cin >> n >> k;
    double ans = 0;
    rrep(i, 1, n + 1) {
        int now = i;
        double tmp = 1.0 / n;
        while (now < k) {
            now *= 2;
            tmp *= 0.5;
        }
        //cout << now << endl;
        ans += tmp;
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;



int main()
{	
	vector<int>v(10);
	for(int i=0;i<10;i++)cin>>v[i];
	sort(v.begin(),v.end(),greater<int>());
	cout<<v[0]<<endl;
	cout<<v[1]<<endl;
	cout<<v[2]<<endl;
	return 0;	
}


Measured memory_bytes: 3104
P = (10**9)+7
N,K = map(int,input().split())
A = list(map(int,input().split()))
res_p = 0
res_n = 0

for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            res_p += 1
        if A[-i-1]>A[-j-1]:
            res_n += 1
res = (K * res_p)
res += (res_p + res_n) * (K * (K-1) // 2)
print(int(res % P) )



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

string s;
int c, c2;

int main() {
  cin>>s;
  for(int i=0; i<3; i++){
    if(s[i]=='A'){
      c+=1;
    }
    else if(s[i]=='B'){
      c2+=1;
    }
  } 
  if(c==2||c2==2){
    cout<<"Yes\n";
  }
  else{
    cout<<"No\n";
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			char T = sc.next().charAt(0);
			if (T == '#') {
				sc.close();
				break;
			}

			int[] points = new int[4];
			int[][] cards = new int[4][13];
			char[][] suits = new char[4][13];

			for (int i = 0; i < cards.length; i++) {
				for (int j = 0; j < cards[i].length; j++) {
					String card = sc.next();
					if (card.charAt(0) == 'T') {
						cards[i][j] = 10;
					} else if (card.charAt(0) == 'J') {
						cards[i][j] = 11;
					} else if (card.charAt(0) == 'Q') {
						cards[i][j] = 12;
					} else if (card.charAt(0) == 'K') {
						cards[i][j] = 13;
					} else if (card.charAt(0) == 'A') {
						cards[i][j] = 14;
					} else {
						cards[i][j] = Character.getNumericValue(card.charAt(0));
					}
					suits[i][j] = card.charAt(1);
				}
			}

			int winner = 0;
			for (int i = 0; i < cards[0].length; i++) {
				char field = suits[winner][i];
				for (int j = 0; j < cards.length; j++) {
					if (suits[j][i] == T) {
						cards[j][i] += 26;
					} else if (suits[j][i] == field) {
						cards[j][i] += 13;
					}
				}

				int max = 0;
				for (int j = 0; j < cards.length; j++) {
					if (cards[j][i] > max) {
						max = cards[j][i];
						winner = j;
					}
				}
				points[winner]++;
			}

			if (points[0] + points[2] > points[1] + points[3]) {
				System.out.println("NS " + (points[0] + points[2] - 6));
			} else {
				System.out.println("EW " + (points[1] + points[3] - 6));
			}
		}

	}
}

Measured memory_bytes: 24768
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i > (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		ll n,m;
		cin>>n>>m;
		ll a;
		FOR(i,0,m)
		{
			cin>>a;
			n-=a;
		}
		if(n>=0)
		{
			cout<<n;
		}
		else
		{
			cout<<-1;
		}
	}
	return 0;
}


Measured memory_bytes: 3644
#include <cstdio>

int p10[10];
int max(int a,int b){return a>b?a:b;}

int tejun2(int n){
  int ans=-1;
  for(int i=1; p10[i]<n; i++)
    ans=max(ans,(n/p10[i])*(n%p10[i]));
  return ans;
}

int main(){
  p10[0]=1;
  for(int i=1; i<10; i++)p10[i]=p10[i-1]*10;

  int Q,N;

  scanf("%d",&Q);
  for(int i=0; i<Q; i++){
    int cnt;
    scanf("%d",&N);
    for(cnt=0; N>=10&&cnt<100000; cnt++){
      N=tejun2(N);
    }
    if(cnt==100000)
      printf("-1\n");
    else
      printf("%d\n",cnt);
  }
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

    int ans = 0;
    rep2(i, 1, N + 1)
    {
        int cnt = 0;
        int tmp = i;
        while (tmp)
        {
            cnt++;
            tmp /= 10;
        }
        if (cnt % 2 == 1)
        {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    
    if (B == 1) {
      System.out.println(0);
      return;
    }

    int i = A;
    int count = 1;
    while (i < B) {
      i += A - 1;
      count++;
    }
    
    System.out.println(count);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int n,k,cnt,MAX,ans;
string s;
char L;
vector<int> v;
int main(void){
    cin>>n>>k>>s;
    s='1'+s+'1';
    cnt=0;
    L='1';
    cnt=1;
    for(int i=1;i<s.size();i++){
        if(s[i]=='0'){
            if(L=='0')cnt++;
            else{L='0';v.push_back(cnt);cnt=1;}
        }
        else{
            if(L=='1')cnt++;
            else{L='1';v.push_back(cnt);cnt=1;}
        }
    }
    v.push_back(cnt);
    if(v.size()<=2*k+1){
        for(int x:v)ans+=x;
        cout<<ans-2<<endl;
        return 0;
    }
    
    for(int i=0;i<2*k+1;i++)ans+=v[i];
    MAX=ans-1;
    for(int i=0;i<(v.size()-2*k-1)/2;i++){
        ans-=v[i*2]+v[i*2+1];
        ans+=v[2*(k+i)+1]+v[2*(k+i)+2];
        if(i==(v.size()-2*k-1)/2-1)MAX=max(ans-1,MAX);
        else MAX=max(ans,MAX);
    }
    cout<<MAX<<endl;
}


Measured memory_bytes: 1016
import sys
n,y = map(int, sys.stdin.readline().split())
for a in range (n+1):
    for b in range(n+1-a):
        c = n-a-b
        if 10000*a + 5000*b + 1000*c == y:
            print(a,b,c)
            break
    else:
        continue
    break
if 10000*a + 5000*b + 1000*c != y:
    print(-1,-1,-1)

Measured memory_bytes: 40684
# -*- coding: utf-8 -*-
n,h,w = input().split()
n = int(n)
h = int(h)
w = int(w)
i = o = 0
for i in range(n):
    i = i + 1
    a,b = input().split()
    a = int(a)
    b = int(b)
    if a>=h and b>=w:
        o = o + 1
print(o)

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>

#define PI 3.1415926535

int main (void) {
    int a, b, c;
    double s, l, h;
    double ac;

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

    ac = c * PI / 180;
    s = a * b * sin(ac) / 2;
    l = a + b + sqrt(pow(a, 2)+pow(b, 2)-2*a*b*cos(ac)); 
    h = b * sin(ac);

    printf ("%lf\n%lf\n%lf\n", s, l, h);

    return 0;
}


Measured memory_bytes: 2048
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;

int64 pow(int a,int b,int mod){
    vector<bool> bit;
    for(b=b;b>0;b>>=1){
        bit.push_back(b&1);
    }
    vector<int64> fac(bit.size()); fac[0] = a;
    int64 res = 1;
    for(int i=1;i<bit.size();i++){
        fac[i] = (fac[i-1] * fac[i-1])%mod;
    }
    for(int i=0;i<bit.size();i++){
        if(bit[i]) res*=fac[i];
        res%=mod;
    }
    return res;
}


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int64 M,N;
    cin >> M >> N;
    cout << pow(M,N,MOD) << bn;
}


Measured memory_bytes: 3172
import java.util.*;

public class Main {


    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);

       String str1 = sc.nextLine();
       String str2 = sc.nextLine();

       if (str1.equals(str2)) {
           System.out.println("Yes");
           return;
       }

        for (int i = 0; i < str1.length(); i++) {
            str1 = str1.charAt(str1.length() - 1) + str1.substring(0, str1.length() -1);
            if(str1.equals(str2)) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");;
    }

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; i++) cin >> x[i];
  vector<int> y = x;
  sort(y.begin(), y.end());
  int md = y[n >> 1];
  int nd = y[(n >> 1) - 1];
  for (int i = 0; i < n; i++) {
    if (x[i] >= md) {
      cout << nd << '\n';
    } else {
      cout << md << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 3840
#include <stdio.h>
#include <ctype.h>

int main(){
    int c;
    
    while((c = getchar()) != EOF){
        if(isupper(c)){
            putchar(tolower(c));
        }
        
        else if(islower(c)){
            putchar(toupper(c));
        }
        
        else {
            putchar(c);
        }
    }
    
    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

typedef int value_type; /* ソートするキーの型 */

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
    if (x < y)
        if (y < z) return y; else if (z < x) return x; else return z; else
        if (z < y) return y; else if (x < z) return x; else return z;
}

void quicksort(value_type a[], int left, int right,value_type index[])
/* クイックソート
 * a     : ソートする配列 
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 * index: index配列
 */
{
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i],a[j] を交換 */
            tmp = index[i]; index[i] = index[j]; index[j] = tmp;
            i++; j--;
        }
        quicksort(a, left, i - 1,index);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right,index); /* 分割した右を再帰的にソート */
    }
}


int dfs(int n,int N){
    if (n>N){
        return 0;
    }
    

    int ret;
    
    return ret;
}


int main(){
    char b;
    cin >> b;
    char ans;
    if(b=='A'){
        ans='T';
    }else if(b=='T'){
        ans='A';
    }else if(b=='G'){
        ans='C';
    }else{
        ans='G';
    }
    std::cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

int main(){

    ll N;
    cin >> N;

    vector<ll > vec(N, 0);

    for(ll i = 0; i < N; i++){
        cin >> vec[i];
    }

    ll ans = 0;
    ll g_ans = 0;
    ll k_ans = 0;
    ll sum = 0;

    //奇数番目を正に揃える
    bool flg = true;
    for(ll i = 0; i < N; i++){
        sum += vec[i];
        if(flg == true){
            if(sum <= 0){
                //cout << i << " " << sum << " " << abs(1 - sum) << endl;
                k_ans += abs(sum) + 1;
                sum = 1;
            }
            flg = false;
        }else{
            if(sum >= 0){
                //cout << i << " " << sum << " " << abs(-1 - sum) << endl;
                k_ans += abs(sum) + 1;
                sum = -1;
            }
            flg = true;
        }
    }

    //cout << k_ans << endl;
    //奇数番目を負に揃える
    flg = true;
    sum = 0;
    for(ll i = 0; i < N; i++){
        sum += vec[i];
        //cout << sum << endl;
        if(flg == false){
            if(sum <= 0){
                //cout << i << " " << sum << " " << abs(sum - vec[i]) << endl;
                g_ans += abs(sum) + 1;
                sum = 1;
            }
            flg = true;
        }else{
            if(sum >= 0){
                //cout << i << " " << sum << " " << abs(sum - vec[i]) << endl;
                g_ans += abs(sum) + 1;
                sum = -1;
            }
            flg = false;
        }
    }
    
    ans = min(k_ans, g_ans);

    cout << ans << endl;


}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define dd double
using namespace std;
const ll MOD = 1e9 + 7; 

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n,m,c;
  cin>>n>>m>>c;
  int b[m];
  int i;
  for(i=0;i<m;i++){
  	cin>>b[i];
  }
  
  int j;
  int a[n][m];
  for(i=0;i<n;i++){
  	for(j=0;j<m;j++){
  		cin>>a[i][j];
	  }
  }
  
  int count=0;
  for(i=0;i<n;i++){
  	int s=0;
  	for(j=0;j<m;j++){
  		s=s+(a[i][j]*b[j]);
	  }
	if(s+c>0){
		count++;
	}
  }
  
  cout<<count<<endl;
  
  return 0;
}

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

resx, resy, resz = (-1, -1, -1)
for x in range(N+1):
    for y in range(N-x+1):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break
        else:
            continue

print(resx, resy, resz)

Measured memory_bytes: 3064
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

ll dp[3030][3030][4];

int main() {
    int r, c, k; cin >> r >> c >> k;
    vector<vector<ll>> da(r, vector<ll> (c));
    rip(i,k,0) {
        int rr, cc; cin >> rr >> cc;
        ll v; cin >> v;
        --rr; --cc;
        da[rr][cc] = v;
    }
    rip(i,r,0) rip(j,c,0) rip(l, 4, 0) dp[i][j][l] = 0;
    rip(i,r,0) {
        rip(j, c, 0) {
            if(i == 0 && j == 0) {
                dp[0][0][0] = 0;
                dp[0][0][1] = da[0][0];
            }
            else {
                if(i > 0) {
                    // rip(l, 4, 0) chmax(dp[i][j][l],dp[i-1][j][l]);
                    // rip(l, 3, 0) chmax(dp[i][j][l+1], dp[i-1][j][l] + da[i][j]);
                    rip(l,4,0) {
                        chmax(dp[i][j][0], dp[i-1][j][l]);
                    }
                    dp[i][j][1] = dp[i][j][0] + da[i][j];
                }
                if(j > 0) {
                    rip(l, 4, 0) chmax(dp[i][j][l] ,dp[i][j-1][l]);
                    rip(l, 3, 0) chmax(dp[i][j][l+1], dp[i][j-1][l] + da[i][j]);
                    // rip(l,4,0) {
                    //     chmax(dp[i][j][0], dp[i][j-1][l]);
                    // }
                    // dp[i][j][1] = dp[i][j][0] + da[i][j];
                }
            }
        }
    }
    // rip(i,4,0) {
    //     rip(j,r,0) {
    //         rip(l,c,0) {
    //             cout << dp[j][l][i] << ' ';
    //         }
    //         cout << endl;
    //     }
    //     cout << endl;
    // }
    ll ans = 0;
    rip(i,4,0) chmax(ans, dp[r-1][c-1][i]);
    cout << ans << endl;
}

Measured memory_bytes: 357748
n = gets.chomp.to_i
list = []
n.times do |i|
  s, p = gets.chomp.split
  p = p.to_i
  list[i] = [i+1, s, p]
end

list.sort_by!{ |ix, s, p| [s, -p] }.map!{ |ix, s, p| ix }

puts(list.join("\n"))

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

using namespace std;

int main() {
  string s, ans = "";
  cin >> s;
  int l;
  l = s.length();
  for (int i = 0; i < l; i++) {
    if (s[i] == '0') {
      ans += '0';
    } else if (s[i] == '1') {
      ans += '1';
    } else if (s[i] == 'B') {
      if (ans.length() != 0) {
        ans.erase(ans.end()-1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  vi x(n);
  int maxNum = 0, minNum = 100;
  rep(i, n){
    cin >> x[i];
    maxNum = maxNum < x[i] ? x[i] : maxNum;
    minNum = minNum > x[i] ? x[i] : minNum;
  }
  int shortest = 1000000;
  for(int i = minNum; i <= maxNum; i++){
    int tot = 0;
    rep(j, n) tot += pow(x[j] - i, 2);
    shortest = shortest > tot ? tot : shortest;
  }
  cout << shortest << endl;
}

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

int main(){
    int n,s1=0,s2=0;
    cin>>n;
    int arr[n];
      for(int i=0;i<n;i++){
        cin>>arr[i];
        if(arr[i]%2==0){
            s1++;
            if(arr[i]%3==0 ||arr[i]%5==0){
                s2++;
            }
        }
      }
    if(s1==s2){
        cout<<"APPROVED"<<endl;

           }

  else{
    cout<<"DENIED"<<endl;
         }
    }



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;
 
void solve(){
	string s;
    cin>>s;
    string ss=s;
    int ans=110;
    rep(i,26){
        char c='a'+i;//全部の文字についてシュミレーション
        int cnt=0;
        s=ss;
        while(1){
            bool judge=true;
            rep(j,s.size()-1){
                if(s[j]!=s[j+1])judge=false;
            }
            if(judge){
                ans=min(ans,cnt);
                break;
            }
            ++cnt;
            string t="";
            rep(j,s.size()-1){
            if(s[j]==c||s[j+1]==c)t+=c;
            else t+=s[j];
            }
            swap(s,t);
        }
    }
    cout<<ans<<"\n";
}
 
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}

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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 1, inf = 1000111222;

int main()
{
    //freopen("input.txt", "r", stdin);
    string s;
    cin >> s;
    for (int i =0 ; i < s.size(); ++i) {
        if (s[i] == '?') {
            s[i] = 'D';
        }
    }
    cout << s << endl;


    return 0;
}




Measured memory_bytes: 3716
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String b = sc.next();
		switch(b) {
		case "A":
			System.out.println("T");
			 break;
		case "C":
			System.out.println("G");
			 break;
		case "G":
			System.out.println("C");
			 break;
		case "T":
			System.out.println("A");
			 break;
		}
	}
}

Measured memory_bytes: 26988
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int, int>P;
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
typedef vector<vector<ll>> mat;
typedef vector<int> vec;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll qp(ll a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

void solve() {
    ll n,m;
    cin >> n >> m;
    string ans = "No";

    if(n==m) ans = "Yes";

    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    solve();
    // stop
        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int n;
int A[3][3];
int B[mn]; 
int K[3][3];
// main solution goes here:
void execute(int test_number)
{
    for (int i=0; i<3; i++) for (int j=0; j<3; j++)
    {
        cin>>A[i][j];
    }
    cin>>n;
    for (int i=0; i<n; i++) cin>>B[i];

    for (int i=0; i<3; i++) for (int j=0; j<3; j++)
    {
        for (int ii=0; ii<n; ii++)
        {
            if (B[ii]==A[i][j]) K[i][j]=1;
        }
    }

    for (int i=0; i<3; i++)
    {
        if (K[i][0]==1 && K[i][1]==1 && K[i][2]==1) 
        {
            cout<<"Yes\n";
            return;
        }
        if (K[0][i]==1 && K[1][i]==1 && K[2][i]==1) 
        {
            cout<<"Yes\n";
            return;
        }
    }

    if (K[0][0] ==1 && K[1][1]==1 && 1 == K[2][2])
    {
cout<<"Yes\n";
            return;
    }
    if (K[0][2] ==1 && K[1][1]==1 && 1 == K[2][0])
    {
cout<<"Yes\n";
            return;
    }

    cout<<"No";
    
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

Measured memory_bytes: 256
/*
3 8
3 30
4 50
5 60
*/
#include <bits/stdc++.h>
#define MAXN 110
#define MAXW 1000000

using namespace std;

long long N, W;
long long w[MAXN],
    v[MAXN], memo[MAXN][MAXW];

long long dp(int index, long long wT){
    if(index >= N) return 0;
    if(memo[index][wT] == -1){  //se nn ho ancora calcolato il memo
        long long tmp = 0;
        if(wT + w[index] <= W)  tmp = v[index] + dp(index + 1, wT + w[index]);  //se posso lo prendo
        tmp =  max(dp(index + 1, wT), tmp); //non lo prendo
        memo[index][wT] = tmp;  //aggiorno il memo
    } 
    return memo[index][wT];
}

int main(){
    cin >> N >> W;
    for(long long i = 0; i < N; i++){
        cin >> w[i] >> v[i];
    }
    memset(memo, -1, sizeof memo);
    long long res = dp(0, 0);
    cout << res << endl;
    return 0;
}





Measured memory_bytes: 859648
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n, q;
    string s;
    cin >> n >> q >> s;

    vector<int> cnt(n, 0);
    for(int i=1; i<n; ++i){
        cnt[i] = cnt[i-1];
        if(s.substr(i-1, 2) == "AC")
            ++ cnt[i];
    }

    while(--q >= 0){
        int l, r;
        cin >> l >> r;
        int ans = cnt[r-1] - cnt[l-1];
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cctype>
#include<cstring>
#define maxn 10000000 
#define ll long long 
#define SDOI2020 RP++ 
using namespace std;
const ll mod = 1e9 + 7;
ll b,c,n,pos1,pos2,pos3,pos4; 
ll pos;
ll a[120]={1,682498929,491101308,76479948,723816384,67347853,27368307,625544428,199888908,888050723,927880474,281863274,661224977,623534362,970055531,261384175,195888993,66404266,547665832,109838563,933245637,724691727,368925948,268838846,136026497,112390913,135498044,217544623,419363534,500780548,668123525,128487469,30977140,522049725,309058615,386027524,189239124,148528617,940567523,917084264,429277690,996164327,358655417,568392357,780072518,462639908,275105629,909210595,99199382,703397904,733333339,97830135,608823837,256141983,141827977,696628828,637939935,811575797,848924691,131772368,724464507,272814771,326159309,456152084,903466878,92255682,769795511,373745190,606241871,825871994,957939114,435887178,852304035,663307737,375297772,217598709,624148346,671734977,624500515,748510389,203191898,423951674,629786193,672850561,814362881,823845496,116667533,256473217,627655552,245795606,586445753,172114298,193781724,778983779,83868974,315103615,965785236,492741665,377329025,847549272,698611116};
ll calc(ll n)
{
        ll k=n/maxn;
        ll sum=a[k];
        for(ll i=k*maxn+1;i<=n;i++)
        {
            sum=sum*i%mod;
        }
        return(sum + mod)% mod;
}
inline ll read()
{
	ll x=0;
	ll flag=0;
	char ch;
	ch=getchar();
	while(!isdigit(ch)) 
	{
		if(ch=='-') flag=1;
	ch=getchar();	
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-48;
		ch=getchar();
		}
		if(flag==1) x=-x;	
		return x;
}
inline ll quick_pow(ll x,ll k)
{
	ll ans = 1;
	while(k)
	{
		if(k & 1)
		{
			ans *= x;
			ans %= mod;
		}
		x *= x;
		x %= mod;
		k >>= 1;
	}
	return ans % mod;
}

inline ll cc(ll x)
{
	return quick_pow(x,mod - 2);
}

inline ll C(ll x,ll y)
{
	return  pos * cc(calc(y) % mod * calc(x - y) % mod) % mod;
}

int main()
{
	n = read();
	c = read();
	b = read();
	pos = calc(n);
	ll ans = quick_pow(2,n) - 1 - C(n,c) - C(n,b);
	while(ans < 0) ans += mod;
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

char a[105][105], o[205][105];
 
int32_t main()
{
    fast;
    int h, w; cin >> h >> w;
    Rep(i, 1, h)  {
        Rep(j, 1, w) {
            cin >> a[i][j];
            //o[i][j] = a[i][j];
        }
    }

    Rep(i, 1, 2*h) {
        Rep(j, 1, w) {
            o[i][j] = a[(i+1) / 2][j];
        }
    }

    Rep(i, 1, 2*h) {
        Rep(j, 1, w) {
            cout << o[i][j];
        }
        cout << "\n";
    }



    
    
    
    return 0;
}

Measured memory_bytes: 3676
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
int main() {
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB"){
        dunk("No");
    }
    else dunk("Yes");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long

int main()
{
        IO;
        ll i, j, n, m, k, l, r,t, q,sum,mod, lcm,mn1,mn2;
        cin>>n>>m;
        if(n<=m) cout<<"unsafe"<<endl;
        else cout<<"safe"<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

ll fastPow(ll a, ll b, ll mod=0){
    if(a == 0 and b == 0){
        return -1;
    }
    if(a == 0){
        return 0;
    }
    if(b == 0){
        return 1;
    }
    ll tmp = fastPow(a,b/2,mod);
    if(mod != 0) {
        if (b % 2 == 0) {
            return (tmp * tmp) % mod;
        } else {
            return ((tmp*tmp) % mod * (a % mod)) % mod;
        }
    }else{
        if (b % 2 == 0) {
            return (tmp*tmp);
        } else {
            return tmp * tmp * a;
        }
    }
}

int main() {
    
    const ll X = 100001;
    string s;
    cin >> s;
    ll numList[X] = {};
    for(ll i=s.length();i>0;i--){
        if(s[i-1] == '?'){
            numList[s.length() - i + 1] = -1;
        }else{
            numList[s.length() - i + 1] = s[i-1] - '0';
        }
    }
    ll dp[2][13] = {};
    dp[0][0] = 1;

    for (ll i=0;i<s.length();i++){
        ll fast = fastPow(10,i,13);
        for(ll j=0;j<13;j++){
            if(numList[i+1] == -1) {
                for (ll k = 0; k <= 9; k++) {
                    ll tmp = j - (fast * k) % 13;
                    if (tmp < 0) {
                        tmp += 13;
                    }
                    dp[1][j] += dp[0][tmp];
                }
            }else{
                for (ll k = numList[i+1]; k <= numList[i+1]; k++) {
                    ll tmp = j - (fast * k) % 13;
                    if (tmp < 0) {
                        tmp += 13;
                    }
                    dp[1][j] += dp[0][tmp];
                }
            }
        }
        for(ll j=0;j<13;j++){
            dp[0][j] = dp[1][j] % mop;
            dp[1][j] = 0;
        }
    }

    cout << dp[0][5] << endl;
}

Measured memory_bytes: 1532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P  = pair <int, int>;

#define rep(i, n)     for (int i = 0; i < (int) (n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp)   for (auto &i : mp)

const int INF = 1001001001;

int main()
{
  std::vector <int> x(5);
  rep(i, 5) cin >> x[i];
  ll ans = 0;
  rep(i, 5) {
    if (x[i] == 0) {
      ans = i;
      break;
    }
  }
  cout << ans + 1 << endl;

  return 0;
}


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

const int maxn = 1e5 + 10;
typedef long long ll;
int n, m, i, j, k;
ll ans, hd[maxn], nxt[maxn << 1], ver[maxn << 1], wei[maxn << 1], cnte;
ll col[maxn], a[maxn]; bool succ;
inline void adde(int u, int v, int w) {
	ver[++cnte] = v, wei[cnte] = w, nxt[cnte] = hd[u], hd[u] = cnte;
}
void dfs(int u) {
	a[col[u]]++;
	for (int i = hd[u]; i; i = nxt[i]) {
		int v = ver[i], w = wei[i];
		if (w == 1) a[3]++;
		if (col[v] == -1) {
			col[v] = (col[u] + w) % 3;
			dfs(v); 
		} else if (col[v] != (col[u] + w) % 3) {
			succ = 1;
		}
	}
}

int main() {
//	freopen("chain.in", "r", stdin);
//	freopen("chain.out", "w", stdout);  
	scanf("%d %d", &n, &m);
	for (int i = 1, u, v; i <= m; i++) {
		scanf("%d %d", &u, &v);
		adde(u, v, 1), adde(v, u, 2); 
	}
	memset(col, -1, sizeof(col));
	for (int i = 1; i <= n; i++) {
		if (col[i] == -1) {
			a[col[i] = 0] = a[1] = a[2] = a[3] = succ = 0;
			dfs(i);
			if (succ) {
				ll tmp = a[0] + a[1] + a[2];
			  ans += 1ll * tmp * tmp;
			  continue;
		  }   
		  if ((!a[0]) || (!a[1]) || (!a[2])) {
			  ans += a[3];
			  continue;
		  }
		  ans += 1ll * a[0] * a[1];
		  ans += 1ll * a[1] * a[2];
		  ans += 1ll * a[0] * a[2];
		}
	}
	printf("%lld\n", ans);
	return 0;  
}

Measured memory_bytes: 9600
N = int(input())
if N < 10:
    ans = N
elif N < 100:
    ans = 9
elif N < 1000:
    tmp = N - 100 + 1
    ans = tmp + 9
elif N < 10**4:
    ans = 909
elif N < 10**5:
    tmp = N - 10**4 + 1
    ans = tmp + 909
else:
    ans = 90909
print(ans)

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

int main(){
    int n,T;cin>>n>>T;
    int ans=1001;
    for(int i=0;i<n;i++){
        int c,t;cin>>c>>t;
        if(t<=T) ans=min(ans,c);
    }
    if(ans==1001) cout<<"TLE"<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
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 < n ; i++ ){
            h[i] = sc.nextInt();
        }
        Arrays.sort(h);
        sc.close();
        boolean aa = true;
        int s = -1;
        while(aa == true){
            s++;
            if(s + 1 == n){
                aa = false;
            }
            if(h[s] >= k){
                aa = false;
            }
        }
        if(s + 1 == n){
            s++;
        }
        System.out.println(n - s);
    }
}

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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < (int)k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

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

const int MOD = 1e9 + 7;
const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

set<P> t;

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

    int n, m;
    cin >> n;
    rep(i, n) {
        int h, g;
        cin >> h >> g;
        t.insert(P(h, g));
    }
    cin >> m;
    rep(i, m) {
        int h, g;
        cin >> h >> g;
        t.insert(P(h, g));
    }
    int cnt = 0;
    for(auto i = t.begin(); i != t.end(); ++i) {
        if(cnt != t.size() - 1) printf("%d:%02d ", i->first, i->second);
        else printf("%d:%02d\n", i->first, i->second);
        ++cnt;
    }
    return 0;
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
int solve()
{
	ll x;
    cin>>x;
    ll rem = x%500;
    ll ans = (x/500);
    ans = ans *1000;
    rem = rem/ 5;
    ans = ans+rem*5;
    cout<<ans<<endl;

}
int main()
{
    /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else
    #endif */
    solve();
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC<<" Sec\n";
    #endif */
    return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long a,b;
  cin>>a>>b;
  if((a==1&&b==2)||(a==2&&b==1))
  {
    cout<<3<<endl;
  }
  else if((a==2&&b==3)||(a==3&&b==2))
  {
    cout<<1<<endl;
  }
  else
    cout<<2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cfloat>
using namespace std;

int main() {
  int n, c, m, s, b[4];
  double t, a[4];
  while (1) {
    scanf("%d", &n);
    if (!n) break;
    a[0] = a[1] = DBL_MAX;
    a[2] = a[3] = -DBL_MAX;
    b[0] = b[1] = b[2] = b[3] = -1;
    for (int i=0; i<n; i++) {
      scanf("%d", &c);
      t = 0.;
      for (int j=0; j<4; j++) {
        scanf("%d %d", &m, &s);
        t += 60 * m + s;
      }
      if (t < a[0]) {
        a[1] = a[0];
        a[0] = t;
        b[1] = b[0];
        b[0] = c;
      } else if (t < a[1]) {
        a[1] = t;
        b[1] = c;
      }
      if (t > a[3]) {
        a[2] = a[3];
        a[3] = t;
        b[2] = b[3];
        b[3] = c;
      } else if (t > a[2]) {
        a[2] = t;
        b[2] = c;
      }
    }
    for (int i=0; i<3; i++) {
      printf("%d\n", b[i]);
    }
  }
  return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;
const int N = 2e5 + 5;

int a[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	unordered_map<int,int>M;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		M[-a[i]-i]++;
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		if(M.count(a[i]-i)) ans+=M[a[i]-i];
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 12076
n = int(input())

# 3 5 7 11 13
# 105 135 165 189 195
if n >= 195:
  print(5)
elif n >= 189:
  print(4)
elif n >= 165:
  print(3)
elif n >= 135:
  print(2)
elif n >= 105:
  print(1)
else:
  print(0)


Measured memory_bytes: 9112