akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{   ll n;
    cin>>n;
    ll a[n][3];
    ll dp[3];
    dp[0]=dp[1]=dp[2]=0;
    for(ll i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    dp[0]=a[0][0];
    dp[1]=a[0][1];
    dp[2]=a[0][2];
    for(ll i=1;i<n;i++){
            ll d[3]={0};
        for(ll j=0;j<3;j++){
            for(ll k=0;k<3;k++){
                if(j!=k)d[k]=max(d[k],dp[j]+a[i][k]);
            }
        }
        dp[0]=d[0];
        dp[1]=d[1];
        dp[2]=d[2];

    }
    cout<<max({dp[0],dp[1],dp[2]});
    return 0;
}


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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const double INF = std::numeric_limits<double>::infinity() ;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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){
  ios::sync_with_stdio(false);

  int H, W, N;
  cin >> H >> W >> N;


  int val = max(H, W);
  int ans;
  if (N % val == 0){ans = N/val;}
  else ans = int(N/val) + 1;


  cout << ans << endl;



  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100005
#define LL long long
LL n,X;
LL x[MAXN];
LL ans;
LL gcd(LL a,LL b)
{
	if(b==0) return a;
	return gcd(b,a%b);
}
LL Abs(LL p)
{
	if(p>=0) return p;
	return -p;
}
int main()
{
	scanf("%lld %lld",&n,&X);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&x[i]);
		x[i]=Abs(x[i]-X);
		if(i==1) ans=gcd(x[1],x[2]);
		else ans=gcd(ans,x[i]);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define int long long
#define maxn 210000
#define inf 1000000000
#define mod 1000000007
#define flash cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); //freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);

using namespace std;

int n, k, c, l[maxn + 1], r[maxn + 1], a[maxn + 1], b[maxn + 1];
string s;

signed main()
{
	flash
	
	cin>>n>>k>>c>>s;
	for(int i = 0; i < n; i++){
		if(s[i] == 'o'){
			l[i] = (i >= c + 1)? 1 + l[i - (c + 1)]: 1;
		}
		if(i)
		l[i] =max(l[i], l[i - 1]);

		if(l[i] > k) return cout<<'\n', 0;
	}
	
	reverse(s.begin(), s.end());

	for(int i = 0; i < n; i++){
		if(s[i] == 'o'){
			r[i] = (i >= c + 1)? 1 + r[i - (c + 1)]: 1;
		}
		if(i)
		r[i] = max(r[i], r[i - 1]);
	}
	
	for(int i = 0; i < n; i++)
		r[i] = k - r[i] + 1;
	reverse(r, r + n);

	
	for(int i = 0; i <= n; i++)
		a[i] = inf, b[i] = 0;
	
	for(int i = 0; i < n; i++){
		a[l[i]] = min(a[l[i]], i + 1);
		b[r[i]] = max(b[r[i]], i + 1);
	}

	for(int i = 1; i <= k; i++){
		if(a[i] == b[i]) cout<<a[i]<<"\n";
	}	
}



Measured memory_bytes: 8212
#include<iostream>


using namespace std;

int main(){
	int N, K;
	cin >> N >> K;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;
		if (x >= K)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		LinkedList<Coordinate> list = new LinkedList<>();
		int x = 0;
		int y = 0;
		for (int i = 0; i < n; i++) {
			x = scanner.nextInt();
			y = scanner.nextInt();
			list.add(new Coordinate(x, y, "red"));
		}
		
		for (int i = 0; i < n; i++) {
			x = scanner.nextInt();
			y = scanner.nextInt();
			list.add(new Coordinate(x, y, "blue"));
		}
		scanner.close();
		Collections.sort(list, new CoordinateConparator());
		
		
		Set<Coordinate> set = new HashSet<>();
		for (int i = 0; i < list.size(); i++) {
			Coordinate c = list.get(i);

			if (c.color.equals("red")) {
				set.add(c);
				
			}else {
				int maxy = 0;
				Coordinate removeCoordinate = null;
				for (Coordinate cy : set) {
					if (c.y > cy.y && cy.color.equals("red")) {
						if (maxy <= cy.y) {
							maxy = cy.y;
							removeCoordinate = cy;
							
						}
					}
				}
			
				set.remove(removeCoordinate);	
			}
		}
		System.out.println(n - set.size());
	}
	
}

class Coordinate {
	int x;
	int y;
	String color;
	public Coordinate(int x, int y, String color) {
		this.x = x;
		this.y = y;
		this.color = color;
	}
}

class CoordinateConparator implements Comparator<Coordinate> {
	
	@Override
	public int compare(Coordinate c1, Coordinate c2) {
		return c1.x < c2.x ? -1 : 1;
	}
}


Measured memory_bytes: 24020
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定
#include <list> //前後に数値を入れれる配列



#define REP(i,m,n) for(int i = (int) (m);i < (int) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
ll chg_DegRad(int deg) {
	return deg * PI / 180.0;
}

//radian → degree
ll chg_RadDeg(int rad) {
	return rad * 180.0 / PI;
}

