akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int main(){
    ll n, r;
    cin >> n >> r;

    if(n >= 10)cout << r;
    else cout << r +100*(10-n);

}


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

int main() {
  int p, q, r;
  cin >> p >> q >> r;
  int a, b, c;
  a  =p + q;
  b = q+r;
  c = p +r;
  cout << min(a,min(b,c)) << endl;
}


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

n,k=map(int,input().split())

segment=[]
for i in range(k):
    l,r=map(int,input().split())
    segment.append((l,r))

INF=998244353
dp=[0]*n
dp[0]=1
sum=[0]*(n+1)
sum[0]=0
sum[1]=1

for i in range(1,n):
    temp=0
    for j in range(k):
        l=i-segment[j][1]
        r=i-segment[j][0]
        if r<0:
            continue
        if l<0:
            l=0
        temp=(temp+(sum[r+1]-sum[l]))%INF
    dp[i]=temp
    sum[i+1]=(sum[i]+temp)%INF

print(dp[n-1])


Measured memory_bytes: 71340
#include<iostream>
#include<vector>

signed main(){

  int n,m;
  int64_t k;
  std::cin>>n>>m>>k;
  std::vector<int64_t> a(n),b(m);
  for(auto& ai:a)std::cin>>ai;
  for(auto& bi:b)std::cin>>bi;

  std::vector<int64_t> c (std::rbegin(b),std::rend(b));
  std::copy(std::begin(a),std::end(a),std::back_inserter(c));
  
  int l=m,r=m;
  int64_t sum = 0;
  while(l>0&&sum+c[l-1]<=k)sum+=c[--l];

  int ans = r-l;

  for(;l<=m;++l){
    while(r<m+n&&sum+c[r]<=k)sum+=c[r++];
    ans = std::max(ans,r-l);
    sum -= c[l];
  }

  std::cout<< ans <<std::endl;

}

Measured memory_bytes: 12396
#include <iostream>
#include <vector>

using namespace std;

int main(){
  int N; cin>>N;
  vector<int> C(N-1),S(N-1),F(N-1);
  for(int i=0;i<N-1;i++) cin>>C[i]>>S[i]>>F[i];

  vector<int> ans(N,0);

  for(int i=0;i<N-1;i++){
    int t=0; 
    for(int j=i;j<N-1;j++){
      if(t<S[j]){
        t=S[j];
      }
      else{
        if(t%F[j]!=0){
          t=((t+F[j])/F[j])*F[j];
        }
      }
      t+=C[j];
    }
    ans[i]=t;
  }

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

  return 0;
}


Measured memory_bytes: 256
import math


def is_prime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


n = int(input())
for i in range(n, 10**10):
    if is_prime(i):
        print(i)
        exit()

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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  set<string> s;
  int rainbowCount = 0;
  rep(i, n) {
    int v = a[i];
    switch (v) {
      case 1 ... 399:
        s.insert("gray");
        break;
      case 400 ... 799:
        s.insert("brown");
        break;
      case 800 ... 1199:
        s.insert("green");
        break;
      case 1200 ... 1599:
        s.insert("sky");
        break;
      case 1600 ... 1999:
        s.insert("blue");
        break;
      case 2000 ... 2399:
        s.insert("yellow");
        break;
      case 2400 ... 2799:
        s.insert("orange");
        break;
      case 2800 ... 3199:
        s.insert("red");
        break;
      default:
        rainbowCount++;
    }
  }
  cout << max(1, (int) s.size()) << " " << (int) s.size() + rainbowCount << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;

//桁DP
//dp[i][j] -> あまりj のカウント数
//2桁のときの疑問は解消->足しても0
int main() {

    string S;
    cin >> S;

    ll dp[105000][13];

    REP(i,105000)
    {
        REP(j,13)
        {
            dp[i][j] = 0;
        }
    }



    //S.size()-1 z = 1;
    //S.size()-2 z = 2;
    dp[0][0] = 1;
    //各文字
    for(ll i = 0; i < S.size(); ++i)
    {
        ll z = i;
        //?か
        if(S[i] == '?')
        {
            for(ll k = 0; k <= 9; ++k)
            {
                for(ll j = 0; j < 13; ++j)
                {
                    dp[z+1][(j*10 + k) % 13] += dp[z][j];
                    dp[z+1][(j*10 + k) % 13] %= MOD;
                }
            }
        }
        else
        {
            ll k = S[i] - '0';
            for(ll j = 0; j < 13; ++j)
            {
                //
                dp[z+1][(j * 10 + k) % 13] += dp[z][j];
                dp[z+1][(j * 10 + k) % 13] %= MOD;
            }  
        }
    }

    ll res = dp[S.size()][5];

    cout << res << endl;
    return 0;
}

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

