akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int W,H,k;
inline int _gcd(int a,int b){
	if(b==0)return a;
	return _gcd(b,a%b);
}
ll Solve(int n,int m){
	int lim=3*m+2*k;
	ll ans=0;
	for(int y=1;y<m;++y){
		for(int d=0;d<n-1&&d*y<=lim;++d){
			int t=_gcd(m,d)+2*k-d*y-2;
			if(t<0)continue;
			int x=t/m+1;
			ans+=(min(t/m,n-d-1)+(x+d<n&&x*m-_gcd(x,y)-_gcd(m-y,x+d)<=t))*(1+(d>0));
		}
	}
	return ans;
}
int main(){
	W=read(),H=read(),k=read();
	printf("%lld\n",(Solve(W,H)+Solve(H,W))<<1);
	return 0;
}

Measured memory_bytes: 3756
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <functional>
#include <cstdio>
using namespace std;

int solve(int in){
	char mozi[9] = {};
	int max, min;
	// itoa(in, mozi, 10);
	sprintf(mozi, "%d", in);

	sort(mozi, mozi + 8);
	min = atoi(mozi);

	sort(mozi, mozi + 8, greater<int>());
	max = atoi(mozi);
	
	return abs(max - min);
}


int main(){
	int n,in;

	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> in;
		cout << solve(in) << endl;
	}

	return 0;
}

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

#define ll long long
#define dbg(x) cout << #x << " = " << x << endl

int n, w;
vector<int> valor, peso;
int INF = INT_MAX;
vector<vector<ll>> memo;

ll dp(int i, int weight) {
    if (weight < 0) return -INF;
    if (i == n) return 0;
    ll &ans = memo[i][weight];
    if (ans != -1) return ans;
    return ans = max(dp(i + 1, weight), dp(i + 1, weight - peso[i]) + valor[i]);
}

int main() {
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> w;
    for (int i = 0; i < n; ++i) {
        int a, b; cin >> a >> b;
        peso.push_back(a);
        valor.push_back(b);
    }
    memo.resize(n + 5, vector<ll>(w + 5, -1));
    cout <<  dp(0, w) << endl;
    return 0;
}

Measured memory_bytes: 86244
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

int main(){
    int N;
    string S;

    cin >> N >> S;

    vector<int> V;    
    int count_s = 0;
    int count_d = 0;
    
    int mini = 0;

    for(int i = 0; i < N; i++){
        if(S[i] == '#'){
            count_s++;
            if(count_d != 0){
                V.push_back(count_d);
                count_d = 0;
            }
        }
        else{
            count_d++;
            if(count_s != 0){
                V.push_back(count_s);
                count_s = 0;
            }
        }
    }
    if(count_d != 0) V.push_back(count_d);

    if(S[0] == '.') V.erase(V.begin());

    if(V.size() == 0) cout << 0 << "\n";

    else{  
        int sum = 0;
        for(int i = 1; i < V.size(); i = i+2){
            sum += V[i];
        }
        mini = sum;

        for(int i = 1; i < V.size(); i = i+2){
            sum += (V[i-1] - V[i]);
            mini = min(sum, mini);
        }
        cout << mini << endl;
    }

    // for(int i = 0; i < V.size(); i++){
    //     cout << V[i] << ", ";
    // }
    // cout << endl;
    

}


Measured memory_bytes: 1532
from collections import deque

n, m = list(map(int, input().split()))
root_dict = {}

for _ in range(m):
    a, b = list(map(int, input().split()))
    if a not in root_dict:
        root_dict[a] = [b]
    else:
        root_dict[a].append(b)
    if b not in root_dict:
        root_dict[b] = [a]
    else:
        root_dict[b].append(a)

visited = [1] + [-1] * (n-1)

done = deque([1])

while done:
    x = done.popleft()
    for i in root_dict[x]:
        if visited[i-1] < 0:
            visited[i-1] = x
            done.append(i)

if -1 in visited:
    print("No")
else:
    print("Yes")
    for i in range(1, n):
        print(visited[i])

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