//提出コード↓

ll n, a[10010], ans;


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

	rep(i, n) {
		while (a[i] % 2 == 0) {
			a[i] = a[i] / 2;
			ans++;
		}
	}
	cout << ans << endl;




	return 0;
}



Measured memory_bytes: 384
from collections import defaultdict
H,W,D = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(H)]

d = defaultdict(lambda:[])

for i in range(H):
    for j in range(W):
        d[A[i][j]] = [i,j]

cost = defaultdict(lambda:[0])
for r in range(1,D+1):
    for m in range(0,H*W//D):
        if D*(m+1)+r <= H*W:
            cost[r].append(abs(d[D*m+r][0]-d[D*(m+1)+r][0])+abs(d[D*m+r][1]-d[D*(m+1)+r][1]))
for r in range(1,D+1):
    for m in range(len(cost[r])-1):
        cost[r][m+1] += cost[r][m]

Q = int(input())

def magic(L,R):
    r = L%D
    if r == 0:
        r = D
    ml = (L-r)//D
    mr = (R-r)//D
    return cost[r][mr]-cost[r][ml]


for _ in range(Q):
    L,R = map(int,input().split())
    print(magic(L,R))

Measured memory_bytes: 43148
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	int N;
	cin >> N;
	vi d(N);
	int sum=0;
	for(int i=0; i<N; i++){
		cin >> d[i];
		sum+=d[i];
	}

	int ans=0;
	for(int i=0; i<N; i++){
		ans+=d[i]*(sum-d[i]);
	}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		String []s = new String [n];
		for(int i = 0 ; i < n ;i++) {
			s[i] = sc.next();
		}
		
		int ac = 0;
		int wa = 0;
		int tle = 0;
		int re = 0;
		
		for(int i = 0 ;i < n  ;i++) {
			if(s[i].equals("AC")) {
				ac++;
			}
			else if(s[i].equals("TLE")) {
				tle++;
			}
			else if(s[i].equals("WA")) {
				wa++;
			}
			else {
				re++;
			}
		}
		
		System.out.println("AC x "+ac);
		System.out.println("WA x "+wa);
		System.out.println("TLE x "+tle);
		System.out.println("RE x "+re);
		
		
	}
}


Measured memory_bytes: 64056
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define epsilon 1e-9
#define INF 5e18
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

int main(){
    //freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    int N, sum = 0, cnt = 0; cin >> N; string arr [N]; int len [N];
    for(int i = 0; i < N; i++) cin >> arr[i] >> len[i];
    string bad; cin >> bad;
    for(int i = 0; i < N; i++){
        //cout << arr[i] << len[i] << endl;
        if(cnt) sum += len[i];
        cnt |= arr[i].compare(bad) == 0;
    }
    cout << sum << '\n';
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/


Measured memory_bytes: 892
#include <stdio.h>
#include <string.h>

#define M 1000003/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long int getKey(char str[]){
  long long int sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M;/* your task */ }
int h2(int key){ return 1+key%(M-1);/* your task */ }

int find(char str[]){
  long long int key,h,i;
    /* your task */
  key = getKey(str);
  for(i=0;;i++){
    h = (h1(key) + i*h2(key))%M;  
  if(strcmp(str,H[h])==0) return 1;
  if(H[h][0]=='\0') return 0;
  }
}