int main(void){
    int n = 0; 
    long int l[87];

    l[0] = 2;
    l[1] = 1;

    scanf("%d", &n);

    for(int i = 2; i <= n; i++){
        l[i] = l[i-1] + l[i-2];
    }
    printf("%ld\n", l[n]);

    return 0;

} 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> a(n);
    for(int i = 0 ;i < n; i++) {
        cin >> a[i];
    }
    
    vector<int> b(n);
    for(int i = 0; i < n; i++) {
        cin >> b[i];
    }
    
    vector<int> c(n - 1);
    for(int i = 0; i < n - 1; i++) {
        cin >> c[i];
    }
    
    int ans = 0;
    for(int i = 0; i < n; i++) {
        ans += b[a[i] - 1];
        if(i == n-1) {
            break;
        }
        if(a[i] == a[i + 1] - 1) {
            ans += c[a[i] - 1];
        }
    }
    
    cout << ans << endl;
    
    return 0;
}



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

int main() {
  int n, x;
  cin >> n >> x;
  cout << (500*n>=x? "Yes" : "No") << endl;
}


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

#define MAX_INDEX 51 
#define MAX_SUM 2505 
#define ll long long

// This dp array is used to store our values 
// so that we don't have to calculate same 
// values again and again 
ll dp[MAX_INDEX][MAX_SUM][MAX_INDEX]; 

ll waysutil(ll index, ll sum, ll count, 
			vector<ll>& arr, ll K) 
{ 
	// Base cases 
	// Index can't be less than 0 
	if (index < 0) 
		return 0; 

	if (index == 0) { 

		// No element is picked hence 
		// average cannot be calculated 
		if (count == 0) 
			return 0; 
		ll remainder = sum % count; 

		// If remainder is non zero, we cannot 
		// divide the sum by count i.e. the average 
		// will not be an integer 
		if (remainder != 0) 
			return 0; 
		ll average = sum / count; 

		// If we find an average return 1 
		if (average == K) 
			return 1; 
	} 

	// If we have already calculated this function 
	// simply return it instead of calculating it again 
	if (dp[index][sum][count] != -1) 
		return dp[index][sum][count]; 

	// If we don't pick the current element 
	// simple recur for index -1 
	ll dontpick = waysutil(index - 1, 
							sum, count, arr, K); 

	// If we pick the current element add it to 
	// our current sum and increment count by 1 
	ll pick = waysutil(index - 1, 
						sum + arr[index], 
						count + 1, arr, K); 
	ll total = pick + dontpick; 

	// Store the value for the current function 
	dp[index][sum][count] = total; 
	return total; 
} 

// Function to return the number of ways 
ll ways(ll N, ll K, ll* arr) 
{ 
	vector<ll> Arr; 

	// Push -1 at the beginning to 
	// make it 1-based indexing 
	Arr.push_back(-1); 
	for (ll i = 0; i < N; ++i) { 
		Arr.push_back(arr[i]); 
	} 

	// Initialize dp array by -1 
	memset(dp, -1, sizeof dp); 

	// Call recursive function 
	// waysutil to calculate total ways 
	ll answer = waysutil(N, 0, 0, Arr, K); 
	return answer; 
} 

// Driver code 
int main() 
{ 
  ll K,N,arr[100];
  cin>>N>>K;
    for(ll i=0;i<N;i++)
      cin>>arr[i]; 
	cout << ways(N, K, arr); 

	return 0; 
} 


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

int main() {
    int a,b;
    cin>>a>>b;
    for(int i=1;i<=1000000;i++){
        int p = (i * 8)/100;
        int q = (i * 10)/100;
        if((p == a && q == b) || (p == b && q == a)){
            cout<<i<<"\n";
            return 0;
        }
    }
    cout<<"-1\n";
    return 0;
}


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

int main()
{
	string s;
	cin>>s;
	if(s=="Sunny")
		cout<<"Cloudy"<<endl;
	else if(s=="Cloudy")
		cout<<"Rainy"<<endl;
	else //if(s=="Rainy")
		cout<<"Sunny"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
   int a,b;
   int main()
   {
   while(scanf("%d%d",&a,&b)!=EOF)
      {
      b=b*2;	
      if(a>b)
	  printf("%d\n",a-b);
	  else
	  printf("0\n");	
      }	
   } 

Measured memory_bytes: 128
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    while (sc.hasNext()) {
        val a = sc.nextLine().split(",").map { it.toDouble() }
        val dist = a.slice(0..9).sum()/(a[10]+a[11])*a[10]
        var d = 0.0
        for (i in 1..10) {
            d += a[i-1]
            if (d+1e-9 >= dist) {
                println(i)
                break
            }
        }
    }
}


