akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		int n = sc.nextInt();
		int xx[] = new int[n];
		int yy[] = new int[n];
		int hh[] = new int[n];
		
		for(int i =0 ; i < n ;i++){
			xx[i] = sc.nextInt();
			yy[i] = sc.nextInt();
			hh[i] = sc.nextInt();
		}
		
		for(int x = 0; x <= 100; x++){
			for(int y = 0 ; y <= 100;y++){
				
				int h = -1;
				for(int i = 0; i < n; i++){
					if(hh[i] == 0){
						continue;
					}
					int dist = Math.abs(x - xx[i]);
					dist += Math.abs(y-yy[i]);
					h = dist+ hh[i];
					break;
				}
				
				boolean flag = true;
				for(int i = 0; i < n; i++){
					int dist = Math.abs(x - xx[i]);
					dist += Math.abs(y-yy[i]);
					if(Math.max(0, h-dist) != hh[i]){
						flag= false;
						break;
					}
				}
				if(flag){
					System.out.println(x+" "+y+" "+h);
					return;
				}
			}
		}
		
	}
}


Measured memory_bytes: 25300
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define prin(a) cout<<(a)<<endl
using ll=int64_t;
using namespace std;

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a,ll b){
    return a * b / gcd(a, b);
}


int main(){
    int a,n ,k,ans=0;
    cin>>n>>k;
    rep(i,n){
        cin>>a;
        if(a>=k) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
long long n,x,m,fix[100005],i,cycle,s,ans,k;
vector<int>V;
 main(){
	cin>>n>>x>>m;
	while(!fix[x] && n){
		i++; ans+=x; n--;
		fix[x]=i; 
		V.push_back(x);
		x=x*x%m; 
	} 
	if(!n) cout<<ans;
	else {
	//	cout<<ans<<" "<<n<<endl;
		i=fix[x];
		 cycle=V.size()-i+1; 
		for(int k=i-1;k<V.size();k++){
			s+=V[k];
		}
		ans+=(n/cycle)*s;//cout<<ans<<endl;
		n%=cycle;
		for(k=i-1;k<=i-1+n-1;k++){
			ans+=V[k];
		}
		cout<<ans;
	}
	
}

Measured memory_bytes: 4672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    int[] inputArray;
    Set<String> set = new HashSet<>();
    int K;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[][] array = new int[N][N];

        for(int i=0; i<M; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();

            array[a-1][b-1] += 1;
            array[b-1][a-1] += 1;
        }

        for(int i=0; i<N; i++){
            int count = 0;
            for(int j=0; j<N; j++){
                count+=array[i][j];
            }
            System.out.println(count);
        }
    }

    void substring(String s, int num){
        for(int i=1; i<=num; i++){
            if(i > K){
                break;
            }
            for(int j=0; j<num; j++){
                if(j + i-1 < num){
//                    System.out.println(s.substring(j, j+i));
                    set.add(s.substring(j, j+i));
                } else {
                    break;
                }
            }
        }
    }

    void permutation(String s, String ans){
        if(s.length() <= 1){
            System.out.println(ans + s);
        } else {
            for(int i=0; i<s.length(); i++){
                permutation(s.substring(0, i) + s.substring(i + 1), ans + s.charAt(i));
            }
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;
ll dp[101][(1<<16)];

int main(){

  while(1){
    int n,L[103],m,man[103],c;
    cin >> n;
    if(n==0) break;

    for(int i=1;i<=n;i++){
      cin >> m >>L[i];
      c=0;
      for(int j=0;j<m;j++) {
	int a,b;
	cin>>a>>b;
	for(int k=a-6;k<b-6;k++) c =(c|(1<<(15-k)));
      }
      man[i] = c;
    }

    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++)
      for(int j=0;j<(1<<16);j++){
        dp[i][j]=max(dp[i-1][j],dp[i][j]);
	if((j|man[i])<(1<<16)&&(j&man[i])==0)dp[i][(j|man[i])] = max(dp[i-1][(j|man[i])],dp[i-1][j]+L[i]);
      }

    ll ans = 0;
    for(int j=0;j<(1<<16);j++) ans = max(ans,dp[n][j]);
    cout << ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 52876
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//conversion
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

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

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string ans = "No";
    for(int i = 0; i<=25; i++)
    {
        for(int j = 0; j<=15; j++)
        {
            if(i * 4 + j * 7 == n)ans = "Yes";
        }
    }
    PUTS(ans);
}

Measured memory_bytes: 256
"use strict";
(function(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  const N=input.shift();
  const A=(N%3===0),
        B=((input.reduce((a,c)=>a+c*c,0))===0);
  if((!A)&&(!B)){
    console.log("No");
    return;
  }
  if(B){
    console.log("Yes");
    return;
  }
  const values=[],
        counts=[0,0,0];
  for(let i=0;i<N;i++){
    let V=values.length;
    if(V>3){
      console.log("No");
      return;
    }
    for(let v=0;v<V;v++){
      if(input[i]===values[v]){
        counts[v]++;
        i++;
        v=-1;
        continue;
      }
    }
    if(i>=N)break;
    values.push(input[i]);
    if(counts[V]===0)counts[V]++;
  }
  if(values.length>3){
    console.log("No");
    return;
  }
  const C=((counts[0]===counts[1])&&(counts[1]===counts[2]));
  const E=((counts[2]===0)&&((counts[0]===(2*counts[1]))||(counts[1]===(2*counts[0]))));
  if((!C)&&(!E)){
    console.log("No");
    return;
  }
  const D=((values[0]^values[1]^values[2])===0);
  const F=(((values[0]^values[0]^values[1])===0)||((values[0]^values[1]^values[1])===0));
  if(C&&(!D)){
    console.log("No");
    return;
  }
  if(E&&(!F)){
    console.log("No");
    return;
  }
  console.log("Yes");
  return;
})(require("fs").readFileSync("/dev/stdin","utf8"));


Measured memory_bytes: 25804
#include<iostream>
using namespace std;
#define INF 1000000
int main(){
	int n,m,c[21];
	int dp[50001];
	cin >> n >> m;
	for(int i=0;i<m;i++){
		cin >> c[i];
	}
	for(int i=0;i<=n;i++){
		dp[i] = INF;
	}
	dp[0] = 0;
	for(int i=0;i<m;i++){
		for(int j=0;j<=n;j++){
			if(j+c[i] > n) break;
			if(dp[j]==INF) continue;
			dp[j+c[i]] = min(dp[j+c[i]],dp[j]+1);
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1356
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = 0;
        int N = sc.nextInt();
        int [] arr = new int[N];

        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }

        for(int i = 0; i < N; i++) {
            for(int j = i + 1; j < N; j++) {
                if(arr[i] != arr[j]) {
                    for(int k = j + 1; k < N; k++) {
                        if(arr[k] != arr[i] && arr[k] != arr[j]) {
                            if(isTriangle(arr[i], arr[j], arr[k])) {
                                count++;
                            }
                        }
                    }
                }
            }
        }




        System.out.println(count);
    }

    public static boolean isTriangle(int a, int b, int c) {
        if((a + b > c) && (a + c > b) && (c + b > a)) {
            return true;
        } else  {
            return false;
        }
    }
}


Measured memory_bytes: 36632
#include <iostream>

int main(void){
  int my_hp, enemy_hp;
  int my_attack, enemy_attack;
  std::cin >> my_hp >> my_attack >> enemy_hp >> enemy_attack;
  while(1){
  	enemy_hp -= my_attack;
    if(enemy_hp <= 0){
      std::cout << "Yes" << std::endl;
      break;
    }
    my_hp -= enemy_attack;
    if(my_hp <= 0){
      std::cout << "No" << std::endl;
      break;
    }
  }
 return 0; 
}


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

int main(){
  int N, a, c = 0;
  cin >> N;
  
  for (int i = 0; i < N; i++){
    cin >> a;
    if (a % 2 == 1){
      c += 1;
    }
  }
  
  if (c % 2 == 1){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
let input() = stdin.ReadLine()
let inputs() = input().Split()

let YN b = printfn "%s" (if b then "Yes" else "No")
let print x = printfn "%A" x
let printS (s: string) = printfn "%s" s


let N = int (input())
let S = input()

open System.Linq


S.Replace("ABC", "0").Count(fun c -> c = '0') |> print


Measured memory_bytes: 15964
#include <iostream>
using namespace std;
void ABC150(void);
void ABC151(void);
void ABC152(void);
void ABC153(void);
void ABC154(void);
void ABC155(void);
void ABC156(void);
void ABC157(void);
void ABC158(void);
void ABC159(void);

int main(void){
    ABC158();
}

void ABC158(){
    string s;
    cin>>s;
    int k=0;
    if(s[0]==s[1])++k;
    if(s[0]==s[2])++k;
    if(s[2]==s[1])++k;
    if(k==3)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;

int main() {
	int w, a, b, ans;
	cin >> w >> a >> b;
	if (abs(a - b) < w)ans = 0;
	else {
		if (a > b)ans = a - b - w;
		else ans = b - a - w;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main(){
	int x,y;
	cin >> x >> y;
	if(x%y==0){
		cout << "-1" << endl;
		return 0;
	}else{
		int a=2;
		while(1){
			if(a*x % y!= 0){
				cout << a*x << endl;
				return 0;
			}else{
				a++;
			}	
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>


#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long

using namespace std;

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b; //あまりが0ならそれが、最大公約数
}

int main()
{
    //    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    ll N,X,res;
    cin >> N >> X;

    vector <ll> x(N);

    ll tmp;

    REP(i,N)
    {
        cin >> tmp;
        x[i] = abs(X-tmp);
    }

    res = x[0];
    REP(i,N)
    {
        res = euclidean_gcd(res,x[i]);
    }
    cout << res <<endl;

    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<string> a(3);
  for(int i=0;i<3;i++){
    cin>>a[i];
  }
  string t_1="abcdefghijklmnopqrstuvwxyz";
  string t_2="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(int i=0;i<3;i++){
    for(int j=0;j<26;j++){
      if(a[i][0]==t_1[j]){
        cout<<t_2[j];
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxs=1e5+4;
ll n;
ll dp[maxs];
ll mincost(ll start,ll n,ll *a)
{
  if(start==(n-1))
    return 0;
  else
    if(dp[start]!=-1)
      return dp[start];
  else
  {
    ll ans=INT_MAX;
    if(start+1<n)
    ans=min(ans,abs(a[start+1]-a[start])+mincost(start+1,n,a));
    if(start+2<n)
    ans=min(ans,abs(a[start+2]-a[start])+mincost(start+2,n,a));
  
  dp[start]=ans;
  }
  return dp[start];
}

int main()
{
  cin>>n;
  ll i=0;
  ll a[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  memset(dp,-1,sizeof(dp));
  cout<<mincost(0,n,a)<<"\n";
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
pair<pair<int,int>,pair<int,int>> mx[1000000];
int ans[1000000];
int main() {
    //ios_base::sync_with_stdio(false);
    //cout<<setprecision(20);
    int m;
    cin>>m;
    int n=1;
    for(int i=0;i<m;i++){
        n*=2;
    }
    pair<int,int> a[1000000];
    for(int i=0;i<n;i++){ 
        cin>>a[i].first;
        a[i].second=i;    
    }
    mx[0].first=a[0];
    if(a[0].first>a[1].first){
        mx[1].first=a[0];
        mx[1].second=a[1];
    }
    else{
        mx[1].first=a[1];
        mx[1].second=a[0];
    }
    for(int i=2;i<n;i++){
        int d=1;
        mx[i].first=a[i];
        mx[i].second=make_pair(0,0);
        while(d<=i){
            int s=(i%(d*2)-i%d)/d;
            if(s==1){
                int k=i-d;
                if(mx[k].first.first>mx[i].first.first){
                    mx[i].second=mx[i].first;
                    mx[i].first=mx[k].first;
                }
                else if(mx[k].first.first>mx[i].second.first&&mx[k].first!=mx[i].first){
                    mx[i].second=mx[k].first;
                }
                if(mx[k].second.first>mx[i].second.first&&mx[k].second!=mx[i].first){
                    mx[i].second=mx[k].second;
                }
            }
            d*=2;
        }
        
    }
    int ans=0;
    for(int i=1;i<n;i++){
        int d=1;
        int d1=1;
        if(ans<mx[i].first.first+mx[i].second.first)ans=mx[i].first.first+mx[i].second.first;
        //cout<<mx[i].first<<" "<<mx[i].second<<" ";
        //int b[20];
        int j=i;
        if(j%2==1)j--;
        while(d<=j){
            int h =(i%(d*2)-i%d)/d;
            if(h==1){
                j-=d1;
                d1=d;
                if(mx[j].first.first+mx[j].second.first>ans)ans = mx[j].first.first+mx[j].second.first;
            }
            d*=2;
        }
        cout<<ans<<'\n';
    }
    return 0;
}

Measured memory_bytes: 17024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    REP(i, n) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    REP(i, n - 1) ans += p[i];
    ans += p[n - 1] / 2;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
int n, p[100001], c[100001];
int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; ++i){
        scanf("%d", &p[i]);
        c[p[i]] ++;
    }
    int t = 0, k = 0;
    for(int i = 1; i <= 100000; ++i){
        if(c[i] > 0){
            t += c[i] - 1;
            ++k;
        }
    }
    printf("%d\n", k - (t&1));
}
        


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

int n;
const double x = 380000.0;
double a, sum;
string b;
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a >> b;
        if (b == "JPY")
            sum += a;
        else
            sum += a * x;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3704
using System;

class CF2016QCA
{
	static public void Main(string[] args)
	{
		string s = Console.ReadLine();
		bool CF = false;

		for(int i=0; i<s.Length-1; i++)
		{
			if(s[i] == 'C')
			{
				for(int j=i+1; j<s.Length; j++)
				{
					if(s[j] == 'F')
					{
						CF = true;
					}
				}
			}
		}

		if(CF)
			Console.WriteLine("Yes");
		else
			Console.WriteLine("No");

	}
}


Measured memory_bytes: 11092
n = int(input())
a = list(map(int, input().split()))
b = [0] * (n + 1)
for i in range(n):
  b[i + 1] = a[i] - b[i]
x = b[-1] // 2
for i in range(n):
  if i & 1 == 1:
    b[i] -= x
  else:
    b[i] += x
  b[i] *= 2
print(" ".join(map(str, b[:-1])))

Measured memory_bytes: 20000
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end
def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n = gi

s = n.to_s
l = s.length
ar=["3","5","7"]
prev=['']
ans=[]
while l>0 do
  current = []
  prev.each do |i|
    ar.each do |j|
      current << (i+j)
    end
  end
  prev = current
  ans << current
  ans.flatten!
  l-=1
end
#debug 'ans',ans.to_s

ans.each do |s|
  break if s.to_i>n
  cnt+=1 if s["3"] && s["5"] && s["7"]
end
puts cnt

Measured memory_bytes: 4180
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
    ll N;
    cin>>N;
    string S;
    ll AC,WA,TLE,RE=0;
    AC=WA=TLE=RE=0;
    rep(i,N){
        cin>>S;
        if(S=="AC")AC++;
        else if(S=="WA")WA++;
        else if(S=="TLE")TLE++;
        else RE++;
    }
    cout<<"AC x "<<AC<<endl;
    cout<<"WA x "<<WA<<endl;
    cout<<"TLE x "<<TLE<<endl;
    cout<<"RE x "<<RE<<endl;
}

Measured memory_bytes: 3596
n,k=map(int,input().split())
list=[]
for i in range(n):
    a,b=map(int,input().split())
    list.append((a,b))
list.sort()

count=0
for i in range(n):
    count+=list[i][1]
    if count>=k: ans=list[i][0]; break


print(ans)

Measured memory_bytes: 16944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
  ll S;
  cin >> S;
  ll v = pow(10, 9);
  ll t = sqrt(S);
  if (t * t == S) {
    cout << "0 0 " << t << " " << "0 0 " << t << "\n";
    return 0;
  }
  t += 1;
  ll e = t * t - S;
  cout << "0 0 " << t << " " << e << " " << "1 " << t << "\n";
  return 0;
}

Measured memory_bytes: 384
n=int(input())
s=[list(map(int, input().split())) for i in range(n-1)]
for i in range(n):
    t=0
    for j in range(i,n-1):
        if t<=s[j][1]:
            t=s[j][0]+s[j][1]
        else:
            if t%s[j][2]==0:
                t+=s[j][0]
            else:
                t+=s[j][0]+(s[j][2]-t%s[j][2])
    print(t)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define fi first
#define se second
#define int long long
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int h, w, n;
int t[500 * 500];
int u[500 * 500][50];
int sp[500 * 500];

bool check(int m){
    set<int> st;
    rep(i, 0, n){
        int p = sp[i];
        rep(j, 0, 50){
            if(m >> j & 1) p = u[p][j];
        }
        if(st.count(p) > 0) return true;
        st.insert(p);
    } 
    return false;
}

signed main(){
    cin >> h >> w >> n;
    rep(i, 0, h){
        rep(j, 0, w){
            int y, x;
            cin >> y >> x;
            t[i * w + j] = y * w + x;
        }
    }
    rep(i, 0, n){
        int y, x;
        cin >> y >> x;
        sp[i] = y * w + x;
    }
    rep(i, 0, h * w){
        u[i][0] = t[i];
    }
    rep(k, 1, 50){
        rep(i, 0, h * w){
            u[i][k] = u[u[i][k - 1]][k - 1];
        }
    }
    int l = 0, r = ((int)1<<45), m;
    if(check(r) == false){
        cout << -1 << endl;
        return 0;
    }
    while(l < r){
        m = (l + r) / 2;
        if(check(m)) r = m;
        else l = m + 1;
    }
    cout << l << endl;
}

Measured memory_bytes: 116356
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	int n, ans = INF;
	cin >> n;
	vector<pair<int, int> > p(n);

	for (int i = 0; i < n; ++i) {
		cin >> p[i].first >> p[i].second;
	}

	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i == j) {
				continue;
			}

			int pp = p[i].first - p[j].first;
			int qq = p[i].second - p[j].second;
			int cnt = n;

			for (int k = 0; k < n; ++k) {
				if (find(p.begin(), p.end(), make_pair(p[k].first - pp, p[k].second - qq)) != p.end()) {
					cnt--;
				}
			}
			ans = min(ans, cnt);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

bool compare(int h1, int w1, int h2, int w2) {
  return ((h1*h1+w1*w1 < h2*h2+w2*w2) ||
	  (h1*h1+w1*w1 == h2*h2+w2*w2 && h1 < h2));
}

int main() {
  int h,w;
  while(true) {
    cin >> h >> w;
    if (h == 0 && w == 0) break;

    int ansh = 1000, answ = 1000;
    for (int th = 1; th <= 150; th++) {
      for (int tw = th+1; tw <= 150; tw++) {
	int dia = th*th+tw*tw;

	if (compare(h, w, th, tw) && compare(th, tw, ansh, answ)) {
	  ansh = th;
	  answ = tw;
	}
      }
    }

    std::cout << ansh << " " << answ << std::endl;
  }
}

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

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

  if(x==2){
    cout << x << endl;
    return 0;
  }

  

  for(int i=x;i<=100003;i++){
    int count =0;

    for(int j=2;j<x;j++){
      if(i%j==0){
        count++;
         
      }
  }
  if(count ==0){
    cout << i << endl;
    return 0;
     }

  }
  


  
}

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

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

    int M, D;
    cin >> M >> D;

    int count = 0;

    for (int m = 1; m <= M; m++) {
        for (int d = 1; d <= D; d++) {
            int d_1 = d % 10;
            int d_10 = (d - d_1) / 10;

            if (((d_1 >= 2) && (d_10 >= 2)) && (d_1 * d_10 == m)) {
                count++;
            }
        }
    }

    cout << count << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)

{
 int a,b,d,r;
 double f;
 scanf("%d",&a);
 scanf("%d",&b);

 d=a/b;
 r=a%b;
 f=(double)a/b;
 
 printf("%d %d %lf\n",d,r,f);
 
 return 0;
}


 

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
const int N = 55;
int n, i, a[N];
double ans = 0;
int main(){
	cin>>n;
	for(i = 1; i <= n; i++) cin>>a[i];
	sort(a+1, a+n+1);
	ans = a[1];
	for(i = 2; i <= n; i++)
		ans = (ans + (double)a[i]) / 2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  long n;
  scanf("%ld", &n);
	long a[n+1];
  for (long i = 0; i < n+1; i++) {
    scanf("%ld", &a[i]);
  }
  long b[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &b[i]);
  }

  long defeated = 0;
  long remain = a[0];
  for (long i = 0; i < n; i++) {
    if (remain >= b[i]) {
      defeated += b[i];
      remain = a[i+1];
    } else {
      defeated += remain;
      b[i] -= remain;
      remain = a[i+1];
      if (remain >= b[i]) {
        defeated += b[i];
        remain -= b[i];
      } else {
        defeated += remain;
        remain = 0;
      }
    }
  }

  printf("%ld\n", defeated);

  return 0;
}

Measured memory_bytes: 1664
#include <cstdio>
#include <algorithm>

int main()
{
  long long n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
  if ((b - a) & 1)
  {
    long long ans2 = (a - 1) + 1 + (b - a) / 2;
    long long ans3 = (n - b) + 1 + (b - a) / 2;
    printf("%lld\n", std::min(ans2, ans3));
  }
  else
  {
    printf("%lld\n", (b - a) / 2);
  }
  return 0;
}


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int n,k;
  string s;
  cin>>n>>k;
  cin>>s;
  s[k-1]=s[k-1]-'A'+'a';
  cout<<s<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define yorn(f) puts((f)?"Yes":"No")
ll a,b,c,d;
//ld ;
//string s;
 
int main() {
  cin >> a >> b >> c >> d;
  ll tHit = (c-1)/b + 1;
  ll aHit = (a-1)/d + 1;
  //cout << tHit << " " << aHit << endl;
  yorn(tHit <= aHit);
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;



int main(void) {
  ll N;
  cin >> N;
  ll x[111];
  ll i;
  
  for(i=0; i<N; i++) {
    cin >> x[i];
  }
  sort(x, x+N);
  
  
  ll ans=INF;
  
  for(ll p=x[0]; p<=x[N-1]; p++) {
    ll t=0;
    for(i=0; i<N; i++) {
      t+=(x[i]-p)*(x[i]-p);
    }
    chmin(ans, t);
  }
  
  pt(ans);
}








Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int N, K, ans;
  cin >> N >> K;
  vector<int> a(N);
  rep(i, N){
    cin >> a[i];
  }
  if ((N-1)%(K-1) == 0) ans = (N-1)/(K-1);
  else ans = (N-1)/(K-1) + 1;
  
  cout << ans << endl;

}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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 ll MOD = 1e9+7;
const ll INF = 1e8;

ll H, W;

ll A[100][100];
ll B[100][100];

#define NUM 2*80*160

int DP[81][81][NUM+100];
ll base;

int main(){
    cin >> H >> W;
    REP(i,H){
        REP(j,W){
            cin >> A[i][j];
        }
    }
    REP(i,H){
        REP(j,W){
            cin >> B[i][j];
        }
    }

    base = 80 * (H+W);

    REP(i,H)
        REP(j,W)
            REP(k,2*80*(H+W))
                DP[i][j][k] = INF;

    REP(k,2*80*(H+W))
        DP[H-1][W-1][k] = abs(k-base);

    for(int i = H-1; i >= 0; i--){
        for(int j = W-1; j >= 0; j--){
            ll a = A[i][j];
            ll b = B[i][j];
            ll d = abs(a - b);
            for(int k = 0; k <= 2*(H+W)*80; k++){
                if(i > 0){
                    chmin(DP[i-1][j][k + d], DP[i][j][k]);
                    if(k-d >= 0)
                        chmin(DP[i-1][j][k - d], DP[i][j][k]);
                }
                if(j > 0){
                    chmin(DP[i][j-1][k + d], DP[i][j][k]);
                    if(k-d >= 0)
                        chmin(DP[i][j-1][k - d], DP[i][j][k]);
                }
            }
        }
    }

    int ans = INF;
    ll d = A[0][0] - B[0][0];
    chmin(ans, DP[0][0][base + d]);
    chmin(ans, DP[0][0][base - d]);

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


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

using ll = long long;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 1;

ll f(int x) {
    ll ans = 0;
    while (__builtin_popcount(x)) {
        x = x % __builtin_popcount(x);
        ans++;
    }
    return ans;
}

long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int bits = 0;
    for (char &c : s) {
        bits += (c == '1');
    }
    ll tmp1 = 0, tmp2 = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (bits != 1) tmp1 = (tmp1 + (binpow(2, n - i - 1, bits - 1) * (s[i] == '1'))) % (bits - 1);
        tmp2 = (tmp2 + (binpow(2, n - i - 1, bits + 1) * (s[i] == '1'))) % (bits + 1);
    }
    int org1 = tmp1;
    int org2 = tmp2;
    for (int i = 0; i < n; i++) {
        if (s[i] == '1') {
            if (bits != 1) {
                tmp1 = (org1 - binpow(2, n - i - 1, bits - 1) + 2 *(bits - 1)) % (bits - 1);
                cout << 1 + f(tmp1) << endl;
            } else {
                cout << 0 << endl;
            }
        } else {
            tmp2 = (org2 + binpow(2, n - i - 1, bits + 1)) % (bits + 1);
            cout << 1 + f(tmp2) << endl;
        }
    }
}

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

const int ORIGIN = 8000;
int x, y;
string s, ans = "Yes";
vector<int> d;
bitset<16001> xbit, ybit;

int main() {
    cin >> s >> x >> y;
    d.push_back(0);
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'F') d.back()++;
        else d.push_back(0);
    }
    xbit.set(d.front()+ORIGIN);
    ybit.set(ORIGIN);
    for (int i = 1; i < d.size(); i++) {
        if(i%2 == 0) {
            xbit = (xbit << d[i]) | (xbit >> d[i]);
        } else {
            ybit = (ybit << d[i]) | (ybit >> d[i]);
        }
    }
 
    if (!xbit[x+ORIGIN] || !ybit[y+ORIGIN]) ans = "No";
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef pair<int,int> pii;

signed main(void) {
  int i,j;
  int n;
  cin>>n;
  vector<pii> p(2*n);
  rep(i,n){
    cin>>p[i].first;
    p[i].second=1;
  }
  rep(i,n){
    cin>>p[i+n].first;
    p[i+n].second=-1;
  }
  sort(all(p));
  ll ans=1;
  int a=0,b=0;
  rep(i,2*n){
    if(p[i].second==1){//pc
      if(a==0)
	b++;
      else
	ans=(ans*a)%MOD,a--; 
    }else{
      if(b==0)
	a++;
      else 
	ans=(ans*b)%MOD,b--;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main() {

    string a, b;
    int ans = 0;
    cin >> a >> b;
    int l = (int) a.length();
    for(int i = 0; i < l; ++i){
        if(a[i] != b[i]){
            ans++;
        }
    }
    cout << ans;

}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define len(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>


signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n; cin >> n;
  set<string> a;
  rep(i,n){
    string s; cin >> s;
    a.insert(s);
  }
  cout << a.size() << endl;
  ret;
}


Measured memory_bytes: 19152
from math import sqrt

N, D = map(int, input().split())
X = [tuple(map(int, input().split())) for i in range(N)]

ans = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        sq_d = 0
        for k in range(D):
            sq_d += (X[i][k] - X[j][k]) ** 2
        d = sqrt(sq_d)
        if d - int(d) == 0:
            ans += 1
print(ans)


Measured memory_bytes: 38256
d = input().split(" ")
a = int(d[0])
b = int(d[1])
ans = -1
for i in range(1, 12501):
	aa = int(i * 0.08)
	bb = int(i * 0.1)
	if a == aa and b == bb and ans == -1:
		ans = i
		break
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin >> n >> m;
  int a[n],b[n],c[m],d[m];

  rep(i,n) cin >> a[i] >> b[i];
  rep(i,m) cin >> c[i] >> d[i];

  rep(i,n){
    int index =-1;
    int dist = INT_MAX;
    rep(j,m){
      int tmp = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if(dist > tmp){
	dist = tmp;
	index = j+1;
      }
    }
    cout << index << endl;
  }
  
  
  return 0;
    

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    int a,z;
    cin >> s;
    for(int i = 0;i < s.size();i++){
        if(s[i] == 'A'){
            a = i;
            break;
        }
    }

    for(int i = s.size() - 1;i >= 0;i--){
        if(s[i] == 'Z'){
            z = i;
            break;
        }
    }
    cout << (z - a + 1) << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
char a[1001][1001]; 
int wi[8]={1,1,0,-1,-1,-1,0,1};
int wj[8]={0,-1,-1,-1,0,1,1,1},n=0,m=0;
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(a[i][j]=='#')
            {
                cout<<'#';
            }
            else
            {
                int num=0;
                for(int m=0;m<8;m++)
                {
                    if(a[i][j]!='.')
                    {
                        continue;
                    }
                    if(a[i+wi[m]][j+wj[m]]=='#')
                    {
                        num++;
                    }
                }
                cout<<num;
            }
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll N, K, T, W, H, M, C;

const int MAX = 5100000;
const ll MOD = 1e9 + 7;

const double PI=3.14159265358979323846;


long long fac[MAX], finv[MAX], inv[MAX];

vector<double> cx, cy, c;
 ll MM = 1e12;

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

std::vector<int> Eratosthenes(int n ){
    std::vector<bool> is_prime( n + 1 );
    for( int i = 0; i <= n; i++ ) is_prime[ i ] = true;
    std::vector<int> P;
    for( int i = 2; i <= n; i++ ){
        if( is_prime[ i ] ){
            for( int j = 2 * i; j <= n; j += i ){
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
    return P;
}

ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}



int main(){
    cin >> N >> K;
    ll ans = 0;
    for(ll i = K; i <= N+1; ++i){
        ans += (5 *MOD - i * (i-1)/2)%MOD;
        //cout << ans << " ";
        ans += ( 5 *MOD - (N - i +1)*(N-i)/2) %MOD;
        //cout << ans << " ";
        ans +=(N * (N+1) /2) %MOD;
        ans += MOD + 1;
        ans %= MOD;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cctype>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void){
  int i,j,l;
  int an,bn;
  int a[5001],b[5001];
  int ans=0;
  scanf("%d %d",&an,&bn);
  for(i=0;i<an;i++) scanf("%d",&a[i]);
  for(i=0;i<bn;i++) scanf("%d",&b[i]);

  for(i=0;i<bn;i++){
    for(j=i,l=0;j<bn && l<an;l++){
      if(a[l]==b[j]) j++;
    }
    ans=max(ans,j-i);
  }
  printf("%d\n",ans);
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

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

    int Q;
    std::cin >> Q;

    for(int i=0;i<Q;++i){
        int A, B;
        std::cin >> A >> B;

        ll X = 1ll * A * B;
        
        // if minimizing, lb satisfies lb > ub
        // if maximizing, lb satisfies lb < ub
        int64_t lb = 1000000001ll, ub = 0ll;

        while(std::abs(ub - lb) > 1){
            int64_t mid = (lb + ub) / 2;

            if(X - 1 < mid * (mid + 1)){
                lb = mid;
            }else{
                ub = mid;
            }
        }
        
        ll res = (lb - 1) + (X - 1) / lb;
        auto f = [&](ll a){return (X - 1) / a;};
        
        // std::cout << (A > 1 ? f(A - 1) : -1) << ", " << f(A) << ", " << f(A + 1) << std::endl;
        // std::cout << (B > 1 ? f(B - 1) : -1) << ", " << f(B) << ", " << f(B + 1) << std::endl; 
        
        if(A == B){

        }else{
            --res;
        }
        
        // if((A > 1 && f(A - 1) == f(A) && B > f(lb)) ||
        //    (B > 1 && f(A + 1) == f(A) && B > f(lb)) ||
        //    (B > 1 && f(B - 1) == f(B) && A > f(lb)) ||
        //    (A > 1 && f(B + 1) == f(B) && A > f(lb))){
        //     // std::cout << "ok" << std::endl;
        // }else{
        //     --res;
        // }
        
        std::cout << res << std::endl;
    }
}


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

using namespace std;

int main() {
	int R,G,B,N;
	cin >> R >> G >> B >> N;

	if(G<B){
		int sw = B;
		B = G;
		G = sw;
	}
	if(R<G){
		int sw = G;
		G = R;
		R =sw;
	}
	if(G<B){
		int sw = B;
		B = G;
		G = sw;
	}
	int ans = 0;

	int a = N/R;
	for(int i = a; i > -1 ;i--){
		int M = N-R*i;
		for(int j = M/G; j > -1 ;j--){
			int L = M-G*j;
			if(L%B==0) ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;

int main() {
    string S;
    cin >> S;
    if (S.at(2) == S.at(3) && S.at(4) == S.at(5)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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


using namespace std;

int main() {

	int n;
	cin >> n;

	int maxa = -1000000;
	int mina = 1000000;
	long long suma = 0;

	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		maxa = max(maxa, a);
		mina = min(mina, a);
		suma += a;
	}
	cout << mina << " " << maxa << " " << suma << endl;
}


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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if((a+b) == c) {
        cout << "Yes" << endl;
    } else if((a+c) == b) {
        cout << "Yes" << endl;
    } else if((b+c) == a) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>

using namespace std;

int main() {
    int order[5], mod[5], min_mod;
    min_mod = 10;
    int ans = 0;
    for (int i = 0; i < 5; i++) {
        cin >> order[i];
        mod[i] = order[i] % 10;
        if (mod[i] != 0 && mod[i] < min_mod) {
            min_mod = mod[i];
        }
        ans += ceil(float(order[i]) / 10) * 10;
    }

    if (min_mod == 10) {
        cout << ans << endl;
    } else {
        cout << ans - (10 - min_mod) << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#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 drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
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};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    map<char, int> mp;
    for(auto c : s) mp[c]++;
    for(char c = 'a'; c <= 'z'; c++) if(mp[c] == 0) {
        cout << c << endl;
        return 0;
    }
    cout << "None" << endl;
}

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

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		int n = nextInt();
		int[] a = new int[3 * n];
		for (int i = 0; i < 3 * n; i++) {
			a[i] = nextInt();
		}
		
		Arrays.sort(a);
		
		long sum = 0;
		for (int i = 0; i < n; i++) {
			sum += a[3 * n - 2 - 2 * i];
		}
		
		out.println(sum);
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

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

int main(){
    ll n,k,a,b,c;
    cin>>n>>k>>a>>b>>c;
    string s;
    cin>>s;
    ll ans = 0;
    for(ll i=0;i<n;i++){
        if(i>=k){
            if(s[i]==s[i-k]){
                s[i]='a';
                continue;
            }
        }
        if(s[i]=='r') ans += c;
        if(s[i]=='p') ans += b;
        if(s[i]=='s') ans += a;
    }
    
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 512