void insert(char str[]){
  long long int key,h,i;
    /* your task */
  key = getKey(str);
 
  for(i=0;;i++){
  h = (h1(key) + i*h2(key))%M;
  if(H[h][0]=='\0'){
    strcpy(H[h],str);
    break;
  } 
  }
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 15416
#include <iostream>

using namespace std;

int main()
{
  int a,b,c;
  int X,Y;
  a = b = c = 0;

  cin >> Y >> X;

  c = X/1000;

  if ( c == Y ) a = b = 0;
  else if ( c < Y ) a = b = c = -1;
  else {
    int tmp2 = c-Y;
    bool t = false;

    for ( int i = 5; i <= c; i += 5 ) {
      if ( 9*(i/10)+4*(i%10) < tmp2 || tmp2 < (i/5)*4 ) continue;
      if ( ( tmp2-(i/5)*4 ) <= i/10 ) {
        a = tmp2-(i/5)*4;
        b = (i-a*10)/5;
        c = c-a*10-b*5;
        t = true;
        break;
      }

    }
    if ( !t ) a = b = c = -1;
  }

  cout << a << " " << b << " " << c << "\n";

  //cout << a*10000+b*5000+c*1000 << "\n";
}


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

enum Direction{S, E, N, M};

class Die{
// front right back left bottom top
private:
  int right_index[6][6] = {
    {-1, 5, -1, 4, 1, 3},
    {4, -1, 5, -1, 2, 0},
    {-1, 4, -1, 5, 3, 1},
    {5, -1, 4, -1, 0, 2},
    {3, 0, 1, 2, -1, -1},
    {1, 2, 3, 0, -1, -1}
  };

public: 
  vector<int> data;
  Die(): data(6,0){}
  Die(vector<int> input){
    data.resize(6);
    for(int i=0; i<6; i++)
      data[(i+5)%6] = input[i];
    swap(data[2],data[3]);
  } 

  void roll(int dir){
    int tmp = data[5];
    data[5] = data[(dir+2)%4];
    data[(dir+2)%4] = data[4];
    data[4] = data[dir];
    data[dir] = tmp;
  }

};

bool check_all(Die d1, Die d2){
  for(int i=0; i<6; i++){
    if(d1.data[i] != d2.data[i])
      return false;
  }
  return true;
}

bool is_same_die(Die d1, Die d2){
  Direction d;
  for(int i=0; i<7; i++){
    if(d1.data[0] == d2.data[0]){
      for(int j=0; j<4; j++){
        if(d1.data[5] == d2.data[5]){
          if(check_all(d1, d2))
            return true;
        }
        d2.roll(d = E);
      }
    }
    d2.roll(d = S);
    if(i==3){
      d2.roll(d = E);
      d2.roll(d = S);
    }
  }
  return false;
}

int main(){
  int n; cin >> n;
  vector<Die> dice;
  for(int i=0; i<n; i++){
    vector<int> input(6);
    for(int j=0; j<6; j++){
      cin >> input[j];
    }
    dice.emplace_back(input);
  }
  
  bool independent = true;
  for(int i=0; i<n-1; i++){
    for(int j=i+1; j<n; j++){
      if(is_same_die(dice[i], dice[j])){
        independent = false;
      }
    }
  }

  cout << ((independent)? "Yes": "No") << endl;

  return 0;
}

Measured memory_bytes: 3188
/* ~ CoderMehraJ ~ */
#include <bits/stdc++.h>
using namespace std;

#define show(x) cout << #x << " = " << x << '\n';

int hehe(string a){
    string b="";
    int n=a.size();
    for(int i=n-1;i>=0;i--) b+=a[i];
    return a==b;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s,a="",b="";
    cin>>s;
    int n=s.size();
    for(int i=0;i<(n-1)/2;i++) a+=s[i];
    for(int i=((n+3)/2)-1;i<n;i++) b+=s[i];
    //show(a); show(b);
    if(hehe(s) && hehe(a) && hehe(b)) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}
//fixed<<setprecision(1)


Measured memory_bytes: 256
#include <stdio.h>

int A[1000000], n;

int binarySearch(int key)
{
    int left = 0;
    int right = n;
    int mid;
    while (left < right) {
        mid = left + (right - left) / 2;
        if (key == A[mid]) return 1;
        if (key > A[mid]) left = mid + 1;
        else if (key < A[mid]) right = mid;
    }
    return 0;
}


int main(int argc, char const *argv[])
{
    int q, k, sum = 0;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d", &k);
        if (binarySearch(k)) {
            sum++;
        }
    }

    printf("%d\n", sum);

    return 0;
}




Measured memory_bytes: 2100
#include <stdio.h>

int  sum_and_judge(int a[], int b[]);

int main(void)
{
	int a[4], b[4];
	int i;
	
	for (i = 0; i < 4; i++){
		scanf("%d",&a[i]);
	}
	for (i = 0; i < 4; i++){
		scanf("%d",&b[i]);
	}
	printf("%d\n", sum_and_judge(a, b));
	
	return (0);
}
int sum_and_judge(int a[], int b[])
{
	int i;
	int sum_a, sum_b;
	
	sum_a = sum_b = 0;
	
	for (i = 0; i < 4; i++){
		sum_a += a[i];
		sum_b += b[i];
	}
	if (sum_a > sum_b || sum_a == sum_b){
		return (sum_a);
	}
	else {
		return (sum_b);
	}
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

const int mod = 1e9 + 7;
const int inf = 1e9;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

struct edge {ll from,to,cost;};

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    bool same = false;
    for(int i = 0; i < n-1;i++){
        if(a[i] == a[i+1]){
            same = true;
        }
    }
    if(same){
        cout << "NO";
    }else{
        cout << "YES";
    }
}

Measured memory_bytes: 1024
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))


def dfs(x, d, res):
    if len(x) == N + 1:
        d[0] += 1
        if x[1:] == P:
            res["P"] = d[0]
        if x[1:] == Q:
            res["Q"] = d[0]
        return

    for v in range(1, N + 1):
        if v not in x:
            x.append(v)
            dfs(x, d, res)
            x.pop()

res = {"P": 0, "Q": 0}
dfs([0], [0], res)
print(abs(res["P"] - res["Q"]))


Measured memory_bytes: 69336
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N, Q; cin >> N >> Q;) {
		string s; cin >> s;
		vector<char> t(Q), d(Q); rep(i, 0, Q) {
			cin >> t[i] >> d[i];
		}

		int l = 0, r = 0;
		rrep(i, 0, Q) {
			char c = t[i] - 'A';
			if (d[i] == 'L') {
				if (s[l] == t[i]) {
					l++;
				}
			}
			else {
				if (l > 0 && s[l - 1] == t[i])
					l--;
			}
		}
		dump(l);
		rrep(i, 0, Q) {
			char c = t[i] - 'A';
			if (d[i] == 'R') {
				if (s[N - 1 - r] == t[i]) {
					r++;
				}
			}
			else {
				if (r > 0 && s[N - 1 - (r - 1)] == t[i])
					r--;
			}
		}
		dump(r);
		cout << N - l - r << endl;
	}
	return 0;
}

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