Measured memory_bytes: 33240
A = input()
B = input()
C = input()

turn = 'a'
win = ''
while win == '':
  if turn == 'a':
    if len(A) == 0:
      win = 'A'
    else:
      turn = A[0]
      A = A[1:]
  elif turn == 'b':
    if len(B) == 0:
      win = 'B'
    else:
      turn = B[0]
      B = B[1:]
  elif turn == 'c':
    
    if len(C) == 0:
      win = 'C'
    else:
      turn = C[0]
      C = C[1:]
print(win)

Measured memory_bytes: 3064
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
# UnionFind
class UnionFind():
    def __init__(self, n):
        self.nodes=[-1] * n  # nodes[x]: 負なら、絶対値が木の要素数

    def get_root(self, x):
        # nodes[x]が負ならxが根
        if self.nodes[x] < 0:
            return x
        # 根に直接つなぎ直しつつ、親を再帰的に探す
        else:
            self.nodes[x]=self.get_root(self.nodes[x])
            return self.nodes[x]

    def unite(self, x, y):
        root_x=self.get_root(x)
        root_y=self.get_root(y)
        # 根が同じなら変わらない
        # if root_x == root_y:
        # pass
        if root_x != root_y:
            # 大きい木の方につないだほうが計算量が減る
            if self.nodes[root_x] < self.nodes[root_y]:
                big_root=root_x
                small_root=root_y
            else:
                small_root=root_x
                big_root=root_y
            self.nodes[big_root] += self.nodes[small_root]
            self.nodes[small_root]=big_root

def main():
    N=I()
    A=LI()
    timing = list(set(A))
    timing.sort(reverse=True)
    appear = defaultdict(list)
    for i,a in enumerate(A):
        appear[a].append(i)
    
    exist=set()

    ans = 0
    num = 0
    for t in timing:
        if t <= 0:
            break
        for land in appear[t]:
            exist.add(land)
            # if land == 0:
            #     if land+1 in exist:
            #         pass
            #     else:
            #         num += 1
            # elif land == N-1:
            #     if land-1 in exist:
            #         pass
            #     else:
            #         num+=1
            # else:
            left = land-1 in exist
            right = land+1 in exist
            if left and right:
                num-=1
            elif left or right:
                pass
            else:
                num+=1
        # print(t, num)
        ans = max(ans, num)

    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 36020
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;
char c[301][301];

int calc(string s, string t){
	int n = s.size();
	
	vector<vi> diff(2*n+2, vi(n+2));
	REP(k, n)REP(i, n) diff[n + k][i+1] = s[i] == t[k+i];
	REP(k, n)REP(i, n) diff[n - k][i+1] = s[k+i] == t[i];
	REP(k, 2 * n + 1) REP(i, n) diff[k][i+1] += diff[k][i];
	vector<vi> dp(n + 2, vi(n + 2, MOD));
	dp[0][0] = 0;
	REP(i, n + 1) REP(j, n + 1){
		int sum = 0;
		sum += diff[n + j-i][min(n - i, n - j)];
	//	for(int k=0;k+i<n&&k+j<n;k++){
	//		sum += s[k+i] == t[k+j];
	//	}
		chmin(dp[i][j+1], dp[i][j] + sum);
		chmin(dp[i+1][j], dp[i][j] + sum);
//		cout << i << ", " << j << ": " << dp[i][j] << endl;
	}
	return dp[n][n];
}

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	vector<string> s(m, string(n, ' '));
	REP(i, n)REP(j, m) cin >> s[j][i];
	int ans = 0;
	REP(i, m-1) ans += calc(s[i], s[i+1]);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1620
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int a; cin>>a;
    cout << a+a*a+a*a*a << '\n';
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll modpow(ll a,ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll nCr(ll n, ll r, ll mod) {
  r = min(n-r, r);
  if (r == 0) return 1;
  ll ans = 1;
  FOR(i, n-r+1, n+1) ans = ans * i % mod;
  ll a = 1;
  FOR(i, 1, r+1) a = a * i % mod;
  ans = ans * modpow(a, mod-2, mod) % mod;
  return ans;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;

  ll ans = (modpow(2, n, mod) - 1 - nCr(n, a, mod) - nCr(n, b, mod) + mod * 3) % mod;
  cout << ans << endl;

  
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

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

const int MAX = 1e5 + 5;
const ll INF = 1ll << 60;
const int MOD = 1e9 + 7;

int main(){
    int N, X, D;
    cin >> N >> X >> D;

    if (!D) {
        if (!X) cout << 1 << endl;
        else cout << N + 1 << endl;
        return 0;
    }

    map<int, vector<P>> mp;
    rep(k, N + 1) {
        ll L = (ll)k * (k - 1) / 2;
        ll R = (ll)N * (N - 1) / 2 - (ll)(N - k) * (N - k - 1) / 2;

        int rem = (ll)k * X % D;
        if (rem < 0) rem += D;
        mp[rem].emplace_back((ll)k * X / D + L, (ll)k * X / D + R);
    }

    ll ans = 0;
    for (auto i : mp) {
        auto v = i.second;
        
        vector<P> event;
        for (auto j : v) {
            event.emplace_back(j.first, 1);
            event.emplace_back(j.second + 1, -1);
        }

        sort(event.begin(), event.end());

        ll cnt = 0, pre = -INF;
        for (auto j : event) {
            ll t = j.first, e = j.second;
            if (cnt) ans += t - pre;
            cnt += e;
            pre = t;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a[3]={},tmp,cnt,ans1=0,ans2=0;
  string s;
  while(cin >> s){
    tmp=-1,cnt=0;
    for(int i=0;i<s.size();i++){
      if(s[i]==','){
        a[cnt]=atoi(s.substr(tmp+1,i-tmp-1).c_str());
        tmp=i;
        cnt++;
      }
    }
    a[cnt]=atoi(s.substr(tmp+1,s.size()-tmp-1).c_str());
    if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2]){
      ans1++;
    }
    if(a[0]==a[1]){
      ans2++;
    }
  }
  cout << ans1 << endl << ans2 << endl;
  return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n, 0);
  vector<int> b(n, 0);
  vector<int> c(n, 0);
  for(int i = 0; i < n; i++)
     cin >> a[i] >> b[i] >> c[i];
         
  int dp[n][3];
  // n = 1
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  for(int i = 1; i < n; i++) {
  	dp[i][0] = a[i] + max(dp[i-1][1], dp[i-1][2]);
    dp[i][1] = b[i] + max(dp[i-1][0], dp[i-1][2]);
    dp[i][2] = c[i] + max(dp[i-1][0], dp[i-1][1]);
  }
  int max_ = max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));
  cout << max_;
  return 0;
}