int main() {
 int N;
  cin >> N;
  int c = 0;
  
  while(1){
   if(N == 1){
      break;
    }
    N = N/2;

     c++;
  }
  
  int d = 1;
  for(int i = 1; i < c+1; i++){
    d = d * 2;
  }
  cout << d << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;
int main(){
    int X,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A),q(B),r(C);
    for(int i=0; i<A; i++){
        cin >> p.at(i);
    }
    for(int i=0; i<B; i++){
        cin >> q.at(i);
    }
    for(int i=0; i<C; i++){
        cin >> r.at(i);
    }
    sort(p.begin(),p.end());
  	sort(q.begin(),q.end());
 	sort(r.begin(),r.end());
    reverse(p.begin(),p.end());
  	reverse(q.begin(),q.end());
  	reverse(r.begin(),r.end());
    int total=0;
    int aka=0;
    int mido=0;
    int mu=0;
    ll sum=0;
    while(total<X+Y){
        int a,b,c=0;
        if(aka<X) a=p.at(aka); else a=0;
        if(mido<Y) b=q.at(mido); else b=0;
        if(mu<C) c=r.at(mu); else c=0;
      	
        if(a>=b && a>=c){
            sum+=a;
            aka++;
            total++;
        }else if(b>=c){
            sum+=b;
            mido++;
            total++;
        }else{
            sum+=c;
            mu++;
            total++;
        }
      	
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 2688
#include<iostream>
#include<cmath>
#include<string>
#include<cstdlib>
#include<ctime>
#include<map>
#include<vector>
#include<list>
#include<set>
#include<string>
using namespace std;

#define ll long long
#define ld long double
#define uint unsigned int
#define alloc(n,type) (type*)calloc(n,sizeof(type))
#define MODULE 1
#define RAND(min,max) (rand()%(max-min+1)+min)
#define repeat(i,condition) for(int i = 0; condition; i++)
#define LOG(log) cout<<#log<<" : "<<log<<'\n'
#define DEBUG() {cout<<"DEBUG "<<num_debug<<'\n'; num_debug++;}
int num_debug = 0;
bool* IsPrime;
vector<int> Prime;

int compare_int(const void* a, const void* b);
void PrimeEnable(int n);
class Math;
class Module;

int main(void) {
	srand((unsigned)time(NULL));

	int N;
	cin >> N;

	repeat(i, i < N) {
		printf("ACL");
	}

	return 0;
}

int compare_int(const void* a, const void* b) {
	//昇順
	return *(int*)a - *(int*)b;
}
void PrimeEnable(int n) {
	//initialize IsPrime
	IsPrime = (bool*)calloc(n + 1, sizeof(bool));
	for (int i = 0; i <= n; i++)
		IsPrime[i] = true;

	//IsPrime 
	IsPrime[0] = IsPrime[1] = false;
	for (int i = 2; i * i <= n; i++) {
		if (IsPrime[i])
			for (int j = i; i * j <= n; j++) {
				IsPrime[i * j] = false;
			}
	}

	//push back to Prime
	for (int i = 0; i <= n; i++) {
		if (IsPrime[i])
			Prime.push_back(i);
	}
}
class Math {
public:
	template<typename T> static T Fac(int n) {
		T ans = 1;
		for (int i = 2; i <= n; i++) {
			ans *= i;
		}
		return ans;
	}
public:
	template<typename Tout, typename Tin> static Tout P(Tin n, Tin r) {
		Tout ans = 1;
		for (Tin i = 0; i < r; i++) {
			ans *= n - i;
		}
		return ans;
	}
public:
	template<typename T>static T C(int n, int r) {
		T nmr = 1;
		T dnm = 1;
		if (n - r < r)
			r = n - r;
		for (int i = 0; i < r; i++) {
			nmr *= n - i;
			dnm *= r - i;
		}
		return nmr / dnm;
	}
};
class Module {
public:
	static const int mod = MODULE;

public:
	static int add(int a, int b) {
		long ans = (long)a + b;
		if (ans < 0)
			ans += mod;
		ans %= mod;
		return ans;
	}
public:
	static int mult(int a, int b) {
		long ans = (long)a * b;
		return ans % mod;
	}

public:
	static int Pow(int a, int b) {
		int base = a % mod;
		if (mod / 2 < abs(base))
			if (base < 0) {
				base += mod;  //negative
			}
			else {
				base -= mod;  //positive
			}

		return pow(base, b);
	}
};

Measured memory_bytes: 3688
N,T = list(map(int,input().split()))
ans = []
for i in range(N):
    c,t = list(map(int,input().split()))
    if t > T:
        continue
    else:
        ans.append(c)
if len(ans) != 0:
    print(min(ans))
else:
    print('TLE')
        

Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  ll n;
  cin >> n;
  vector<ll> a(n);
  REPe(e, a) cin >> e;
  int q;
  cin >> q;
  vector<ll> b(q), c(q);
  REP(i, q) cin >> b[i] >> c[i];
  vector<ll> num(1e5 + 1, 0);
  ll sum = 0;
  REP(i, n) {
    num[a[i]]++;
    sum += a[i];
  }
  REP(i, q) {
    ll j = num[b[i]];
    num[b[i]] = 0;
    sum = sum - (ll)b[i] * (ll)j + (ll)c[i] * (ll)j;
    cout << sum << endl;
    num[c[i]] += j;
  }
}


Measured memory_bytes: 6360
def main():
    L, R = list(map(int, input().split()))
    minmod = 10000000
    for i in range(L, R):
        for j in range(i+1, R+1):
            prod = i * j
            mod = prod % 2019
            #mod = np.mod([prod], 2019)[0]
            if mod < minmod:
                minmod = mod
            if minmod < 1:
                break
        else: continue
        break
    print(minmod)

main()

Measured memory_bytes: 38768
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,s1,s2;
	cin>>s;
	s1=s2=s;
	reverse(s1.begin(),s1.end());
	for (auto &i : s1)
	{
		if (i=='b')
			i='d';
		else
		if (i=='d')
			i='b';
		else
		if (i=='p')
			i='q';
		else
		if (i=='q')
			i='p';
	}
		
	if (s==s1)
	{
		cout<<"Yes";
	}
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

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

int main()
{
  FOR(i,1,10) {
    FOR(j,1,10) {
      printf("%dx%d=%d\n",i,j,i*j);
    }
  }
  return 0;
}


Measured memory_bytes: 2612
#include <iostream>
#include <math.h>
#include<stdio.h>
#include <climits>
using namespace std;

int main()
{

	ios::sync_with_stdio(false);
	string s;
	int i = 0, j = 0 ;
	int ans = 0;
	
	cin >> s;
	for (i; s[i] != '\0'; i++) {
		//cout << j << "\n";
		if (s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T') j++;
		else {
			
			if (ans < j) { 
				ans = j; 
			}
			else;
			j = 0;
		}
	}
	if (ans < j) {
		ans = j;
	}
	else;
	cout << ans << endl;
}
//ATCOATCATC

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll power(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)

//your code here!
int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート 1,2,....9
}

int main(void){
    ll N, A[100100], is_ans0=0;
    scanf("%lld", &N);
    rep(i, N) scanf("%lld", A+i);
    qsort(A, N, sizeof(ll), cmp);//昇順ソート
    if(N%2==1) {
        if(A[0]!=0) is_ans0=1;
        for(ll i=1; i<N; i+=2) if( A[i]!=A[i+1] || A[i]!=i+1 ) is_ans0=1;
    }
    else {
        for(ll i=1; i<N; i+=2) if( A[i]!=A[i-1] || A[i]!=i ) is_ans0=1;
    }

    if(is_ans0) printf("0\n");
    else {
        ll ans=1;
        rep(_, N/2) {
            ans *= 2;
            ans %= MOD;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};

struct UnionFind {
    //自身が親であれば、その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;

    UnionFind(int N) {
        r = vector<int>(N, -1);
    }

    int root(int x) {
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) {
        return -r[root(x)];
    }
};

int main(void){
  int N, M;
  cin >> N >> M;
  UnionFind UF(N);
  rep(i,M){
    int A, B;
    cin >> A >> B;
    A --; B --;
    UF.unite(A, B);
  }
  set<int> S;
  rep(i,N){
    S.insert(UF.root(i));
  }
  int ans = S.size() - 1;
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n,c=1,a=-1;
  cin >> n;
  vector<int> data(n);
  for (int i=0; i<n; i++) cin >> data.at(i);
  for (int i=0; i<n; i++) {
    c = data.at(c-1);
    if (c == 2) {
      a = i+1;
      break;
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 768
#include <stdio.h>

int main(){
  int n,m,l;
  int a[100][100],b[100][100],i,j,k;
 unsigned long int c[100][100];
  scanf("%d %d %d",&n,&m,&l);
  for(i=0; i<n; i++){
    for(j=0; j<m; j++){
      scanf("%d",&a[i][j]);
    }
  }
  for(i=0; i<m; i++){
    for(j=0; j<l; j++){
      scanf("%d",&b[i][j]);
    }
  }
  for(i=0; i<n; i++){
    for(j=0; j<l; j++){
      c[i][j]=0;
    }
  }//----       
 for(i=0; i<n; i++){//                                                         
    for(j=0; j<l; j++){
      for(k=0; k<m; k++){
        c[i][j]+=(a[i][k]*b[k][j]);
      }
    }
  }
  for(i=0; i<n; i++){
    for(j=0; j<l; j++){
      if(j==l-1)printf("%ld\n",c[i][j]);
      else printf("%ld ",c[i][j]);
    }
  }
  return 0;
}


Measured memory_bytes: 2140
import java.util.*;

class Main {
    private static Scanner sc;

    public static void main(final String[] args) {
        sc = new Scanner(System.in);
        int a = sc.nextInt(),b = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < b; i++) list.add(sc.nextInt());
        if(!list.contains(a)){
            System.out.println(a);
            System.exit(0);           
        }     
        for (int i = 1; i <= 100; i++) {          
            a -= i;
            if(list.contains(a)){
                a += i*2;
                if(list.contains(a)){
                    a -= i;
                }else {
                    System.out.println(a);
                    System.exit(0);
                }
            }else {
                System.out.println(a);
                System.exit(0);
            }
           
        }
    }
}








Measured memory_bytes: 35484
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int N = scanner.nextInt();
        int a = 1;
        for (int i = 0; i < 10; i++) {
            int b = a * 2;
            if (b > N) {
                System.out.println(a);
                return;
            } else {
                a = b;
            }
        }
        System.out.println(a);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";

        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {
                    line = br.readLine();
                }
                s = line.split(reg, 0);
                i = 0;
                return s[i++];
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public int nextInt() {
            try {
                return Integer.parseInt(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public double nextDouble() {
            try {
                return Double.parseDouble(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public long nextLong()  {
            try {
                return Long.parseLong(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }
    }
}


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

class Dmondai
{
    static void Main()
    {
        var line = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
        var N = line[0];
        var K = line[1];

        //バーガー全体の数
        var bArray = new long[N + 1];
        bArray[0] = 1;
        //パティの数
        var pArray = new long[N + 1];
        pArray[0] = 1;
        for (long i = 1; i <= N; ++i)
        {
            bArray[i] = bArray[i - 1] * 2 + 3;
            pArray[i] = pArray[i - 1] * 2 + 1;
        }

        var ans = 0L;
        var k = K;
        for (var i=N;-1<i;--i) {
            var num = (bArray[i] + 1) / 2;
            if (k <= i)
            {
                break;
            }
            else if ((num - 1) == k || (num - 2) == k)
            {
                ans += pArray[i - 1];
                break;
            } else if (num == k)
            {
                ans += pArray[i - 1] + 1;
                break;
            } else if (bArray[i] - i <= k)
            {
                ans += pArray[i];
                break;
            }
            else {
                if (num < k)
                {
                    ans += pArray[i - 1] + 1;
                    k -= num;
                }
                else
                {
                    --k;
                }
            }
        }
        Console.WriteLine(ans);
    }
}

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

using namespace std;
#define ll long long

const int N = 100005;
int n, m, cf, cg, cnt, ans, a[N], b[N], c[N], cc[N], d[N], dd[N], f[N], g[N], p[N];
ll sum, cyc;
bool vis[N];
int main() {
	// freopen("C:\\Users\\Cekavis\\Downloads\\01-63.txt", "r", stdin);
	scanf("%d%d", &n, &m);
	for(int i=1; i<=m; ++i){
		scanf("%d%d%d", a+i, b+i, c+i);
		++d[a[i]], ++dd[b[i]], p[a[i]]=b[i], cc[a[i]]=c[i];
		if(a[i]!=b[i]) sum+=c[i]-1, ++ans;
	}
	for(int i=1; i<=m; ++i) if(a[i]==b[i]){
		if(dd[a[i]]>1 || d[a[i]]>1){
			if(c[i]>1) f[++cf]=c[i]-1;
		}
		else if(c[i]>2) g[++cg]=c[i]-2;
	}
	for(int i=1; i<=n; ++i) if(!vis[i] && d[i]==1 && dd[i]==1 && p[i]!=i){
		int u=i;
		ll s=0;
		while(!vis[u] && d[u]==1 && dd[u]==1) vis[u]=1, s+=cc[u]-1, u=p[u];
		if(u==i) ++ans, ++cnt, cyc+=s;
	}
	sort(f+1, f+cf+1, greater<int>()), sort(g+1, g+cg+1, greater<int>());
	int mn=cnt?1e9:0;
	for(int i=sum==cyc, j=0; i<=cf; ++i){
		sum+=f[i];
		while(j<cg && sum<cnt) sum+=g[++j];
		while(j && sum-g[j]>=cnt) sum-=g[j--];
		if(sum>=cnt) mn=min(mn, i+j*2);
	}
	if(mn==1e9) puts("-1"); else printf("%d\n", ans+mn);
	return 0;
}

Measured memory_bytes: 6732
#include <iostream>
#include <ctype.h>
#include <vector>
#include <string>

using namespace std;

void func_A() {

    char s;
    cin >> s;

    if (isupper(s)) cout << "A";
    else cout << "a";

}

void func_B() {

}

void func_C() {

}

int main() {

    func_A();
    //func_B();
    //func_C();

    return 0;
}

Measured memory_bytes: 3620
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      int n = sc.nextInt();
      int[] a = new int[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
      System.out.println(a[n-1]);
    } finally {
      sc.close();
    }
  }
}

Measured memory_bytes: 35852
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    vector<int> t(n), x(n), y(n);
    rep(i,n){
        cin >> t[i] >> x[i] >> y[i];
    }
    int a = 0, b = 0,c = 0;
    rep(i,n){
        int len = (t[i]-c)-abs(x[i] - a) - abs(y[i] - b);
        if(len%2==0 && len >= 0){
            c = t[i];
            a = x[i];
            b = y[i];
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

int main(){
  int a,i,j;
  cin>>a;
  int f[101];
  for(i=0;i<=100;i++){
    f[i]=0;
  }
  for(i=1;i<10;i++){
    for(j=1;j<10;j++){
      f[i*j]=1;
    }
  }
  if(f[a]){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;

ll step(ll pre)
{
  if(pre%2)return 3*pre+1;
  return pre/2;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll s;
  cin>>s;
  set<ll>ma ;
  rep(i,1000000)
  {
    //cout<<s<<endl;
    if(ma.count(s)>0)
    {
      cout<<i+1<<endl;
      return 0;
    }
    ma.insert(s);
    s=step(s);

  }


  return 0;

}


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

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for(int i = 0; i < N; i++){
    cout << vec.at(i);
  }
  cout <<endl;
}

Measured memory_bytes: 256
n = int(input())
s = []
for _ in range(n):
    S = list(input())
    S.sort()
    s.append(S)
#print(s)
a_z = "abcdefghijklmnopqrstuvwxyz"
ans = []
for i in range(26):
    minimum = 1000000
    for j in range(n):
        kosuu = s[j].count(a_z[i])
        minimum = min(minimum, kosuu)
        if minimum == 0:
            break
    else:
        for _ in range(minimum):
            ans.append(a_z[i])
print("".join(ans))



Measured memory_bytes: 66352
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int A,B,ans;
  cin >> A >> B;
  ans = A - 2*B;
  if(ans < 0){
    ans = 0;
	cout << ans;
  }else{
  
  cout << ans;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;

int main()
{
    ll w, h, x, y;
    cin >> w >> h >> x >> y;

    string s = to_string(w * h / 2);
    if (w * h % 2 != 0)
    {
        s += ".5";
    }

    int way = 0;
    if (x * 2 == w && y * 2 == h)
    {
        way = 1;
    }

    cout << s << " " << way << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,i,j,flg;
	scanf("%d",&n);
	flg=1;
	for(i=1;i<10;i++){
		for(j=1;j<10;j++){
			if(n==i*j){
				flg=0;
				break;
			}
		}
	}
	if(flg==0)	printf("Yes\n");
	else	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  char a,b;
  cin>>a>>b;
  if(a=='H'){
    if(b=='H'){
      cout<<'H'<<endl;
    }
    else if(b=='D'){
      cout<<'D'<<endl;
    }
  }
  else if(a=='D'){
    if(b=='H'){
      cout<<'D'<<endl;
    }
    else if(b=='D'){
      cout<<'H'<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define D(x) cout << #x << "=" << x <<endl; 
using namespace std; 

//int _; 

string s;

int main()
{
	//for(scanf("%d",&_);_;_--)
	cin >> s;
	s=s.substr(0,3);
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    INT(n);
    VI a(n); VIin(a);
    int ans = 0;
    int res = 1;
    bool flag = false;
    rep(i,n){
        if(res != a[i]) ans++;
        else res++;
        if(a[i] == 1) flag = true;
    }
    if(flag) ANS;
    else OUT(-1);

    return 0;
}

Measured memory_bytes: 1792
//Zory-2020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}
	
	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=1e9+7;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int M=1e3+10;
	ll fac[M],facinv[M],Inv[M];ll C(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,M-1) fac[i]=fac[i-1]*i%MOD;
		facinv[M-1]=invm(fac[M-1]);fd(i,M-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,M-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e6+10;
	//------------------FIXED------------------
	//��״����
	struct BIT
	{
		int bit[N];int lowbit(int x){return x&-x;}
		void ad(int x,int c){ while(x<N) bit[x]+=c,x+=lowbit(x); }
		int ask(int x){ int ret=0;while(x>=1) ret+=bit[x],x-=lowbit(x);return ret; }
	}bit;
	char str[N];deque<int> pos[30];bool ok[N];
	void main()
	{
		scanf("%s",str+1);int n=strlen(str+1);fo(i,1,n) pos[str[i]-'a'].PB(i);
		fo(i,1,n) bit.ad(i,1);int ct=0;fo(i,0,25)ct+=sz(pos[i])%2;if(ct>n%2) GG();
		ll ans=0;
		fo(i,1,n) if(!ok[i])
		{
			int col=str[i]-'a',j=pos[col].back();ok[i]=ok[j]=1;
			pos[col].pop_front(),bit.ad(i,-1);
			if(i!=j) pos[col].pop_back(),bit.ad(j,-1),ans+=bit.ask(n)-bit.ask(j);
			else ans+=bit.ask(n)/2;//ʣ���ˣ�һ����һ����
		}write(ans);
	}
};//����������
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();//����Ԥ����ģ����
	mine::main();
	debug("\n---------------------Zory---------------------\nTime: %.2lf s",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 3712
package main

import "fmt"
import "strconv"

func main() {
	var a,b string
	var axb,bxa string
	var inta,intb int
	var intaxb,intbxa int
	fmt.Scan(&a)
	fmt.Scan(&b)
	inta, _ = strconv.Atoi(a)
	intb, _ = strconv.Atoi(b)
	for i := 0; i < intb; i++ {
		axb += a
	}
	for i := 0; i < inta; i++ {
		bxa += b
	}
	intaxb, _ = strconv.Atoi(axb)
	intbxa, _ = strconv.Atoi(bxa)
	if intaxb > intbxa {
		fmt.Println(axb)	
	} else {
		fmt.Println(bxa)
	}
}


Measured memory_bytes: 512
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
#define inf 1000000007
signed main(){
    int n;cin>>n;
    string s;cin>>s;
    int num[105];
    rep(i,0,n){
        if(s[i]=='(')num[i]=1;
        else num[i]=-1;
    }
    int sum[105]={};
    sum[0]=num[0];
    int mini=0;
    mini=min(mini,sum[0]);
    rep(i,1,n){
        sum[i]+=sum[i-1]+num[i];
        mini=min(mini,sum[i]);
    }
    int ds=sum[n-1];
    mini*=-1;
    rep(i,0,mini){
        cout<<"(";
    }
    cout<<s;
    rep(i,0,ds+mini){
        cout<<")";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Unit = {
    val N, W = sc.nextInt
    val dp = Array.fill[Int](W + 1)(0)
    for (_ <- 0 until N) {
      val v, w, m = sc.nextInt
      var flag = true
      for (_ <- 0 until m) {
        if (flag) {
          flag = false
          for (i <- 0 to W - w) {
            val x = W - i
            val y = W - i - w
            if (dp(x) < dp(y) + v) {
              dp(x) = dp(y) + v
              flag = true
            }
          }
        }
      }
    }
    println(dp(W))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 49376
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

// find_by_order(k) returns the iterator to the kth largest element (start from 0)
// order_of_key(k) returns the number of elements in the set which are strictly less than the value k

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define all(v)          v.begin(), v.end()
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mem(dp,x)       memset(dp,x,sizeof dp);
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int dx[] = { -1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int dx2[] = { -1 , -1 , -1, 0 , 0 , 1 , 1 , 1};
int dy2[] = { -1 , 0 , 1 , -1, 1 , -1, 0, 1};

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
// .Always initialize dp array
// 1, 1, 2, 5, 14, 42, 132, 429, 1430, CATALAN NUMBER
int32_t main()
{
	g_b();
	int n , w;
	cin >> n  >> w;
	int wt[n] , val[n];
	for (int i = 0; i < n; i++)
		cin >> wt[i] >> val[i];
	int sum = accumulate(val, val + n, 0LL);
	int dp[n + 1][sum + 1];
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= sum; j++)
			dp[i][j] = inf;
	}
	for (int i = 0; i <= n; i++) dp[i][0] = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= sum; j++)
		{
			if (val[i - 1] > j)  dp[i][j] = dp[i - 1][j];
			else dp[i][j] = min(wt[i - 1] + dp[i - 1][j - val[i - 1]] , dp[i - 1][j]);
		}
	}
	for (int j = 0; j <= sum; j++)
		cerr << dp[n][j] << " ";
	cerr << endl;
	for (int j = sum; j >= 1; j--)
	{
		if (dp[n][j] <= w) {
			cout << j;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 82496
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X;
  cin >> X;
  //vector<bool> prime(100005);
  int i=X;
  
  while(1==1){
    int chk=0;
    for(int j=sqrt(i); j>1; j--){
      if( (i%j) == 0 ){
        chk=1;break;
      }
    }
    if(chk==0)break;
    i++;
  }
  
  cout << i << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    unsigned long long int ans=0,t=0;
    cin>>s;
    if(s==""){cout<<0<<endl;return 0;}
    int flag=1;
    for( unsigned long long int i=0;i<s.size();i++)
        if(s[i]=='A'||s[i]=='G'||s[i]=='C'||s[i]=='T')
        {
            s[i]='*';
        }
        else flag = 0;
    if(flag==1)
    {cout<<s.size()<<endl;return 0;}
    for( unsigned long long int i=0;i<=s.size();i++)
    {
        if(s[i]=='*'){t++;}
        else
        {
            ans = max(t,ans);
            t=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
function Main(input) {
    input = input.trim()
  input = input.split("").map(Number);
  if(input[0]==input[1]||input[2]==input[1]||input[2]==input[3]) console.log("Bad");
  else console.log("Good")
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <cmath>
#include <stack>

using namespace std;
typedef long long ll;
vector<string> a;
vector<string> b;
int cost[101];
int name[101][101];
string name2[3001];
ll dist[3001];
vector<pair<int,int>> v[3001];

string rev(string x) {
	reverse(x.begin(), x.end());
	return x;
}
bool palin(string x) {
	int i = 0;
	int j = x.size() - 1;
	while (i <= j) {
		if (x[i] != x[j])return false;
		i += 1; j -= 1;
	}
	return true;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	int n; cin >> n;

	for (int i = 0; i < n; i++) {
		string s; cin >> s >> cost[i];
		cost[i + n] = cost[i];
		a.push_back(s);
	}

	for (int i = 0; i < n; i++) {
		a.push_back(rev(a[i]));
	}
	
	int start = 0;
	for (int i = 0; i < 2 * n; i++) {
		for (int j = 0; j < a[i].size(); j++) {
			name[i][j] = ++start;
			name2[name[i][j]] = a[i].substr(j);
		}
	}

	for (int i = 0; i < a.size(); i++) {
		for (int j = 0; j < a[i].size(); j++) {
			string s = a[i].substr(j);
			for (int k = 0; k < a.size(); k++) {
				if (i / n == k / n)continue;
				int w = min(s.size(), a[k].size());
				if (s.substr(0, w) != a[k].substr(0, w))continue;
				int u = 0;
				if (a[k].size() > w)u = name[k][w];
				else if (s.size() > w)u = name[i][j + w];
				v[name[i][j]].push_back({ u , cost[k] });
			}
		}
	}

	memset(dist, -1, sizeof(dist));
	priority_queue<pair<ll, int>> q;
	for (int i = 0; i < n; i++) {
		dist[name[i][0]] = cost[i];
		q.push({ -cost[i], name[i][0] });
	}

	ll ans = -1;
	while (!q.empty()) {
		ll z = -q.top().first;
		int x = q.top().second; q.pop();
		if (palin(name2[x]) || x == 0) {
			if (ans == -1 || ans > z) {
				ans = z;
			}
			continue;
		}	
		for (auto next : v[x]) {
			if (dist[next.first] == -1 || dist[next.first] > (ll)z + (ll)next.second) {
				dist[next.first] = (ll)z + (ll)next.second;
				q.push({ -dist[next.first], next.first });
			}
		}
	}
	cout << ans << '\n';


}

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

public class Main {
    public static void main(String[] args) throws Exception {
        Reader sc = new Reader();
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            char[] c = sc.next().toCharArray();
            int count = 0;
            int max = 0;
            for(int i=0 ; i<3 ; i++) {
                if(c[i] == 'R') {
                    count++;
                }
                else {
                    max = Math.max(max, count);
                    count = 0;
                }
            }
            max = Math.max(max, count);
            pw.println(max);
        }
        finally {
            pw.flush();
            pw.close();
        }
    }
    
    static class Reader {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while(!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch(IOException io) {
                    io.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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


Measured memory_bytes: 32760
use proconio::input;
use proconio::marker::{Bytes, Chars, Isize1, Usize1};

fn main() {
    input! {
        n: usize
    }

    let ans = {
        if n % 1000 == 0 {
            0
        } else {
            1000-n%1000
        }
    };

    println!("{}",ans)
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int mod = 1000000007;
const int inf = 1e9;
const ll INF = ll(1e18)+1;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

vector<ll> a;
ll n, k;

bool ok(ll x){
    ll tot = 0;
    rep(i,n){
        ll l = -1, r = n;
        if(a[i] < 0){
            while(r-l>1){
                ll mid = (l+r)/2;
                if(a[mid]*a[i]<=x) r = mid;
                else l = mid;
            }
            tot += n-r;
        }else{
            while(r-l>1){
                ll mid = (r+l)/2;
                if(a[mid]*a[i]<=x) l = mid;
                else r = mid;
            }
            tot += r;
        }
        if(a[i]*a[i]<=x) tot--;
    }
    tot /= 2;
    return tot < k;
}


int main(){
    cin >> n >> k;
    a.resize(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end());
    ll l = -INF;
    ll r = INF;
    while(r-l>1){
        ll m = (l+r)/2;
        if(ok(m)) l = m;
        else r = m;
    }
    cout << r << endl;
}


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

int main() {
  int n;cin>>n;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  ll ans=0,cnt=0;
  rep(i,n){
    if(cnt>a[i])ans+=cnt-a[i];
     cnt=max(cnt,a[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4764
from string import ascii_lowercase
from collections import defaultdict


N = int(input())
S = input().strip()
MOD = 10 ** 9 + 7


c = defaultdict(int)
for i in range(N):
    c[S[i]] += 1

ans = 1
for x in ascii_lowercase:
    ans *= c[x] + 1
    ans %= MOD
ans -= 1
ans %= MOD
print(ans)


Measured memory_bytes: 3832
#include<bits/stdc++.h>
 // #include <ext/pb_ds/tree_policy.hpp>
 // #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
  using namespace std;
   using namespace std::chrono;      
  // using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        1e18
 #define sm         -2e18
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;
#define MEM(x,val) memset(x,val,sizeof(x))

 // typedef tree<pii, null_type, less<pii>, rb_tree_tag,  
 //            tree_order_statistics_node_update>  odst; 


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

void solve()
{
  
  int n;
  cin >> n;
  int a[n];
  forf(i,0,n) cin >> a[i];
  int an = 0, pr=0;
  

  forf(i,0,n)
  {
    an+=(a[i]%M*pr%M)%M;
    pr+=a[i];
    pr%=M;
    an%=M;
  }

  cout<<an;

}

int32_t main()
{
  pr_init();
  fastio;
  auto start = high_resolution_clock::now(); 
  solve(); 
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

  return 0;
}

Measured memory_bytes: 5180
#include<iostream>
#include<cmath>
#include<vector>
#include<climits>
#define ll long long
#include<cstring>
using namespace std;



int main(){
    ll n,w,a,b;
    cin>>n>>w;
    vector<ll> dp(w+1,0);
    vector<pair<ll,ll> > v(n);
    for(ll i=0;i<n;i++) 
     cin>>v[i].first>>v[i].second;
    
    for(ll j=0;j<n;j++){
        for(ll i=w;i>=v[j].first;i--){
            dp[i]=max(dp[i],dp[i-v[j].first]+v[j].second);
        }
    }

cout<<dp[w]<<endl;

    return 0;
}

Measured memory_bytes: 3984
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

bool Check(string s) {
	if (s.length() == 1)
		return true;
	string sa, sb;
	sa = s.substr(0, s.length() / 2);
	sb = s.substr(s.length() / 2, s.length() / 2);
	if (sa == sb)
		return true;
	else
		return false;
}

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	string S;
	cin >> S;

	FOR(i, 1, S.length()) {
		string now = S.substr(0, S.length() - i * 2);
		bool ok = Check(now);
		if (ok) {
			cout << now.length() << endl;
			break;
		}
	}


	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n,m,k;
    cin>>n>>m>>k;
    long long a[n],b[m];
    for(long long i=0;i<n;i++){cin>>a[i];}
    for(long long i=0;i<m;i++){cin>>b[i];}
    long long count=0,ans=0;
    long long i=0,j=0;
    while(i<n && ans+a[i]<=k){
        ans+=a[i];
        i++;
    }
    count=i;
    while(j<m && i>=0){
        ans+=b[j];
        j++;
        while(i>=0 && ans>k){
            i--;ans-=a[i];
        }
        if(ans<=k && i+j>count){count=i+j;}
    }
    
    cout<<count;
}


Measured memory_bytes: 6764
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	while (S.size() < 15)S.push_back('o');
	int res = 0;
	for (int i = 0; i < 15; i++) {
		if (S[i] == 'o')res++;
	}
	if (res >= 8) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256