void maxHeapify(vector<int>& A, int i)
{
	int H = A.size() - 1;
	int l = 2 * i;
	int r = 2 * i + 1;
	//????????????????????????????????§???????????§????????????????????¶
	int largest;
	if(l <= H && A[l] > A[i]){
		largest = l;
	}else{
		largest = i;
	}
	if(r <= H && A[r] > A[largest]){//i???????????????????????§????????´???

		largest = r;
	}
	if(largest != i){
		swap(A[i], A[largest]);
		maxHeapify(A, largest); // ?????°??????????????????
	}
}

void buildMaxHeap(vector<int>& A)
{
	int H = A.size() - 1;
	for(int i = H / 2; i >= 1; i--){
		maxHeapify(A, i);
	}
}

void Output(const vector<int>& Heap)
{
	for(int i = 1; i < Heap.size(); i++){
		cout << " " << Heap[i];
	}
	cout << endl;
}

int main()
{
	int H;
	cin >> H;
	vector<int> Heap(H+1);
	for(int i = 0; i < H; i++){
		cin >> Heap[i+1];
	}
	buildMaxHeap(Heap);
	Output(Heap);
	return 0;
}

Measured memory_bytes: 4600
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());

        System.out.println(lcm(a,b));
    }
    private static long gcd(long a, long b){return b>0?gcd(b,a%b):a;}
    private static long lcm(long a, long b){return a*b/gcd(a,b);}
}


Measured memory_bytes: 23764
a,b,c = map(int,input().split())
l = []

for i in range(a,a+c):
  if i <= b:
    l.append(i)
for j in range(b,b-c,-1):
  if j >= a:
    l.append(j)
l = list(set(l))
l.sort()

for i in range(len(l)):
  print(l[i])

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
    int n, p, i, data[51]={}, nokori=0;
    for(;scanf("%d%d", &n, &p);){
        if( n == 0 && p == 0 ) break;
        for( i = 0, nokori = p;; i++ ){
            if( nokori != 0 ){
                data[i] = data[i] + 1;
                nokori = nokori - 1;
            }else{
                nokori = data[i];
                data[i] = 0;
            }
            if( data[i] == p ){
                printf("%d\n", i);
                break;
            }
            if( i == n - 1 ) i = -1;
        }
        for( i = 0; i < 51; i++ ) data[i] = 0;
    }
    return 0;
}

Measured memory_bytes: 600
class NumArray(object):

    def __init__(self, nums):
        self.l = len(nums)
        self.tree = [0]*self.l + nums
        for i in range(self.l - 1, 0, -1):
            self.tree[i] = max(self.tree[i<<1],self.tree[i<<1|1])
    
    def update(self, i, val):
        n = self.l + i
        self.tree[n] = val
        while n > 1:
            self.tree[n>>1] = max(self.tree[n],self.tree[n^1])
            n >>= 1
        
    
    def maxRange(self, i, j):
        m = self.l + i
        n = self.l + j
        res = 0
        while m <= n:
            if m & 1:
                #res += self.tree[m]
                res = max(res,self.tree[m])
                m += 1
            m >>= 1
            if n & 1 ==0:
                #res += self.tree[n]
                res=max(res,self.tree[n])
                n -= 1
            n >>= 1
        return res
    
N=int(input())
H=list(map(int,input().strip().split(" ")))
V=list(map(int,input().strip().split(" ")))
Ans=NumArray([0]*(N+1))
for i in range(len(H)):
    h=H[i]
    ans1=Ans.maxRange(0,h-1)+V[i]
    Ans.update(h,ans1)
print(max(Ans.tree))


Measured memory_bytes: 120796
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N, X;
    int pos = 0;
    int bound_cnt = 1;
    cin >> N >> X;
    for (int i = 0; i < N; i++){
        int L;
        cin >> L;
        pos += L;
        if (pos <= X) bound_cnt++;
    }
    cout << bound_cnt << endl;
    return 0;
}

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

//#include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using cint = cpp_int;
//#pragma GCC optimize("", on)
//#pragma GCC optimization_level 3

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)
#define input(a) scanf("%lld", &(a))
#define print(a) printf("%lld\n", (a))

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

#define dump(a, h, w)                                                          \
    {                                                                          \
        cerr << __LINE__ << ": " << #a << " = [" << endl;                      \
        rep(i, h) {                                                            \
            rep(j, w) cerr << a[i][j] << space;                                \
            cerr << endl;                                                      \
        }                                                                      \
        cerr << "]" << endl;                                                   \
    }

