akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, ans = 1e13;

int main() {
	cin >> n;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0 && n / i + i < ans)ans = n / i + i;
	}
	cout << ans - 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#%%二分探索?めんどくせぇ%% TLEしました。
import bisect

n,q=[int(i) for i in input().split(" ")]

Q=[[] for i in range(n)]

for _ in range(q):
    query=[int(j) for j in input().split(" ")]
    if query[0]==0:
        index=bisect.bisect_left(Q[query[1]],query[2])
        Q[query[1]].insert(index,query[2])
    elif query[0]==1:
        if len(Q[query[1]])>0:
            print(Q[query[1]][-1])
    else:
        if len(Q[query[1]])>0:
            Q[query[1]].pop(-1)



Measured memory_bytes: 13196
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main() {

	int n;
	cin >> n;
	vector<int> a(n + 1);

	for (int x = 1;x <= 100;x++) {
		for (int y = 1;y <= 100;y++) {
			for (int z = 1;z <= 100;z++) {
				int tmp = x * x + y * y + z * z + x * y + y * z + z * x;
				if (n >= tmp)a[tmp]++;
			}
		}
	}

	for (int i = 1;i <= n;i++) {
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		String str = reader.next();
		int ans = 0;
		int s = 0;
		int tmp = 0;
		while (s < str.length()) {
			char b = str.charAt(s);
			if (b == 'A' || b == 'T' || b == 'C' || b == 'G') {
				tmp++;
				if (tmp > ans) {
					ans = tmp;
				}
			} else {
				tmp = 0;
			}
			s++;
		}

		reader.close();
		System.out.println(ans);
	}
}