Measured memory_bytes: 2560
[A,B,N] = list(map(int,input().split()))

W = N//B
dammy=[]
x=N
dammy.append((A*x)//B - A * int(x/B))
x=(B * W)-1
dammy.append((A*x)//B - A * int(x/B))


print(max(dammy))

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

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x, v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector<vi> vii;
const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f;
const ll MOD = 1e9+7;
const int N = 1e5+5;

ll dp[1005][1005];
char a[1005][1005];

int main(){
    int h, w;

    cin >> h >> w;

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin >> a[i][j];
        }
    }
    dp[1][1] = 1;
    for(int i=2;i<1005;i++){
        if(a[i][1]=='.') dp[i][1] = dp[i-1][1];
        if(a[1][i]=='.') dp[1][i] = dp[1][i-1];
    }
    for(int i=2;i<=h;i++){
        for(int j=2;j<=w;j++){
            if(a[i][j]=='.') dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
        }
    }

    cout << dp[h][w] << "\n";

    return 0;
}


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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

int cnt = 0;


void solve()
{
	string s; cin >> s;
	int a = 0, b = 0, c = 0, d = 0;
	for(int i = 0; i < s.length(); ++i)
	{
		if (s[i] == 'N') a++;
		if (s[i] == 'W') b++;
		if (s[i] == 'S') c++;
		if (s[i] == 'E') d++;
	}
	if (b != 0 && d != 0)
	{
		if (c != 0 && a != 0) cout << "Yes";
		else if (c == 0 && a == 0) cout << "Yes";
		else cout << "No";
	}
	else if (a != 0 && c != 0)
	{
		if (b != 0 && d != 0)
			cout << "Yes";
		else if (b == 0 && d == 0)
			cout << "Yes";
		else
			cout << "No";
	}
	else cout << "No" ;
}

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


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n[]=new int[5];
		String s="Yay!";

		for(int i=0;i<=4;i++){



		n[i]= sc.nextInt();// nこの希望
		}
		int k=sc.nextInt();
		for(int i=0;i<=4;i++){
for(int j=0;j<=4;j++){
	if(Math.abs(n[i]-n[j])>k){
		s=":(";
	}
}
		}
System.out.println(s);

	}}

Measured memory_bytes: 23252
import bisect
for e in iter(input,'0'):
 n=int(e)
 c=[sorted(int(input())for _ in[0]*n)]
 c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
 t=f=0
 while 1:
  x=bisect.bisect(c[t],f)
  if not c[t]:break
  f=c[t].pop(x)if x<len(c[t])else 0
  t^=1
 for i in[1,0]:print(len(c[i]))