#define lldump(a, n) dump(vector<vector<ll>>{a}, 1, n)

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)
#define loop() for (;;)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }
func sign(ll a) { return a ? abs(a) / a : 0; }

def in() {
    ll A;
    cin >> A;
    return A;
}

signed main() {
    ll N, K, res = 0;
    cin >> N >> K;
    ll L[N];
    rep(i, N) cin >> L[i];
    sort(L, L + N);
    dec(i, N - 1, N - K) res += L[i];
    cout << res << endl;
}

// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast_input ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long int ll;
int main()
{
    fast_input;
    int a,b;
    cin>>a;
    cin>>b;
    if(a+b==4)     
      cout<<2<<endl;
    else if(a+b==3) 
      cout<<3<<endl;
    else if(a+b==5)
      cout<<1<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int i, j, max, n, tmp, sum, l[11];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&l[i]);
  }
  for(i=0;i<n;i++){
    max = i;
    for(j=i+1;j<n;j++){
      if(l[max]<l[j]){
      tmp = l[max];
      l[max] = l[j];
      l[j] = tmp;
      }
    }
  }
  sum = l[0];
  for(i=1;i<n;i++){
    sum = sum - l[i];
  }
  if(sum<0){
    printf("Yes\n");
  }else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int m;
    cin >> m;
    vector<int> b(m);
    rep(i, m) cin >> b[i];
    cout << includes(all(a), all(b)) << endl;
}


Measured memory_bytes: 4376
import java.util.*;
public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    int d = sc.nextInt();
    int[][] t = new int[d][2];
    for(int i=0;i<d;i++){
    	t[i][0] = sc.nextInt();
      	t[i][1] = sc.nextInt();
    }
    boolean flag = false;
    for(int i=0;i<d-2;i++){
    	if(t[i][0] == t[i][1] && t[i+1][0] == t[i+1][1] && t[i+2][0] == t[i+2][1]) flag = true;
    }
    if(flag) System.out.println("Yes");
    else System.out.println("No");
  }
}

Measured memory_bytes: 35908
def gets_can_div_2(a)
  count = 0
  while (a%2==0)
    count+=1
    a /= 2
  end
  count
end

N = gets.to_i
as = gets.split.map(&:to_i)
res =  as.map{|a| gets_can_div_2(a)}
sum = 0
res.each{|e|
  sum += e
}
puts sum


Measured memory_bytes: 2428
#!/usr/bin/env python3
n, m, q = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(q)]

ans = 0

def calc(A):
  score = 0
  for a, b, c, d in x:
    if A[b-1] - A[a-1] == c:
      score += d
  return score

def dfs(A):
  global ans

  if len(A) == n:
    score = calc(A)
    ans = max(ans, score)

  elif len(A) == 0:
    for i in range(1, m+1):
      dfs([i])

  else:
    for i in range(A[-1], m+1):
      dfs(A + [i])

dfs([])
print(ans)


Measured memory_bytes: 9188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int mn=0,mx=N;
  printf("0\n");
  fflush(stdout);
  string s;
  cin>>s;
  if(s=="Vacant")
    return 0;
  while(mx-mn>1){
    int n=(mn+mx)/2;
    printf("%d\n",n);
    fflush(stdout);
    string S;
    cin>>S;
    if(S=="Vacant")
      return 0;
    if((S==s && (n-mn)%2==0) || (S!=s && (n-mn)%2==1))
      mn=n,s=S;
    else
      mx=n;
  }
  printf("%d\n",mx);
  fflush(stdout);
  string S;
  cin>>S;
  if(S!="Vacant"){
    printf("%d\n",mn);
    fflush(stdout);
  }
  return 0;
}

Measured memory_bytes: 3844
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int K; cin >> K;
    string S; cin >> S;
    if (S.length() <= K)
    {
        cout << S << endl;
    }
    else
    {
        S = S.substr(0, K);
        cout << S << "..." << endl;
    }
}

Measured memory_bytes: 3628
while True:
    x = int(input())
    if x == 0:
        break
    a=x-1
    b=x
    while a>0:
         b *= a
         a -= 1
    c=str(b)
    d=len(c)
    
    n=1
    y=0
    while n < d:
        if c[d-n] == '0':
            y += 1
        else:
            break
        n += 1
    
    print(y)


Measured memory_bytes: 5700
#include<stdio.h>

int n, A[50];

int solve(int i, int m){
    if (m==0) return 1;
    if(i >= n) return 0;
    return solve(i + 1, m) || solve(i + 1, m - A[i]);
}