Measured memory_bytes: 22996
#include<cstdio>
#include<vector>
using namespace std;
inline int read()
{
	int x;char c;
	while((c=getchar())<'0'||c>'9');
	for(x=c-'0';(c=getchar())>='0'&&c<='9';)x=x*10+c-'0';
	return x;
}
#define MN 100000
#define MX 200
int d1[MX*2+5],d2[MX*2+5],f[MX*2+5];
vector<int> v[MX*2+5];
int gf(int k){return f[k]?f[k]=gf(f[k]):k;}
int main()
{
	int n,i,j,a,b,c,d;
	n=read();read();
	for(i=1;i<=n;++i)
		a=read(),b=read(),c=read(),d=read(),a=(c?-c:a)+MX,b=(d?d:-b)+MX,
		++d1[a],++d2[b],gf(a)!=gf(b)?f[gf(a)]=gf(b):0;
	for(i=1;i<=MX<<1;++i)if(d1[i]||d2[i])v[gf(i)].push_back(i);
	for(i=1;i<=MX<<1;++i)if(v[i].size())
	{
		for(j=a=b=0;j<v[i].size();++j)
			if(v[i][j]>MX)
			{
				if(d1[v[i][j]]<d2[v[i][j]])return 0*puts("NO");
				a+=d1[v[i][j]]-d2[v[i][j]];
				b|=d1[v[i][j]]-d2[v[i][j]];
			}
			else
			{
				if(d2[v[i][j]]<d1[v[i][j]])return 0*puts("NO");
				a+=d1[v[i][j]]-d2[v[i][j]];
			}
		if(!b||a)return 0*puts("NO");
	}
	puts("YES");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n;
  cin>>n;
  vector<ll> a(n);
  for (int i = 0; i < n; ++i)
  {
    cin>>a[i];
  }
  sort(a.begin(), a.end(),greater<ll>());
  ll ans=0;
  vector<ll> tmp(1,a[0]);
  for (int i = 1; i < n; ++i)
  {
    tmp.push_back(a[i]);
    tmp.push_back(a[i]);
  }
  for (int i = 0; i < n-1; ++i)
  {
    ans+=tmp[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 9016
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();
		int ans = Integer.MAX_VALUE;

		for(int i = 0;i <= s.length-c.length; ++i) {
			int j = 0, k = i, count = 0;
			while(j < c.length) {
				if(c[j++] != s[k++]) count++;
			}
			ans = Math.min(ans,count);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 27092
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            if(n == i * j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	string s, t;
	cin >> n >> s >> t;
	for (int i = 0; i < n; i++)
	{
		cout << s[i] << t[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a==b){
        if(b==c){
            printf("No\n");
        }else{
            printf("Yes\n");
        }
    }else if(b==c){
        printf("Yes\n");
    }else if(a==c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
S = input()
Q = int(input())
Atama = []
Osiri = []
rev = [0]*Q
for i in range(Q):
    a = list(input().split())
    if len(a) == 1:##T_i=1
        rev[i] = 1
    else:#T_i == 2
        if a[1] == "1":
            Atama.append([i,a[2],1])
        else:
            Osiri.append([i,a[2],-1])

##revの累積和
Rev = []
tmp = 0
r = sum(rev)
for i in range(len(rev)):
    r -= rev[i]
    Rev.append(r)
##print(Rev)
for i in range(len(Atama)):
    Atama[i][2] *= (-1)**Rev[Atama[i][0]]
for i in range(len(Osiri)):
    Osiri[i][2] *= (-1)**Rev[Osiri[i][0]]

Ans = Atama+Osiri
Ans.sort()
##print(Ans)
fw = ""
aw = ""
N = len(Ans)
for i in range(N):
    if Ans[i][2] == 1:
        fw += Ans[i][1]
    else:
        aw += Ans[i][1]

if sum(rev)%2 == 1:
    S = S[::-1]
fw = fw[::-1]

print(fw+S+aw)

Measured memory_bytes: 39200
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        FastScanner fsc = new FastScanner();
        char[] s = fsc.next().toCharArray();
        if(s.length == 3) {
            char tmp = s[0];
            s[0] = s[2];
            s[2] = tmp;
        }
        System.out.println(String.valueOf(s));
    }
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

const int maxV = 12345;
vector<int> graph[maxV];

/*
int ende;
int dm;
int center = -1;
bool besucht[maxV];

void treeDFS(int from, int current, int dist, int &maxDist, int &maxVertex) {
     if (dist > maxDist) {
         maxDist = dist;
         maxVertex = current;
     }
    for (auto to : graph[current]) {
        if (to == from) continue;
        treeDFS(current, to, dist + 1, maxDist, maxVertex);
    }
}

void getTreeDiameter() {
    int start = 0, end = 0, maxDist = 0;
    treeDFS(-1, start, 0, maxDist, end);
    start = end, end = 0, maxDist = 0;
    treeDFS(-1, start, 0, maxDist, end);
    ende = end, dm = maxDist;
	// printf("start: %d, end: %d, diameter: %d\n", start, end, maxDist);
}

void findCenter( int node, int dist ) {
	// cout << node << ", " << dist << endl;
	besucht[node] = true;
	if( dist >= (dm-dm%2)/2 ){
		center = node;
		return;
	}
	for( auto to : graph[node] ){
		if( center != -1 ) return; 
		if( besucht[to] ) continue;
		findCenter( to, dist+1 );
	}
}
*/

int res[maxV];
bool visited[maxV];

int main(){
	int n; cin >> n;
	for( int i = 0; i < n-1; ++i ){
		int a, b; cin >> a >> b; --a; --b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	vector<ll> c(n);
	for( auto &k : c ) cin >> k;
	if( n == 1 ){
		cout << 0 << endl;
		return 0;
	}
	cout << accumulate( c.begin(), c.end(), 0ll ) - *max_element( c.begin(), c.end() ) << endl;
	sort( c.begin(), c.end(), greater<ll>() );
	/*
    getTreeDiameter();
	findCenter( ende, 0 );
	*/
	queue<int> q;
	// q.push(center);
	q.push(0);
	int pnt = 0;
	while( !q.empty() ){
		int e = q.front(); q.pop();
		res[e] = c[pnt];
		visited[e] = true;
		for( auto to : graph[e] ){
			if( !visited[to] ) q.push(to);
		}
		++pnt;
	}
	for( int i = 0; i < n; ++i ){
		cout << res[i];
		if( i != n-1 ) cout << ' ';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1152
N = int(input())
Alist = [int(input()) for i in range(N)]
max_first = 0
max_second = 0
for ai in Alist:
    if max_first < ai:
        max_first, max_second = ai, max_first
    elif max_second < ai:
        max_second = ai
for ai in Alist:
    if max_first == ai:
        print(max_second)
    else:
        print(max_first)

Measured memory_bytes: 12532
// 1_2_B
#include <stdio.h>
#include <stdlib.h>

void SelectionSort(int *numbers, int length){
    int i, j, minj, tmp, cnt = 0;
    for(i = 0; i < length; i++){
        minj = i;
        for(j = i; j < length; j++){
            if(numbers[j] < numbers[minj]) minj = j;
        }
        if(minj != i){
            tmp = numbers[i];
            numbers[i] = numbers[minj];
            numbers[minj] = tmp;
            cnt++;
        }
    }

    for(i = 0; i < length - 1; i++){
        printf("%d ", numbers[i]);
    }
    printf("%d\n", numbers[i]);
    printf("%d\n", cnt);
    return;
}

int main(){
    int n, i, *numbers;
    scanf("%d", &n);
    numbers = (int *)malloc(sizeof(int) * n);
    for(i = 0; i < n; i++){
        scanf("%d", &numbers[i]);
    }

    SelectionSort(numbers, n);

    free(numbers);
    return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
 
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}
 
char buf[20];
void mypr(int n)
{
    int i;
    if (!n) { pc('0'); return; }
    i = 0; while (n) buf[i++] = n%10 + '0', n/=10;
    while (i--) pc(buf[i]); 
}
 
typedef struct { char c; int a; int id; } DATA;
 
int partition(DATA *a, int lo, int hi)
{
    int i, j;
    int key;
    DATA t;
     
    key = a[hi].a, i = lo-1;
    for (j = lo; j < hi; j++) {
        if (a[j].a <= key) i++, t = a[i], a[i] = a[j], a[j] = t;
    }
    t = a[++i], a[i] = a[hi], a[hi] = t;
    return i;
}
 
void quick_sort(DATA *a, int lo, int hi)
{
    int mi;
 
    if (lo < hi) {
        mi = partition(a, lo, hi);
        quick_sort(a, lo, mi-1);
        quick_sort(a, mi+1, hi);
    }
}
 
DATA a[100002];
 
int main()
{
    int N, i, f;
 
    N = in();
    for (i = 0; i < N; i++) {
        a[i].c = gc(), gc();
        a[i].a = in(), a[i].id = i;
    }
    quick_sort(a, 0, N-1);
    f = 0; for (i = 1; i < N; i++) {
        if (a[i-1].a == a[i].a && a[i-1].id > a[i].id) { f = 1; break; }
    }
    puts(f? "Not stable": "Stable");
    for (i = 0; i < N; i++) {
        pc(a[i].c), pc(' '), mypr(a[i].a), pc('\n');
    }
    return 0;
}


Measured memory_bytes: 2712
s = list(input())[::-1]
l = [0]*2019 
l[0] = 1
ten = 1
mod = 2019
now = 0
ans = 0
for i in range(len(s)):
    a = int(s[i])*ten
    now = (now+a)%mod
    ans += l[now]
    l[now] += 1
    ten *= 10
    ten %= 2019
print(ans)


Measured memory_bytes: 11784
using System;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		int N = int.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		string[] a = Console.ReadLine().Split(' ');
		string[] b = Console.ReadLine().Split(' ');
		
		int aCnt = 0;
		int bCnt = 0;
		
		int[] aRank = new int[N];
		int[] bRank = new int[N];
		for(var i = 0; i < N; i++){
		    aRank[i] = i;
		    bRank[i] = i;
		}
		for(var i = 0; i < N-1; i++){
		    if(N - (i+2) > 0){
    		    if(aRank[int.Parse(a[i])-1] > 0){
    		        aCnt += Kaijo(N-(i+1)) * (aRank[int.Parse(a[i])-1]);
    		    }
    		    if(bRank[int.Parse(b[i])-1] > 0){
    		        bCnt += Kaijo(N-(i+1)) * (bRank[int.Parse(b[i])-1]);
    		    }
    		    for(var j = 0; j < N; j++){
    		        if(j+1 > int.Parse(a[i])){
    		            aRank[j]--;
    		        }
    		        if(j+1 > int.Parse(b[i])){
    		            bRank[j]--;
    		        }
    		    }
		    }else{
		        aCnt += aRank[int.Parse(a[i])-1] == 0 ? 1 : 2;
		        bCnt += bRank[int.Parse(b[i])-1] == 0 ? 1 : 2;
		    }
		}
		//出力
		Console.WriteLine(Math.Abs(aCnt - bCnt));
	}
	static public int Kaijo(int n, int sum = 1){
	    if(n == 1){
	        return sum;
	    }else{
	        sum *= n;
	        return Kaijo(n-1, sum);
	    }
	}
	
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

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

    int a, b;
    cin >> a >> b;
    if (a == 1) a = 14;
    if (b == 1) b = 14;
    if (a > b) {
        cout << "Alice" << endl;
    } else if (a < b) {
        cout << "Bob" << endl;
    } else {
        cout << "Draw" << endl;
    }
}


Measured memory_bytes: 256
def paint(map_inp, x, y):
    if map_inp[y][x]:
        map_inp[y][x] = False
        if map_inp[y][x - 1]:
            map_inp = paint(map_inp, x - 1, y)
        if map_inp[y][x + 1]:
            map_inp = paint(map_inp, x + 1, y)
        if map_inp[y - 1][x]:
            map_inp = paint(map_inp, x, y - 1)
        if map_inp[y + 1][x]:
            map_inp = paint(map_inp, x, y + 1)
    return map_inp

while True:
    try:
        m = [[False for i in range(14)] for j in range(14)]
        for i in range(12):
            inp = input()
            for j in range(12):
                if inp[j] == "1":
                    m[i + 1][j + 1] = True

        cnt = 0
        for i in range(12):
            for j in range(12):
                if m[i + 1][j + 1]:
                    m = paint(m, j + 1, i + 1)
                    cnt += 1
        print(cnt)
        inp = input()
    except:
        break



Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) 
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que) priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
typedef vector<vector<int>> Matrix;
const int MOD = 1e9 + 7;
const int MAX = 1e7;
const int INF = numeric_limits<int>::max();





int main(){
  int n; cin >> n;
  string s;
  cin >> s;
  int f[n]={0};

  FOR(i,1, n)
  if (s[i] == 'E') f[0]++;
  FOR(i,1,n){
    f[i] = f[i - 1];
    if (s[i] == 'E')
      f[i]--;
    if(s[i-1]=='W')
      f[i]++;
  }
  int res = f[0];

  REP(i,n){
    if(res>f[i])
      res = f[i];
  }
  cout << res << endl;

}

Measured memory_bytes: 1796
function main(input){
    const f = Math.floor;
    const hour = f(input/60/60);
    const minute = f(f(input/60)%60);
    const second = f(input%60);
    console.log(hour+":"+minute+":"+second);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 15128
import sys
tmp=sys.stdin.readline().rstrip()
def main():
   ans=0
   cnt=[0]*2019
   cnt[0]+=1
   t=0
   d=1
   for i in reversed(tmp):
      t=(t+int(i)*d)%2019
      cnt[t]+=1
      d=d*10%2019
   for i in cnt:
      ans+=i*(i-1)//2
   print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 9312
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
//max_element

int N, P;
string S;
vector<int> s;

//int r[200010];
int mod_cnt[100010];

signed main()
{
	cin >> N >> P;
	cin >> S;
	for (char ch : S) s.push_back(ch - '0');
	int len = s.size();

	if (P == 2 || P == 5)
	{
		int ans = 0;
		for (int i = len - 1; i >= 0; i--)
		{
			if (s[i] % P == 0)
			{
				ans += (i + 1);
			}
		}
		cout << ans << endl;
		return 0;
	}

	int cur = 0;
	int ten = 1;
	int ans = 0;
	for (int i = len - 1; i >= 0; i--)
	{
		cur = (s[i] * ten + cur) % P;
		ten = (ten * 10) % P;
		if (cur == 0) ans++;
		ans += mod_cnt[cur];
		mod_cnt[cur]++;
	}
	cout << ans << endl;
}




Measured memory_bytes: 2680
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
const int N=2e5+5;
int dist[200005];
int inf=1e18;
int arr[N];
#define float long double
signed main()
{
 int a;float b;
 cin>>a>>b;
 float ans=a*b;
 cout<<(int)ans;
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000003;
const int maxn = 1e6+5;
ll fmod(ll x,ll y)
{
    ll ans = 1;
    while(y)
    {
        if(y&1)ans = ans*x%mod;
        x = x*x%mod;
        y >>= 1;
    }
    return ans;
}
ll l[maxn];
ll r[maxn];
void init()
{
    l[0] = 1;
    r[mod] = 1;
    for(ll i = 1; i <= 1000002; ++i)
    {
        l[i] = l[i-1]*i%mod;
        r[mod - i] = r[mod - i + 1]*(mod - i)%mod; 
    }
}
int main()
{
    init();
    int q;cin>>q;
    while(q--)
    {
        ll x,d,n;
        cin>>x>>d>>n;
        if(d == 0)
        {
            cout<<fmod(x,n)%mod<<endl;
            continue;
        }
        ll p = x*fmod(d,mod-2)%mod;
        if(p + n - 1 >= mod)
        {
            cout<<0<<endl;
            continue;
        }
        ll ans = l[1000002]*fmod(l[p-1],mod-2)%mod;
        ans = ans*fmod(r[p+n],mod-2)%mod;
        cout<<(ans*fmod(d,n)%mod)<<endl;
    }
}













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

using namespace std;
const double EPS = 1e-9;
#define SQR(x) ((x) * (x))

int main()
{
  int N, X[10], Y[10], L[10];
  double D[10][10];

  while(scanf("%d", &N), N) {
    for(int i = 0; i < N; ++i) {
      scanf("%d %d %d", &X[i], &Y[i], &L[i]);
    }
    for(int i = 0; i < N; i++) {
      for(int j = i + 1; j < N; j++) {
        D[i][j] = sqrt(SQR(X[i] - X[j]) + SQR(Y[i] - Y[j]));
      }
    }

    auto check = [&](double val)
    {
      vector< double > R;
      for(int i = 0; i < N; ++i) {
        R.emplace_back(sqrt(SQR(L[i]) - SQR(val)));
      }
      vector< pair< double, double > > P;
      for(int i = 0; i < N; ++i) {
        P.emplace_back(X[i], Y[i]);
      }
      for(int i = 0; i < N; ++i) {
        for(int j = i + 1; j < N; ++j) {
          if(abs(R[i] - R[j]) < D[i][j] && D[i][j] < R[i] + R[j]) {
            double a = atan2(Y[j] - Y[i], X[j] - X[i]);
            double theta = acos((SQR(D[i][j]) + SQR(R[i]) - SQR(R[j])) / (2 * D[i][j] * R[i]));
            P.emplace_back(X[i] + R[i] * cos(a + theta), Y[i] + R[i] * sin(a + theta));
            P.emplace_back(X[i] + R[i] * cos(a - theta), Y[i] + R[i] * sin(a - theta));
          }
        }
      }
      for(auto &&e : P) {
        double x, y;
        tie(x, y) = e;
        bool f = true;
        for(int i = 0; i < N; i++) {
          if(sqrt(SQR(X[i] - x) + SQR(Y[i] - y)) > R[i] + EPS) f = false;
        }
        if(f) return (true);
      }
      return (false);
    };

    double low = 1.0, high = *min_element(L, L + N);

    for(int i = 0; i < 25; ++i) {
      double mid = (low + high) / 2.0;
      if(check(mid)) low = mid;
      else high = mid;
    }
    printf("%.10lf\n", low);
  }

}

Measured memory_bytes: 3736
#include <iostream>
#include <cstdio>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>

using namespace std;

void solve()
{
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> vec[i];
	}
	int min = 1000000000, max = -1000000000;
	long long int sum = 0;
	for (int i = 0; i < n; ++i)
	{
		if (vec[i] < min)
		{
			min = vec[i];
		}
		if (vec[i] > max)
		{
			max = vec[i];
		}
		sum += vec[i];
	}
	cout << min << " " << max << " " << sum << endl;
}

int main()
{
	solve();
	return(0);
}

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

int main(){
  int w,a,b;
  cin >> w >> a >> b;
  int ans;
  if(b > (a + w)){
    ans = b - (a + w);
  }
  else if(a > (b + w)){
    ans = a - (b + w);
  }
  else{
    ans = 0;
  }

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


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

def calc(h, w):
    return W*h + w*H - w*h

H = int(readline())
W = int(readline())
N = int(readline())
inf = 10**9+7
res = inf

for h in range(H+1):
    for w in range(W+1):
        if calc(h, w) >= N:
            res = min(res, h+w)

print(res)


Measured memory_bytes: 39664
#include <iostream>
#include <string>
using namespace  std;
typedef long long int ll;
int main(){
string s,t;
int n,ans;
cin >> n;
cin >> s>>t;
  for(int i=n;i<=2*n;i++){
     if(s.substr(-n+i,2*n-i)==t.substr(0,2*n-i)) {
       ans=i;break;
     }
  }
cout << ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

char c[2][3];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    rep(i,2)rep(j,3) cin >> c[i][j];
    if(c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  Int k=0;
  while(k*(k-1)/2<n) k++;
  if(k*(k-1)/2!=n){
    cout<<"No"<<endl;
    return 0;
  }
  
  cout<<"Yes"<<endl;
  cout<<k<<endl;
  vector<vector<Int> > G(k);

  Int pos=0;
  for(Int i=0;i<k;i++){
    for(Int j=1;j<k-i;j++){
      //cout<<i+j<<":"<<k<<endl;
      G[i].emplace_back(pos);
      G[i+j].emplace_back(pos);
      pos++;
    }    
  }
  
  for(Int i=0;i<k;i++){
    cout<<k-1;
    for(Int x:G[i]) cout<<" "<<x+1;
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 3200
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
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();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXIST2(s,e) (find(ALL(s),(e))!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

string concat(const string &l,const string &r,int common){
	return l.substr(0,l.size()-common)+r;
}

typedef vector<vs> vvs;
typedef vector<vvs> vvvs;

string smaller(const string &l,const string &r){
	if(l.size()==r.size()){
		return min(l,r);
	}else{
		return (l.size()<r.size()?l:r);
	}
}

int main(){
	int n;
	while(cin>>n,n){
		vs s(n);
		REP(i,n){
			cin>>s[i];
		}

		vi unused(n);
		REP(i,n){
			REP(j,n){
				if(s[i]==s[j]){
					if(i<j)unused[j]=1;
				}else if(i!=j&&s[i].find(s[j])!=string::npos){
					unused[j]=1;
				}
			}
		}
		for(int i=n-1;i>=0;i--){
			if(unused[i]){
				s.erase(s.begin()+i);
			}
		}
		n=s.size();

		vvi common(n,vi(n));
		REP(i,n){
			REP(j,n){
				if(i==j)continue;
				int c=0;
				for(int k=min(s[i].size(),s[j].size());k>0;k--){
					bool flag=true;
					REP(l,k){
						if(s[j][l]!=s[i][s[i].size()-k+l]){
							flag=false;
							break;
						}
					}
					if(flag){
						c=k;
						break;
					}
				}
				common[i][j]=c;
			}
		}

		vvs dp(1<<n,vs(n,string(200,'z')));
		REP(i,n){
			dp[1<<i][i]=s[i];
		}
		REP(mask,1<<n){
			REP(i,n){
				if((1<<i)&mask){
					REP(j,n){
						if(((1<<j)&mask)==0){
							dp[mask|(1<<j)][j]=smaller(dp[mask|(1<<j)][j],concat(dp[mask][i],s[j],common[i][j]));
						}
					}
				}
			}
		}

		string ans(200,'z');
		REP(i,n){
			ans=smaller(ans,dp[(1<<n)-1][i]);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1824
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

int main() {
    double r;
    cin>>r;
    cout<<2*r*M_PI<<endl;
}


Measured memory_bytes: 3784
#include <iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	double a,b,c,d;
 	cin>>a>>b>>c>>d;
 	cout<<setprecision(10)<<sqrt((a-c)*(a-c)+(b-d)*(b-d))<<endl;
 }


Measured memory_bytes: 3284
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int n;
    int[] a, b, c;

    scan(n);
    a = readln.split.to!(int[]);
    b = readln.split.to!(int[]);
    c = readln.split.to!(int[]);

    a.sort();
    b.sort();
    c.sort();

    debug {
        writeln(a);
        writeln(b);
        writeln(c);
    }

    auto d = new long[](n + 1);

    int j;

    foreach (i ; 0 .. n) {
        for (;j < n; j++) {
            if (b[i] < c[j]) {
                d[i] = n - j;
                break;
            }
        }
    }

    foreach_reverse (i ; 0 .. n) {
        d[i] += d[i + 1];
    }

    debug {
        writeln("d:", d);
    }

    j = 0;
    long ans;

    foreach (i ; 0 .. n) {
        for (;j < n; j++) {
            if (a[i] < b[j]) {
                //writefln("i, j:%d %d", i, j);
                ans += d[j];
                break;
            }
        }
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<61
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,q; cin >> a  >> b >>q;
  vector<ll> s(a+2), t(b+2), x(q);
  s[0] = -LINF;
  s[a+1] = LINF;
  t[0] = -LINF;
  t[b+1] = LINF;
  REP(i,a){
      cin >> s[i+1];
  }
  REP(i,b){
      cin >> t[i+1];
  }
  REP(i,q){
      cin >> x[i];
  }
  REP(i,q){
      auto st = lower_bound(all(s), x[i]);
      auto tt = lower_bound(all(t), x[i]);
      ll ls,rs,lt,rt;
      ls = x[i]-*(st-1);
      rs = *st-x[i];
      lt = x[i]-*(tt-1);
      rt = *tt-x[i];
      ll ans = LINF;
      ans = min(ans, max(rs,rt) );
      ans = min(ans, max(ls,lt));
      ans = min(ans, 2*rt + ls);
      ans = min(ans, 2*rs + lt);
      ans = min(ans, 2*ls + rt);
      ans = min(ans, 2*lt + rs);
      cout << ans << endl;
  }

}



Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;

int main(){
    int A,B;
    cin >> A >> B;
    int ans = 0;
    while (true) {
        if(A*ans - (ans - 1) < B){
            ans++;
        }else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;cin>>n;
    long double ans = 0;
    long double b = 380000.0;
    rep(i,n){
        long double x;cin>>x;
        string s;cin>>s;
        if(s=="JPY")ans+=x;
        else ans+=b*x;
    }
    cout<<ans<<endl;
	return 0;
}

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

int main(){
	int n,q,last[300001];
	cin >> n >> q;
	for(int i = 0;i <= 300000;i++) last[i] = -1;
	for(int i = 0;i < n;i++){
		int c;
		cin >> c;
		last[c] = c;
	}
	last[0] = 0;
	for(int i = 1;i <= 300000;i++){
		if(last[i] == -1) last[i] = last[i - 1];
	}
	for(int i = 0;i < q;i++){
		int t,ma = 0;
		cin >> t;
		for(int j = t - 1;j <= 300000;j += t) ma = max(ma,last[j] % t);
		cout << ma << endl;
	}
	return 0;
}

Measured memory_bytes: 4268
n, m = map(int, input().split())
l, r = map(int, input().split())
L = [l]
R = [r]
for i in range(m-1):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)

L.sort()
R.sort()

n =  R[0] -L[m-1] +1
if n > 0:
    print(n)
else:
    print(0)

Measured memory_bytes: 11432
from collections import deque
V, E = map(int, raw_input().split())
g = [[] for i in xrange(V)]
deg = [0]*V
for i in xrange(E):
    s, t = map(int, raw_input().split())
    g[s].append(t)
    deg[t] += 1

ans = list(v for v in xrange(V) if deg[v]==0)
deq = deque(ans)
used = [0]*V

while deq:
    v = deq.popleft()
    for t in g[v]:
        deg[t] -= 1
        if deg[t]==0:
            deq.append(t)
            ans.append(t)
print "\n".join(map(str, ans))

Measured memory_bytes: 9920
class UnionFind():
    def __init__(self, n):
        self.size = n
        self.data = [-1 for _ in range(n)]
        self.sizes = [1 for _ in range(n)]

    def __len__(self):
        return self.size

    def root(self, i):
        """0 <= i < n"""
        if self.data[i] < 0:
            return i
        self.data[i] = self.root(self.data[i])
        return self.data[i]

    def connected(self, i, j):
        return self.root(i) == self.root(j)

    def groupsize(self, i):
        return self.sizes[self.root(i)]

    def roots(self):
        """O(n)"""
        return [i for i, v in enumerate(self.data) if v < 0]

    def unite(self, i, j):
        i = self.root(i)
        j = self.root(j)
        if i == j:
            return
        if (-self.data[i]) < (-self.data[j]):
            self.data[i] = j
            self.sizes[j] += self.sizes[i]
        elif (-self.data[i]) > (-self.data[j]):
            self.data[j] = i
            self.sizes[i] += self.sizes[j]
        else:
            self.data[i] += -1
            self.data[j] = i
            self.sizes[i] += self.sizes[j]


def nC2(n):
    return n * (n - 1) // 2


N, M = map(int, input().split())
AB = []
for _ in range(M):
    a, b = map(int, input().split())
    AB.append((a, b))

unconv = nC2(N)
revans = []
uf = UnionFind(N + 1)

for a, b in reversed(AB):
    revans.append(unconv)
    if uf.connected(a, b):
        continue
    unconv += nC2(uf.groupsize(a))
    unconv += nC2(uf.groupsize(b))
    uf.unite(a, b)
    unconv -= nC2(uf.groupsize(a))

for v in reversed(revans):
    print(v)


Measured memory_bytes: 23264
class SegmentTree():
  def __init__(self, n, oper, e):
    self.n = n
    self.oper = oper
    self.e = e
    self.log = (n - 1).bit_length()
    self.size = 1 << self.log
    self.data = [e] * (2 * self.size)

  def update(self, k):
    self.data[k] = self.oper(self.data[2 * k], self.data[2 * k + 1])

  def build(self, arr):
    #assert len(arr) <= self.n
    for i in range(self.n):
      self.data[self.size + i] = arr[i]
    for i in range(self.size-1,0,-1):
      self.update(i)

  def prod(self, l, r):
    #assert 0 <= l <= r <= self.n
    sml = smr = self.e
    l += self.size
    r += self.size
    while l < r:
      if l & 1:
        sml = self.oper(sml, self.data[l])
        l += 1
      if r & 1:
        r -= 1
        smr = self.oper(self.data[r], smr)
      l >>= 1
      r >>= 1
    return self.oper(sml, smr)

import sys
input = sys.stdin.readline

N, x = map(int, input().split())
A = list(map(int, input().split()))
INF = float('inf')
st = SegmentTree(N,min,INF)
st.build(A)
ans = INF
for k in range(N):
  score = 0
  for j in range(N):
    if j-k>=0:
      score += st.prod(j-k, j+1)
    else:
      score += min(st.prod(0, j+1),st.prod((j-k)%N,N))
  ans = min(ans, k*x+score)
print(ans)

Measured memory_bytes: 70852
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
using namespace std;
#define int long long
#define fr(i,n) for (int i = 0; i < n; i++)
#define fro(i,m,n) for (int i = m; i < n; i++)
#define pb push_back
#define iter ::iterator
#define fi first
#define se second


void io(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
}

void solve(){
  //io();
  int n,W;
  cin>>n>>W;
  int v[n],w[n];
  int V=0;
  fr(i,n){
    cin>>w[i]>>v[i];V+=v[i];
  }
  int dp[V+1];
  fr(i,V+1){
    dp[i]=1e18;
  }
  dp[0]=0;
  //std::cout << dp[1] << '\n';
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=V;j>=0;j--){
      if(v[i]<=j){
        dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
      }
      if(dp[j]<=W){
        ans=max(ans,j);
      }
    }
  }

  std::cout << ans << '\n';

}



int32_t main(){
  std::ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 4348
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int read(){
	int x=0,w=1;
	char ch=0;
	while (ch<'0' || ch>'9'){
		  if (ch=='-') w=-1;
		  ch=getchar();
	}
	while (ch<='9' && ch>='0'){
		  x=(x<<1)+(x<<3)+ch-'0';
		  ch=getchar();
	}
	return x*w;
}
const int N=1e3+5;
int n,m,vis[N],ans;
int a[N][N];
int cnt[2],flag;
int sz[N][2],tot;
int dp[N][N];
void dfs(int x,int fa,int c){
	if (flag) return;
	vis[x]=c;
	cnt[c]++;
	for (int i=1;i<=n;++i)
		if (a[x][i] && i!=fa){
			if (vis[i]==vis[x]) flag=1;
			if (vis[i]==-1) dfs(i,x,c^1);
		}
}
int main(){
	n=read();m=read();
	for (int i=1;i<=n;++i)
		a[i][i]=1;
	for (int i=1;i<=m;++i){
		int u=read(),v=read();
		a[u][v]=a[v][u]=1;
	}
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j)
			a[i][j]^=1;
	memset(vis,-1,sizeof(vis));
	for (int i=1;i<=n;++i){
		if (vis[i]==-1){
			cnt[0]=cnt[1]=0;
			dfs(i,0,1);
			sz[++tot][0]=cnt[0];
			sz[tot][1]=cnt[1];
		}
	}
	dp[0][0]=1; 
	for (int i=1;i<=tot;++i){
		for (int j=0;j<=n;++j){
			if (dp[i-1][j]){
				dp[i][j+sz[i][0]]=1;
				dp[i][j+sz[i][1]]=1;	
			}
		}
	}
	int ans=-1;
	for (int i=n>>1;i>=0;--i)
		if (dp[tot][i]){
			ans=i;
			break;
		}
	ans=(ans*ans)+((n-ans)*(n-ans))-n;
	ans>>=1;
	if (flag) ans=-1;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <algorithm>

using namespace std;

long long dp[100100][3];
long long a[100100][3];

int main(){
    int N;
    cin >> N;
    for(int i = 0;i < N;i++){
        for(int j = 0;j < 3;j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0;i < N;i++){
        for(int j = 0;j < 3;j++){
            for(int k = 0;k < 3;k++){
                if(j == k){
                    continue;
                }
                dp[i + 1][k] = max(dp[i + 1][k],dp[i][j] + a[i][k]);
            }
        }
    }
    long long Ans = 0;
    for(int i = 0;i < 3;i++){
        Ans = max(Ans,dp[N][i]);
    }
    cout << Ans << endl;

}

Measured memory_bytes: 4992
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    string S; cin >> S;
    int N = S.length();
    string a = "", b = "";
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) a += '1';
        else a += '0';
    }
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) b += '0';
        else b += '1';
    }
    int x = 0, y = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] != a[i]) x++;
        if (S[i] != b[i]) y++;
    }
    cout << min(x, y) << endl;
}

Measured memory_bytes: 3840
#include <stdio.h>
  
int main(){
  
  int x,y,z;
  
  while(1){
  
    scanf("%d %d", &x, &y);
  
    if(x == 0  && y == 0){
  
      break;
  
    } else {
  
    if(x > y){
  
      z = x;
  
      x = y;
  
      y = z;
  
    }
  
    printf("%d %d\n",x,y);
  }
  
  }
  
  return 0;
  
}

Measured memory_bytes: 600
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < (int)(n);++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define fi first
#define se second
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()


void fastik() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

//ifstream &cin
ll gcd(ll a, ll b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll cnt(ll r, ll c, ll d){
    //cout << r / (c * d / gcd(c,d)) << endl;
    return r / c + r / d - r / (c * d / gcd(c,d));
}

int main() {
    fastik();
    //ifstream cin("input.txt");
    /*ll t = 1;
    cin >> t;
    while(t--){
       solve();
    }*/
    ll ans = 1;
    ll n,x; cin >> n>>x;
    vll a(n);
    forn(i,n) cin >> a[i];
    ll d = 0;
    forn(i,n){
        d += a[i];
        if(d <= x){
            ans++;
        }else{
           break;
        }
    }
    cout << ans;
}
/*
 *532105071133627368
  532105071133627368
 */

Measured memory_bytes: 256
N = int(input())
a_list = [int(h) for h in input().split()]
attendance_list = [0 for _ in range(N)]
for i, a in enumerate(a_list):
    attendance_list[a-1] = i + 1
for i, attendance in enumerate(attendance_list):
    if i == len(attendance_list) - 1:
        print(attendance)
    else:
        print(attendance, end=" ")

Measured memory_bytes: 13880
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;
int N,M;
int dfs(vector<vector<int>> s, vector<int> p,vector<int> f, int depth)
{
	if(depth==N)
	{
		//照合
		for(int i=0; i<M; i++)
		{
			if(p[i]!=f[i])
			{
				return 0;
			}
		}
		return 1;
	}

	vector<int> next_f = f;

	for(int i=0; i<M; i++)
	{
		if(s[i][depth]==1)
		{
			next_f[i]++;
			next_f[i]%=2;
		}
	}

	return dfs(s,p,f,depth+1) + dfs(s,p,next_f,depth+1);
}
int main()
{
	
	cin>>N>>M;
	vector<vector<int>> s(M);
	for(int i=0; i<M; i++)
	{
		int k;
		cin>>k;
		s[i].resize(N,0);

		for(int j=0; j<k; j++)
		{
			int index;
			cin>>index;
			index--;
			s[i][index] = 1;
		}
	}

	vector<int> p(M);
	for(int i=0; i<M; i++)
	{
		cin>>p[i];
	}
	vector<int> f0(M,0);

	cout<<dfs(s,p,f0,0)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define ll long long int
using namespace std;

void Solve(  ){
   int n;
   cin >> n;
   string s;
   cin >> s;
   int counter = 0;
   for(int i=0; i+2<n; i++)
   {
       if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
       {
           counter++;
       }
   }
   cout << counter;
}
int main(){
  //  int t;
   // cin >> t;
   // while(t--)
   {
        Solve( );
        cout << '\n';
   }
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n;
vector<string> s;
map<string,ll> cnt;

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

  cin>>n;
  s.resize(n);
  ll res=0;
  rep(i,n){
    cin>>s[i];
    sort(all(s[i]));
    res+=cnt[s[i]];
    cnt[s[i]]++;
  }
  cout<<res<<endl;

  return 0;
}


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

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vli;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define I cin
#define O cout
#define EN endl
#define ln cout<<endl
#define pb(a) push_back(a)
#define x first
#define y second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
  return (b ? gcd(b, a % b) : a);
}

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

llint cnt = 0, cntt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int n;
vi a, b;

int main()
{
  I >> n;
  for(int i = 0; i < n; i++) {
    int k;
    I >> k;
    a.pb(k);
  }

  b = a;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<int>());

  bool lr = true;
  int l, r;
  l = r = a[0];
  for(int i = 0; i < n / 2; i++) {
    if(lr) {
      cnt += b[i] * 2 - a[i + 1] - l;
      l = a[i + 1];
      lr = !lr;
    } else {
      cnt += b[i] * 2 - a[i + 1] - r;
      r = a[i + 1];
      lr = !lr;
    }
  }

  l = r = b[0];
  lr = true;
  for(int i = 0; i < n / 2; i++) {
    if(lr) {
      cntt += l + b[i + 1] - a[i] * 2;
      l = b[i + 1];
      lr = !lr;
    } else {
      cntt += r + b[i + 1] - a[i] * 2;
      r = b[i + 1];
      lr = !lr;
    }
  }
  
  O << max(cnt, cntt) << EN;
  
  return 0;
}


Measured memory_bytes: 1144