Measured memory_bytes: 5656
#include<iostream>
#include<vector>

using namespace std;

int main(){
  int s,i,ans=0;
  vector <int> v,w;
  
  for(i=0;i<1000001;i++){
    v.push_back(0);
    w.push_back(0);}
  
  cin>>s;
  v[0]=s;
  w[s]+=1;
  for(i=1;i<1000001;i++){
    if(v[i-1]%2==0){
      v[i]=v[i-1]/2;
      w[v[i]]+=1;
      if(w[v[i]]==2){
        ans=i+1;
        break;}
      }
    else{
      v[i]=3*v[i-1]+1;
       w[v[i]]+=1;
      if(w[v[i]]==2){
        ans=i+1;
        break;}
      }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 10464
s=list(input())
a=[0]*(len(s)+1)
if s[0]=='<':
    a[0]=0
    l=0
    while s[l]=='<':
        a[l+1]=a[l]+1
        l+=1
        if l>len(s)-1:
          break
if s[len(s)-1]=='>':
    a[len(s)]=0
    m=len(s)-1
    while s[m]=='>':
        a[m]=a[m+1]+1
        m-=1
        if m<0:
          break
for i in range(len(s)-1):
    if s[i]=='>' and s[i+1]=='<':
        a[i+1]=0
        k=i
        t=i+1
        while s[k]=='>':
            a[k]=a[k+1]+1
            k-=1
            if k<0 or k>len(s)-1:
                break
        while s[t]=='<':
            a[t+1]=a[t]+1
            t+=1
            if t<0 or t>len(s)-1:
                break
for i in range(len(s)-1):
    if s[i]=='<' and s[i+1]=='>':
        a[i+1]=max(a[i],a[i+2])+1
print(sum(a))

Measured memory_bytes: 27088
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>
#include <limits>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
#define fst first
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//ユークリッドの互除法
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

int main()
{
	int N, R;
	cin >> N >> R;
	int sum = 100 * (10 - N);
	if (N >= 10) {
		cout << R << endl;
	}
	else {
		cout << sum + R << endl;
	}
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#aoj b
import re
from collections import defaultdict

def check(i):#メモ化再帰
    if d[i] > 0:
        return d[i]
    d[i] = 1#チェック状態
    for y in range(p[i][0],p[i][1]+1):
        for x in range(p[i][2],p[i][3]+1):
            if s[y][x] == ".":#長方形内部に空の部分が存在
                d[i] = 3 #SUSPICIOUS
                return d[i]
            elif s[y][x] != i:#長方形内部に他の物質が存在
                if d[s[y][x]] == 1:#その物質がチェック状態
                    d[i] = 3 #SUSPICIOUS(循環参照 テストケース4)
                    return d[i]
                c = check(s[y][x])#そいつの状態確認の再帰
                if c == 3:
                    d[i] == 3
                    return d[i]
    d[i] = 2#SAFE
    return 2

N = int(input())
for _ in range(N):
    h,w = map(int,input().split())
    s = [list(input()) for _ in range(h)]
    p = defaultdict(list)
    #p[0]:上端,p[1]:下端,p[2]:左端,p[3]:右端
    #y座標の追加は横方向で見る(上端は上から、下端は下から)
    for y in range(h):#上端
        for x in range(w):
            if s[y][x] != '.' and len(p[s[y][x]]) < 1:
                p[s[y][x]].append(y)
    for y in range(h)[::-1]:#下端
        for x in range(w):
            if s[y][x] != '.' and len(p[s[y][x]]) < 2:
                p[s[y][x]].append(y)
    #x座標の追加は縦方向で見る(左端は左から、右端は右から)
    for x in range(w):#左端
        for y in range(h):
            if s[y][x] != '.' and len(p[s[y][x]]) < 3:
                p[s[y][x]].append(x)
    for x in range(w)[::-1]:#右端
        for y in range(h):
            if s[y][x] != '.' and len(p[s[y][x]]) < 4:
                p[s[y][x]].append(x)
    d = defaultdict(lambda : 0)#メモ化再帰用dict
    for i in p.keys():
        if check(i) == 3:
            print('SUSPICIOUS')
            break
    else:
        print('SAFE')



Measured memory_bytes: 6584
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
string s;
int n;
int nx[26][2010], nx2[26][2010];
ll dp[2010][2010];
int main()
{
    cin>>s;
    n=s.size();
    for(int i=0; i<=n; i++){
        for(int j=0; j<26; j++){
            nx2[j][i+1]=nx2[j][i];
        }
        if(i>0) nx2[s[i-1]-'a'][i+1]=i;
    }
    for(int j=0; j<26; j++) nx[j][n+1]=n+1;
    for(int i=n; i>=0; i--){
        for(int j=0; j<26; j++) nx[j][i]=nx[j][i+1];
        if(i<n) nx[s[i]-'a'][i]=i+1;
    }
    dp[0][n+1]=1;
    ll ans=MOD-1;
    for(int i=0; i<=n; i++){
        for(int j=n+1; j>=i+1; j--){
            (ans+=dp[i][j])%=MOD;
            for(int k=0; k<26; k++){
                if(nx[k][i]<j) (ans+=dp[i][j])%=MOD;
                if(nx[k][i]<nx2[k][j]) (dp[nx[k][i]][nx2[k][j]]+=dp[i][j])%=MOD;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 26200
import java.util.Scanner;

public class Main {
    static int n;
    static int[] A;

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        n = s.nextInt();
        A = new int [n];
        for (int i = 0; i < n; i++) {
            A[i] = s.nextInt();
        }

        int pivot = partition(A, 0, n - 1);

        for (int i = 0; i < n; i++) {
            if (i != 0) {
                System.out.print(" ");
            }
            if (i == pivot) {
                System.out.print("[" + A[i] + "]");
            } else {
                System.out.print(A[i]);
            }
        }
        
        System.out.println();
    }

    static int partition(int[] A, int p, int r) {
        int i = p, j = p;
        int x = A[r];

        while (j < r) {
            if (A[j] <= x) {
                int y = A[i];
                A[i] = A[j];
                A[j] = y;
                i++;
                j++;
            } else {
                j++;
            }
        }
        int y = A[r];
        A[r] = A[i];
        A[i] = y;
        return i;
    }
}



Measured memory_bytes: 67568
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
    int n;
    cin >> n;
    int arr[n];
    for (int z=0;z<n;z++){
        cin >> arr[z];
    }
    double ans=0;
    for(int a=0;a<n;a++){
        ans = ans + 1/double(arr[a]);
    }
    cout << fixed << setprecision(10) << 1/ans << endl;
 }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int K;


long long kansuu(vector<long long> vec){
	int num[100];
	for(int i=0;i<100;i++){
		num[i]=0;
	}
	for(int i=0;i<vec.size();i++){
		long long t = vec[i];
		for(int k=0;k<1000;k++){
			if(t%2==1)num[k]++;
			t/=2;
			if(t==0)break;
		}
	}
	long long te = 0;
	for(int i=0;i<100;i++){
		if(num[99-i]>=K){
			te=1;
			for(int j=0;j<99-i;j++){
				te*=2;
			}
			break;
		}
	}
	if(te==0)return 0;
	vector<long long> temp;
	for(int i=0;i<vec.size();i++){
		if((vec[i]/te)%2==1){
			temp.push_back(vec[i]-te);
		}
	}
	return te+kansuu(temp);
}


int main(){
	int N;
	cin>>N;
	cin>>K;
	vector<long long> a(N+1);
	a[0]=0;
	for(int i=1;i<=N;i++){
		int b;
		cin>>b;
		a[i]=a[i-1]+b;
	}
	vector<long long> memo;

	for(int i=0;i<N+1;i++){
		for(int j=i+1;j<N+1;j++){
			memo.push_back(a[j]-a[i]);
		}
	}
	cout<<kansuu(memo)<<endl;
	return 0;
}


Measured memory_bytes: 10608
#include <bits/stdc++.h>
#define ll long long
#define MAX_N 8
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;


int M[8][8];
int n,e;

int dfs_visit(int u,int color2[MAX_N]){
    bool all_visited = true;
    for(int i =0;i<n;i++){
        if(color2[i] == WHITE) {
            all_visited = false;
        }
    }
    if(all_visited) return 1;
    int res = 0;

    for(int v = 0; v < n; v++){
        if(M[u][v] == 0)continue;
        if(color2[v] == WHITE){
            color2[v] = GRAY;
            res += dfs_visit(v,color2);
            color2[v] = WHITE;
        }
    }
    color2[u] = BLACK;
    return res;
}

int dfs(){
    int color[MAX_N];
    for(int i=0; i < n ; i++) color[i] = WHITE;
    int u = 0;
    color[u] = GRAY;

    int ans = dfs_visit(u, color);
    return ans;
}

int main(){
    cin>>n>>e;
    for(int i =0;i<n;i++){
        for(int j=0;j<n;j++)M[i][j] = 0;
    }
    for(int i=0;i<e;i++){
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        M[u][v] =M[v][u]= 1;
    }
    cout<< dfs() <<endl;
}


Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3","unroll-loops")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define ins insert

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int n;

main(){
    int p=1,q=1;
    cin>>n;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        int k=max((p+a-1)/a,(q+b-1)/b);
        p=a*k;
        q=b*k;
    }
    dump(p+q);
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	int ans=0;
	for(int i=1;i<=n;i++){
		int cnt=0;
		int j=i;
		cnt+=j%10;
		while(j/10>0){
			j/=10;
			cnt+=j%10;
		}
		if(a<=cnt && cnt<=b) ans+=i;
	}
	cout << ans << endl;
}


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

using namespace std;
typedef unsigned long long uint64;


int main() {
	int n;
	cin >> n;
	vector<uint64>a(n);

	for (int i = 0; i < n; i++) {
		scanf("%lld",&a[i]);
		if (a[i] == 0) {
			cout << "0" << endl;
			return 0;
		}
	}
	
	uint64 prod = 1;
	for (int i = 0; i < n; i++) {
		if(a[i] <= (1000000000000000000 / prod)){
			prod *= a[i]; 
		}
		else { 
			cout << "-1" << endl;
			return 0;
		}
	}

	cout << prod << endl;

	return 0; 
}


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



long long mod = 1000000007;



int main(){
	//freopen("i.txt","r",stdin);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	long long a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a != c){
		cout << 1;
	}
	else cout << 0;
	
}


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

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


std::vector<std::vector<int>> edge; // 枝 (逆向き辺)
std::vector<int> Dist;
std::vector<int> In; // 入ってくる枝の数
std::vector<int> Par; // 親



int main(void){
    // 入力
    int n, m; scanf("%d%d", &n, &m);
    edge.resize(n);
    In.resize(n, 0);
    REP(i, n+m-1){
        int a, b; scanf("%d%d", &a, &b); a--; b--;
        edge[b].push_back(a);
        In[a]++;
    }
    
    // Topological Sort - ic
    std::queue<int> Q;
    Dist.resize(n); 
    Par.resize(n, -1);

    REP(i, n) if(In[i] == 0){ Q.push(i); Dist[i] = 0;}
    while(not Q.empty()){
        int v = Q.front(); Q.pop();
        for(int nv : edge[v]){
            In[nv]--;
            if(In[nv] == 0){
                Dist[nv] = Dist[v] + 1;
                Q.push(nv);
            }
        }
    }

    // 親の取得
    REP(i, n){
        int par = -1, depth = INT32_MAX;
        for(int v : edge[i]){
            if(depth > Dist[v]){ // 根からもっとも近い部分
                depth = Dist[v];
                par = v;
            }
        }
        // 出力
        printf("%d\n", par+1);
    }

    return 0;
}

Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
#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 all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    int Alice = 0;
    int Bob = 0;
    sort(all(vec));
    for(int i = N - 1; i >= 0; i -= 2){
        Alice += vec[i];
    }
    for(int i = N - 2; i >= 0; i -= 2){
        Bob += vec[i];
    }
    cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main () {
	int N;
	scanf("%d", &N);
	
	for ( int i = 0; i >= 0; i++) {
		if ( i * 1000 >= N) {
			printf("%d", i * 1000 - N);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

int main() {
    int n ;
    string s ;
    cin >> n >> s ;
    vector<int> a(n) ;
    rep(i, n){
        if(s[i] == 'R') a[i] = 0 ;
        if(s[i] == 'G') a[i] = 1 ;
        if(s[i] == 'B') a[i] = 2 ; 
    }
    vector<ll> cnt(3) ;
    rep(i,n) cnt[a[i]]++ ;
    ll ans = 1 ;
    rep(i, 3) ans *= cnt[i] ;
    rep(j, n){
        rep(i, j){
            int k = j + (j- i) ;
            if(k < n){
                if(a[i] == a[j]) continue ;
                if(a[i] == a[k]) continue ;
                if(a[k] == a[j]) continue ;
                ans-- ;
            }
        }
    }
    cout << ans << endl ;
}  

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int X[202020],Y[202020];
pair<int,int> P[202020];

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};
UF<202020> uf;

int ret[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>X[i]>>Y[i];
		P[i]={X[i],i};
	}
	
	sort(P,P+N);
	
	vector<pair<int,int>> V;
	FOR(i,N) {
		x=P[i].second;
		
		if(V.empty()) {
			V.push_back({Y[x],x});
		}
		else {
			if(V.back().first<Y[x]) {
				while(V.size()>=2&&V[V.size()-2].first<Y[x]) {
					auto a=V.back();
					V.pop_back();
					auto b=V.back();
					V.pop_back();
					uf(a.second,b.second);
					V.push_back(a);
					
				}
				uf(V.back().second,x);
			}
			else {
				V.push_back({Y[x],x});
			}
		}
	}
	
	FOR(i,N) cout<<uf.count(i)<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 10052
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;

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

        int X = sc.nextInt();
        int Y = sc.nextInt();
        int Z = sc.nextInt();
        int K = sc.nextInt();
        long[] A = readArray(sc, X);
        long[] B = readArray(sc, Y);
        long[] C = readArray(sc, Z);

        System.out.println(solve(A, B, C, K));

        sc.close();
    }

    static long[] readArray(Scanner sc, int size) {
        long[] result = new long[size];
        for (int i = 0; i < size; ++i) {
            result[i] = sc.nextLong();
        }

        return result;
    }

    static String solve(long[] A, long[] B, long[] C, int K) {
        long[] sortedA = reversedSort(A);
        long[] sortedB = reversedSort(B);
        long[] sortedC = reversedSort(C);

        List<Long> result = new ArrayList<>();
        Element initial = new Element(0, 0, 0);
        Set<Element> seen = new HashSet<>();
        seen.add(initial);
        PriorityQueue<Element> pq = new PriorityQueue<>(
                (e1, e2) -> -Long.compare(sortedA[e1.indexA] + sortedB[e1.indexB] + sortedC[e1.indexC],
                        sortedA[e2.indexA] + sortedB[e2.indexB] + sortedC[e2.indexC]));
        pq.offer(initial);

        while (result.size() != K) {
            Element head = pq.poll();
            result.add(sortedA[head.indexA] + sortedB[head.indexB] + sortedC[head.indexC]);

            for (Element candidate : new Element[] { new Element(head.indexA + 1, head.indexB, head.indexC),
                    new Element(head.indexA, head.indexB + 1, head.indexC),
                    new Element(head.indexA, head.indexB, head.indexC + 1) }) {
                if (candidate.indexA != A.length && candidate.indexB != B.length && candidate.indexC != C.length
                        && !seen.contains(candidate)) {
                    seen.add(candidate);
                    pq.offer(candidate);
                }
            }
        }

        return result.stream().map(String::valueOf).collect(Collectors.joining("\n"));
    }

    static long[] reversedSort(long[] values) {
        return Arrays.stream(values).boxed().sorted(Collections.reverseOrder()).mapToLong(x -> x).toArray();
    }
}

class Element {
    int indexA;
    int indexB;
    int indexC;

    Element(int indexA, int indexB, int indexC) {
        this.indexA = indexA;
        this.indexB = indexB;
        this.indexC = indexC;
    }

    @Override
    public int hashCode() {
        return Objects.hash(indexA, indexB, indexC);
    }

    @Override
    public boolean equals(Object obj) {
        Element other = (Element) obj;

        return indexA == other.indexA && indexB == other.indexB && indexC == other.indexC;
    }
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  string T;
  for (int i = 0; i < N/2; i++) {
    T += S.at(i);
  }
  if(S==T+T){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

typedef long long ll;

int main(){
    string S;
    cin >> S;
    
    size_t n = S.length();
    
    for(int i=0; i<n; i+=2){
        S.pop_back(); S.pop_back();
        if(S.substr(0,S.length()/2) == S.substr(S.length()/2,S.length()/2)){
            cout << S.length() << endl;
            break;
        }
    }
}


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

int main() {
    using namespace std;
    unsigned long K;
    cin >> K;
    long X, Y;
    cin >> X >> Y;
    if(~K & (X ^ Y) & 1)return 0 & puts("-1");
    X = X + Y;
    Y = X - 2 * Y;
    bool x = X < 0, y = Y < 0;
    if(x)X *= -1;
    if(y)Y *= -1;
    vector<pair<long, long>> ans;
    if(X < K && Y < K){
        if(X & 1){
            ans.emplace_back(X - K + 1, K);
            ans.emplace_back(X - K, 0);
        }else{
            ans.emplace_back(X - K, K);
        }
        ans.emplace_back(X, Y);
    }else{
        unsigned long time = (max(X, Y) - 1) / K + 1;
        if(K & (time ^ X) & 1)++time;
        unsigned long remX = time * K - X, remY = time * K - Y;
        long a{0}, b{0};
        for(unsigned long i = 0; i < time; ++i){
            auto t = min(remX, 2 * K), k = 0UL;
            if(!t)k = min(remY, 2 * K);
            a += K - t;
            b += K - k;
            remX -= t;
            remY -= k;
            ans.emplace_back(a, b);
        }
    }
    cout << ans.size() << endl;
    for(const auto& i : ans){
        auto a = i.first * (x ? -1 : 1);
        auto b = i.second * (y ? -1 : 1);
        cout << (a + b) / 2 << " " << (a - b) / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 5484