int main(){
    int q, m;
    int i;
    scanf("%d", &n);
    for(i=0;i<n;i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for(i=0;i<q;i++){
        scanf("%d", &m);
        if(solve(0,m)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
    
}

Measured memory_bytes: 580
var n,i,ans:longint;
var r:boolean;
var a:array[0..100020] of longint;
begin
  r:=false;
  read(n);for i:=1 to n do
  begin
    read(a[i]);
    if r then 
r:=false
    else 
if a[i]=i then begin inc(ans);r:=true;end;
  end;
  writeln(ans);{233333333333333333}
end.


Measured memory_bytes: 512
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-02-18 10:36:40
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define Int __int128
#define i64 long long
#include<map>
const int mod=998244353,N=110;
std::map<Int,i64> f[N];
char s[N];
int n;
Int a;
i64 solve(Int a,int n)
{
	if(f[n].count(a)) return f[n][a];
	i64 g[N]; memset(g,0,sizeof(g));
	g[0]=1;
	fr(i,1,n)
	{
		g[i]=g[i-1]*(((a>>(i-1))&1)+1);
		fr(j,1,i/2)
		{
			int k=i-j; Int B=((Int)1<<j)-1,A=(a>>k)&B;
			while(k>=j)
			{
				k-=j; A&=(a>>k)&B;
				g[i]=(g[i]+g[k]*solve(A,j))%mod;
			}
		}
	}
//	printf("%d ",n);
//	fr(i,0,n-1) putchar(((a>>i)&1)+48); putchar(10); putchar(' ');
//	fr(i,0,n) printf("%d%c",int(g[i]),i==n?'\n':' ');
	return f[n][a]=g[n];
}
int main()
{
	scanf("%s",s); n=strlen(s);
	fr(i,0,n-1) a|=(Int)(s[i]-48)<<i;
	printf("%d\n",int(solve(a,n)));
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<bitset>
using namespace std;

const int N=100005;

int n,sum;
int a[N];
bitset<8000002> f,g;

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=n;i++) sum+=a[i];
	for (i=0;i<=sum;i++) g[i]=1,f[i]=0;
	f[0]=1;
	for (i=1;i<=n;i++) f|=(f<<a[i])&g;
	for (i=(sum+1)/2;i<=sum;i++)
		if (f[i]){
			printf("%d\n",i);
			return 0;
		}
	return 0;
} 

Measured memory_bytes: 3712
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

void solve()
{
    int n;
    cin >> n;
    
    int res = inf;
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        int temp = 0;
        while(!(a & 1))
        {
            a >>= 1;
            temp++;
        }
        res = min(res, temp);
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    //freopen("file.in", "r", stdin);freopen("file.out", "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.*;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

		int D = in.nextInt();
		int[] c = new int[26];
		int[][] s = new int[D][26];
		for (int i=0;i<26;i++) {
			c[i] = in.nextInt();
		}
		for (int i=0;i<D;i++) {
			int max_val = 0;
			int max_ind = 0;
			for (int j=0;j<26;j++) {
				s[i][j] = in.nextInt();
				if (max_val <= s[i][j]) {
					max_val = s[i][j];
					max_ind = j;
				}
				max_ind = 0;
			}
			// out.println(max_ind+1);
		}
		long tmp = 0L;
		int[] before_ind = new int[26];
		Arrays.fill(before_ind, -1);
		for (int i=0;i<D;i++) {
			int t = in.nextInt()-1;
			for (int j=0;j<26;j++) {
				if (j != t) tmp -= (long)c[j]*(i-before_ind[j]);
				else {
					tmp += s[i][j];
					before_ind[j] = i;
				}
			}
			out.println(tmp);
		}
		out.close();
	}

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}


Measured memory_bytes: 34548
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define st first
#define nd second

using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set =
	tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
#define shandom_ruffle random_shuffle
 
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;

const int mod = 998244353;
const int MAXN = 1e6 + 100;


int PowMod(int a, int n) {
	int r = 1;
	while (n) {
		if (n & 1) { r = (ll)r * a % mod; }
		n >>= 1;
		a = (ll)a * a % mod;
	}
	return r;
}

int n;
int tab[MAXN + 100];


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(11);
	cerr << fixed << setprecision(6);
	
	cin >> n;
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		int v; cin >> v;
		tab[v] += v;
		if (tab[v] >= mod) { tab[v] -= mod; }
		ans -= v;
		if (ans < 0) { ans += mod; }
	}
	
	for (int d = 1; d <= MAXN; ++d) {
		for (int i = 2 * d; i <= MAXN; i += d) {
			tab[d] += tab[i];
			if (tab[d] >= mod) { tab[d] -= mod; }
		}
	}
	
	for (int d = 1; d <= MAXN; ++d) {
		tab[d] = (ll)tab[d] * tab[d] % mod;
	}
	
	for (int d = MAXN; d >= 1; --d) {
		for (int i = 2 * d; i <= MAXN; i += d) {
			tab[d] -= tab[i];
			if (tab[d] < 0) { tab[d] += mod; }
		}
	}
	
	for (int d = 1; d <= MAXN; ++d) {
		ans += (ll)tab[d] * PowMod(d, mod - 2);
		ans %= mod;
	}
	
	ans = (ll)ans * PowMod(2, mod - 2) % mod;
	
	cout << ans << "\n";
}


Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {
    public int evenPatternCount (int num) {
        int count = 0;
        for (int i = num - 1; i >= 1; i--) {
            count += i;
        }

        return count;
    }

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int evenCount = 0;

        evenCount += MyClass.evenPatternCount(N);
        evenCount += MyClass.evenPatternCount(M);

        System.out.println(evenCount);
    }
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello{
    public static void Main(){
        var input = Console.ReadLine().Split(' ').Select(x=>Int64.Parse(x)).ToList();
        var n = input[0];
        var k = input[1];
        var x1 = n;
        
        if(k < n){
            x1 = n % k; 
        }
        
        if(x1 == 0){
            Console.WriteLine(x1);
            return;
        }
        
        var x2 = Math.Abs(x1 - k);
        
        if(x1 < x2){
            Console.WriteLine(x1);
            return;
        }
        
        Console.WriteLine(x2);
        return;
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){

  string S,T;cin>>S>>T;
    int N=S.size(),M=T.size();
    
    vector<int> ScntA(N+1,0),TcntA(M+1,0),ScntB(N+1,0),TcntB(M+1,0);
    
    for(int i=0;i<N;i++){
        if(S[i]=='A'){
            ScntA[i+1]=ScntA[i]+1;
            ScntB[i+1]=ScntB[i];
        }else{
            ScntA[i+1]=ScntA[i];
            ScntB[i+1]=ScntB[i]+1;
        }
    }
    
    for(int i=0;i<M;i++){
        if(T[i]=='A'){
            TcntA[i+1]=TcntA[i]+1;
            TcntB[i+1]=TcntB[i];
        }else{
            TcntA[i+1]=TcntA[i];
            TcntB[i+1]=TcntB[i]+1;
        }
    }
    
    int Q;cin>>Q;
    
    for(int i=0;i<Q;i++){
        int a,b,c,d;cin>>a>>b>>c>>d;
        a--;c--;
        
        int x=(ScntA[b]-ScntA[a]+300000-(ScntB[b]-ScntB[a]))%3;
        int y=(TcntA[d]-TcntA[c]+300000-(TcntB[d]-TcntB[c]))%3;
        if(x==y) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 2432
#!/usr/bin/env python3
#ABC117 B

n = int(input())
l = list(map(int,input().split()))
m = max(l)
mi = l.index(m)
sum = 0
for i in range(n):
    if i == mi:
        continue
    sum += l[i]
if sum > m:
    print('Yes')
else:
    print('No')


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

int main(){
	string T, P;
	cin >> T >> P;
	if (T.size() < P.size()) return 0;
	for (long i = 0; i < T.size() - P.size() + 1; i++){
		if (T[i] == P[0]){
			if (T.substr(i, P.size()) == P) printf("%d\n", i);
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N; cin >> N;
  ll a[N+1];
  for(int i=1;i<=N;i++){
    cin >> a[i];
  }
  ll sum = 0;
  map<ll, int> mp;
  mp[0] = 1;
  ll cnt = 0;
  for(int i=1;i<=N;i++){
    sum += a[i];
    if(mp.find(sum) == mp.end()){
      mp[sum] = 1;
    }else{
      cnt += mp[sum];
      mp[sum] = mp[sum] + 1;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" ";

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}


int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif
    ll c;
    cin>>c;
    cout<<1-c<<endl;
}

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

int dice[6] = {0, 1, 2, 3, 4, 5};

void rotate(int* s){
	int d0 =  dice[ s[0] ];
	int d1 =  dice[ s[1] ];
	int d2 =  dice[ s[2] ];
	int d3 =  dice[ s[3] ];
	int d4 =  dice[ s[4] ];
	int d5 =  dice[ s[5] ];
	dice[0] = d0;
	dice[1] = d1;
	dice[2] = d2;
	dice[3] = d3;
	dice[4] = d4;
	dice[5] = d5;
}
void rotateN(){int ary[]={1, 5, 2, 3, 0, 4};rotate(ary);}// 2 6 3 4 1 5
void rotateS(){int ary[]={4, 0, 2, 3, 5, 1};rotate(ary);}// 5 1 3 4 6 2
void rotateE(){int ary[]={3, 1, 0, 5, 4, 2};rotate(ary);}// 4 2 1 6 5 3
void rotateW(){int ary[]={2, 1, 5, 0, 4, 3};rotate(ary);}// 3 2 6 1 5 4

int main(){
	int a[6];
	for(int i=0; i<6; i++) cin >> a[i];
	
	string s;
	cin >> s;
	
	for(int i=0; i<s.size(); i++){
		switch(s[i]){
			case 'N': rotateN(); break;
			case 'S': rotateS(); break;
			case 'E': rotateE(); break;
			case 'W': rotateW(); break;
		}
	}
	cout << a[ dice[0] ] << endl;
	return 0;
}


Measured memory_bytes: 3100
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
    
        int amtTime = 0;
        int maxLoss = 10;
        int maxLossNum = 0;
      	boolean a = true;
        
         List<Integer> Array = new ArrayList<>();
        
        while(sc.hasNextInt()) {
        	Array.add((Integer)sc.nextInt());
        }
        
        for(int i = 0; i < Array.size(); i++ ){
            if(Array.get(i) % 10 != 0 && maxLoss > Array.get(i) % 10){
                maxLoss = Array.get(i) % 10; 
                maxLossNum = Array.get(i);
            };
        }        
        for(int j = 0; j < Array.size(); j++ ){
            if(Array.get(j) == maxLossNum && a){
                a = false;
              	continue;
            }else{
            	int t = Array.get(j);
            	int rt = t % 10;
            	int adj = 0;
            	if(rt > 0){
            	    adj = 10 - rt;
            	}
            	amtTime += t + adj;
            }
        }
        
        	System.out.println(amtTime + maxLossNum);
    }
}

Measured memory_bytes: 21844
import java.util.*;

public class Main {

	static int dset;
	static int[] balls = new int[10];

	public static boolean dfs(int l,int r,int d){	//lは左に入っている一番上の球の番号、dは深さ

		if(d==10)
			return true;

		if(balls[d]>l)
			 if(dfs(balls[d],r,d+1))
				return true;

		if(balls[d]>r)
			if(dfs(l,balls[d],d+1))
				return true;

		return false;
	}

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		dset =scan.nextInt();
		boolean[] result = new boolean[dset];
		for(int i=0;i<dset;i++){
			for(int j=0;j<10;j++){
				balls[j]=scan.nextInt();
			}
			result[i] = dfs(0,0,0);
		}

		for(int i=0;i<dset;i++){
			if(result[i])
				System.out.println("YES");
			else
				System.out.println("NO");
		}



	}
}

Measured memory_bytes: 12000
import std.algorithm;
import std.container;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;


class UnionFind(T) if (isIntegral!T) {
private:
  T[] rank;
  T[] par;
  T size;

public:
  this(T size) {
    rank = repeat(0.to!T).take(size).array;
    par = iota(size).array;
    this.size = size;
  }

  T length() {
    return size;
  }

  T getRoot(T n) {
    return par[n] = (par[n] == n ? n : getRoot(par[n]));
  }

  bool unite(T n1, T n2) {
    n1 = getRoot(n1);
    n2 = getRoot(n2);
    if (n1 == n2) return false;
    
    bool t = rank[n1] < rank[n2];
    par[t ? n1 : n2] = t ? n2 : n1;
    if (rank[n1] == rank[n2]) rank[n1]++;
    return true;
  }

  bool haveSameRoot(T n1, T n2) {
    return getRoot(n1) == getRoot(n2);
  }

  T countRoots() {
    T roots = 0;
    par.each!((i, v){ if (getRoot(v) == i) roots++; });
    return roots;
  }
}

void main() {
  auto nm = readln.chomp.split.to!(int[]);
  auto n = nm[0];
  auto m = nm[1];

  auto uf = new UnionFind!int(n);
  iota(m).each!((_){
    auto xyz = readln.chomp.split.to!(int[]);
    uf.unite(xyz[0] - 1, xyz[1] - 1);
  });

  uf.countRoots.writeln;
}



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

using namespace std;

#define dbg(x) cerr << #x"=" << x << endl;
typedef long long LL;
const int MAX_N = 1e5+100;
int n,m;
typedef pair<int, int> P;
#define l first
#define r second
P p[MAX_N];

int main(){
	//freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= m; ++i){
        cin >> p[i].l >> p[i].r;
    }
    sort(p+1, p+1+m);
    int l = p[1].l, r = p[1].r;
    for(int i = 2; i <= m; ++i){
        l = max(l, p[i].l);
        r = min(r, p[i].r);
        if(r < l) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (r-l+1) << endl;
	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
int main(){
int n; 
cin>>n;
if(n%10 == 3) cout<<"bon"<<endl;
else if(n%10 == 0 || n%10 == 6 || n%10 == 1 || n%10 == 8)cout<<"pon"<<endl;
else{
cout<<"hon"<<endl;
}
return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	if (400 <= X && X <= 599) {
		cout << 8 << endl;
	}else if (600 <= X && X <= 799) {
		cout << 7 << endl;
	}
	else if (800 <= X && X <= 999) {
		cout << 6 << endl;
	}
	else if (1000 <= X && X <= 1199) {
		cout << 5 << endl;
	}
	else if (1200 <= X && X <= 1399) {
		cout << 4 << endl;
	}
	else if (1400 <= X && X <= 1599) {
		cout << 3 << endl;
	}
	else if (1600 <= X && X <= 1799) {
		cout << 2 << endl;
	}
	else if (1800 <= X && X <= 1999) {
		cout << 1 << endl;
	}

}






Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main()
{
    int n,m,t;
    cin >> n >> m;
    int matrix [n][m];
    int Vector [m], result [n] = {0};

    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin >> matrix[i][j];

    for(int j = 0; j < m; j++)
            cin >> Vector[j];

    for(int f = 0; f < n; f++)
        for(int g = 0; g < m; g++)
        {
            t = (matrix[f][g] * Vector[g]);
            result[f] += t;
        }
    for(int i = 0; i < n; i++)
        cout << result[i] << endl;

    return 0;
}



Measured memory_bytes: 3148