akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  std::vector<int> a;
  
  for(auto i=0; i<9; ++i) {
    int tmp;
    std::cin >> tmp;
    a.push_back(tmp);
  }
  
  int n;
  std::cin >> n;
  
  for(auto i=0; i<n; ++i) {
    int b;
    std::cin >> b;
    for(auto& v : a) {
      if(b == v)
        v = -1;
    }
  }
  
  auto checked = [](auto v){ return v == -1; };
  
  if([&](){
  for(auto i=0; i<3; ++i) {
    if(std::all_of(a.begin() + i*3, a.begin()+ (i+1)* 3, checked))
       return true;
    if(checked(a[0+i]) && checked(a[3+i]) && checked(a[6+i])) 
       return true;
  }
  
  if(checked(a[0]) && checked(a[4]) && checked(a[8])) 
     return true;
  if(checked(a[2]) && checked(a[4]) && checked(a[6]))
     return true;
    
    	return false;
     }())
     {
       std::cout << "Yes\n";
     }
     else
     std::cout << "No\n";
}

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

int main() {
  int N;
  cin >> N;
  vector<int> mo(N);
  for (int i=0; i<N; i++) {
  cin >> mo.at(i);
  }

  sort (mo.begin(), mo.end());
  
  int ans = 1;
  for (int i=1; i<N; i++) {
    if (mo.at(i-1)!=mo.at(i)) ans++;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int x;
    cin >> x;
    bool flag = false;
    while(!flag){
        flag = true;
        for (int i = 2; i < x-1; i++)
        {
            if(x%i==0){
                flag = false;
            }
        }
        x++;
        // printf("%d\n", x);
    }
    cout << --x << endl;
    // printf("%d\n", N);
    return 0;
}

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

using namespace std;
int main()
{
    string s;
    cin>>s;
    bool good=1;
    for(int i=0;i<4;i++)
    {
        if(s[i]==s[i+1])
        {
            good=0;
            break;
        }
    }
    if(good)
    {
        cout<<"Good"<<endl;
    }
    else
    {
        cout<<"Bad"<<endl;
    }
    return 0;
}


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

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

using namespace std;

int main(){
	string s; cin>>s;
	int n=s.length();

	bool ok=true;
	if(s[0]=='0' || s[n-1]=='1') ok=false;
	rep(i,n/2) if(s[i]!=s[n-i-2]) ok=false;
	if(!ok){
		cout<<-1<<endl;
		return 0;
	}

	int u=1;
	rep(i,n-1){
		int v=i+2;
		cout<<u<<" "<<v<<endl;
		if(s[i]=='1') u=v;
	}

	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  while (true) {
    int m, f, r;
    cin >> m >> f >> r;
    if (m == -1 && f == -1 && r == -1) {
      break;
    }
    if (m == -1 || f == -1) {
      cout << "F" << endl;
      continue;
    }
    if (m + f >= 80) {
      cout << "A" << endl;
      continue;
    }
    if (m + f >= 65) {
      cout << "B" << endl;
      continue;
    }
    if (m + f >= 50) {
      cout << "C" << endl;
      continue;
    }
    if (m + f >= 30) {
      if (r >= 50) {
        cout << "C" << endl;
      } else {
        cout << "D" << endl;
      }
      continue;
    }
    cout << "F" << endl;
  }
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define M 1000000007
#define pi ld(acos(-1.0))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(ll i=a;i<=(ll)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define ii pair<int,int>
#define bye(x) {cout<<x;return 0;}
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    cs
    int n,t=0,ans=0;cin>>n;
    vector<int> v(n);
    for(auto &i:v) {cin>>i;t=max(t,i);ans+=i;}
    cout<<ans-t/2;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(void){
    // Your code here!
    int N = 0;
    int M = 0;
    
    cin >> N;
    cin >> M;
    int A[N];
    int total = 0;
    
    for(int i=0; i < M; i++) {
        cin >> A[i];
        total = total + A[i];
    }
    
    if ( N - total <= -1) {
        cout << -1;
    } else {
        cout << (N-total);
    }

}


Measured memory_bytes: 3204
A,B,C,D,E,F = map(int,input().split())
f = F//100

ans = [0,0]
per = -1
#水の量を100g単位ずつ全探索
for w in range(1,f+1):
    #そのような水の取り方があるか確認
    wt = 0
    for b in range(0,w+1,B):
        if (w-b)%A == 0:
            wt = 1
            break
    if wt == 0:
        continue

    water = w*100
    sugar = min(w*E,F-water)
    if ans[0] == 0:
        ans[0] = water
    st = 0
    #砂糖として考えられる量を大きい順に0gまでに全探索
    for s in range(sugar,0,-1):
        st = 0
        for d in range(0,s+1,D):
            if (s-d)%C == 0:
                st = 1
                break
        if st == 1:
            break
    if st == 1 and s+water <= F and s/(s+water) > per:
        ans = [s+water,s]
        per = s/(s+water)

print(' '.join(map(str,ans)))


Measured memory_bytes: 3064
import sys

import numba as nb
import numpy as np

input = sys.stdin.readline


@nb.njit("void(i8,i8,i8,i8[:,:],i8,i8[:,:],i8[:])", cache=True)
def dfs(H, W, D, A, Q, LR, ans):
    position = [(-1, -1)] * (H * W + 1)
    for h in range(H):
        for w in range(W):
            position[A[h][w]] = (h, w)

    mp = np.zeros(shape=(H * W + 1), dtype=np.int64)

    for i in range(1, H * W + 1 - D):
        h, w = position[i]
        y, x = position[i + D]
        mp[i + D] = abs(x - w) + abs(y - h)

    for d in range(1, D + 1):
        mp[d::D] = np.cumsum(mp[d::D])

    for i in range(Q):
        l, r = LR[i]
        ans[i] = mp[r] - mp[l]


def main():
    H, W, D = map(int, input().split())
    A = np.zeros(shape=(H, W), dtype=np.int64)
    for i in range(H):
        A[i] = tuple(map(int, input().split()))
    Q = int(input())
    LR = np.zeros(shape=(Q, 2), dtype=np.int64)
    for i in range(Q):
        LR[i] = tuple(map(int, input().split()))

    ans = np.zeros(shape=Q, dtype=np.int64)
    dfs(H, W, D, A, Q, LR, ans)

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 117312
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll N;
	cin >> N;

	vector < tuple<ll, ll, ll> > A;
	vector < tuple<ll, ll, ll> > B;

	for (ll ii = 0; ii < N; ++ii){
		ll a, b;
		cin >> a >> b;
		tuple<ll, ll, ll> aa = make_tuple(a + b, a, ii);
		tuple<ll, ll, ll> bb = make_tuple(b + a, b, ii);
		A.push_back(aa);
		B.push_back(bb);
	}

	sort(A.rbegin(), A.rend());
	sort(B.rbegin(), B.rend());

	// for (int ii = 0; ii < N; ++ii){
	// 	printf("a[%i] %lld\n", ii, get<0>(A[ii]));
	// }
	// for (int ii = 0; ii < N; ++ii){
	// 	printf("b[%i] %lld\n", ii, get<0>(B[ii]));
	// }

	ll acnt = 0;
	ll bcnt = 0;
	ll asum = 0;
	ll bsum = 0;
	vector <bool> ok(N, true);
	for (int ii = 0; ii < N; ++ii){
		if (ii % 2 == 0){	//たかはしのターン
			while(true) {
				ll idx = get<2>(A[acnt]);
				if (ok[idx]){
					break;
				} else {
					acnt++;
				}
			}
			asum += get<1>(A[acnt]);
			ll idx = get<2>(A[acnt]);
			ok[idx] = false;
			acnt++;
			// printf("asum %lld, idx %lld\n",asum, idx);
		} else {	//あおきのターン
			while(true) {
				ll idx = get<2>(B[bcnt]);
				if (ok[idx]){
					break;
				} else {
					bcnt++;
				}
			}
			bsum += get<1>(B[bcnt]);
			ll idx = get<2>(B[bcnt]);
			ok[idx] = false;
			bcnt++;
			// printf("bsum %lld, idx %lld\n",bsum, idx);
		}
	}

	cout << asum - bsum << "\n";		

	return 0;
}


Measured memory_bytes: 6700
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int INF = 9999999999;
using ll = long long;

int main(){
  int N;
  cin>>N;
  int a[N];
  int suum = 0;
  int ans = 0;
  for(int i = 0;i<N;i++){
    cin>>a[i];
    suum += a[i];
  }
  for(int i = 0;i<N;i++){
    ans += a[i]*(suum-a[i]);
  }
  cout << ans/2 << endl;
  return 0;
}

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

using namespace std;

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

	int total = 0;
	for (int i = 0; i < N; i++) {
		int l, r;
		cin >> l >> r;
		total += (r - l + 1);
	}

	cout << total << endl;
}






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

int main() {
  int n;cin>>n;
  // int a[n];

  int sum = 0;
  rep(i, n) {
    int a;cin>>a;
    if((i+1) % 2 != 0 && a % 2 != 0) {
      sum ++;
    }
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std;

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];

    sort(a, a + 3);
    int sh_1 = a[2] - a[0];
    int sh_2 = a[2] - a[1];

    int ans;
    if ((sh_1 - sh_2)%2) {
        ans = (sh_1 + sh_2 + 3)/2;
    } else {
        ans = (sh_1 + sh_2)/2;
    }

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

Measured memory_bytes: 256
from math import sqrt
def f(x):
    lst  = [i for i in range(x + 1)]
    flag = [1 for i in range(x + 1)]
    flag[0] = flag[1] = 0
    for i in lst:
        if flag[i] == 0:
            continue
        else:
            for j in range(i*2, x + 1, i):
                flag[j] = 0
    return flag.count(1)

a = []
while True:
    try:
        a.append(int(input()))
    except EOFError:
        break

for x in a:
    print(f(x))



Measured memory_bytes: 58196
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b

signed main(){
	string s; cin>>s;
	string t; cin>>t;
	int n=s.size();
	bool ans=false;
	rep(i,0,n){
		string k;
		rep(j,0,n){
			k.push_back(s[(i+j)%n]);
		}
		if(t==k)ans=true;
	}
	cout<<(ans ? "Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 3584
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
 
public class Main {
 
    static class edge{
        int from, to;
        long cost;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
//        String[] str = br.readLine().split(" ");
 
        ArrayList<edge>[] es  = new ArrayList[n];
        for(int i=0; i<n; i++) es[i] = (new ArrayList<>());
 
        for (int i=0; i<n-1; i++) {
            String[] str = br.readLine().split(" ");
            edge ed_f = new edge();
            int a = Integer.parseInt(str[0]) - 1;
            int b = Integer.parseInt(str[1]) - 1;
            long c = Long.parseLong(str[2]);
            ed_f.from = a;
            ed_f.to = b;
            ed_f.cost = c;
            es[a].add(ed_f);
 
            edge ed_b = new edge();
            ed_b.from = b;
            ed_b.to = a;
            ed_b.cost = c;
            es[b].add(ed_b);
 
        }
        String[] str = br.readLine().split(" ");
        int q = Integer.parseInt(str[0]);
        int k = Integer.parseInt(str[1]);
 
        PriorityQueue<long[]> dist = new PriorityQueue<>((long[] le, long[] ri) -> (int)(le[0] - ri[0]));
        long[] vertex = new long[2];
        vertex[0] = 0;
        vertex[1] = k-1;
        dist.add(vertex);
 
        long[] len = new long[n];
        Arrays.fill(len, Long.MAX_VALUE);
        len[k-1] = 0;
 
        while(!dist.isEmpty()){
            vertex = dist.poll();
 
            long u = vertex[1];
            for (Object ed: es[(int)u]){
                if(len[((edge) ed).from] + ((edge) ed).cost < len[((edge) ed).to]) {
                    len[((edge) ed).to] = len[((edge) ed).from] + ((edge) ed).cost;
                    long[] p = new long[2];
                    p[0] = len[((edge) ed).to];
                    p[1] = ((edge) ed).to;
                    dist.add(p);
                }
            }
        }
 
        for(int i=0; i<q;i ++){
            long length = 0;
            str = br.readLine().split(" ");
            int st = Integer.parseInt(str[0]);
            int ed = Integer.parseInt(str[1]);
            length += len[st-1] + len[ed-1];
            System.out.println(length);
        }
    }
}

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

int main() {
    int n;
    cin >> n;
    unordered_set<int> nums;
    rep(i, n){
        int a;
        cin >> a;
        if(nums.count(a)){
            cout << "NO\n";
            return 0;
        } else {
            nums.insert(a);
        }
    }
    cout << "YES\n";
}

Measured memory_bytes: 8520
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; 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 ALL(v) (v).begin(),(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 (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=998244353;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
ll pow_mod(ll n,ll k,ll m){
  ll res=1;
  for(;k>0;k>>=1){
    if(k&1){
      res=(res*n)%m;
    }
    n=(n*n)%m;  
  }
  return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin >> n;
    vector<ll> d(n),c(n);
    REP(i,n){
        cin >> d[i];
        c[d[i]]++;
    }
    if(d[0]!=0||c[0]!=1){
        cout << 0 << endl;
        return 0;
    }
    ll ans=1;
    FOR(i,1,n){
        if(!c[i]) continue;
        (ans*=pow_mod(c[i-1],c[i],mod))%=mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4788
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,s=0,t=0;
	int q,i,arr[1024];
	scanf("%d",&q);
	for(i=0;i<q;i++)
	{
		scanf("%lld %lld",&a,&b);
		s=a*b;
		t=sqrt(s);
		if(t*t==s)
		{
			if(a==b)
			{
				arr[i]=(a-1)*2;
			}
			else if(a!=b)
			{
				arr[i]=(t-1)*2-1;
			}
		}
		else if(t*t!=s)
		{
			if(s<=t*(t+1))
			{
				arr[i]=t*2-2;
			}
			else if(s>t*(t+1))
			{
                arr[i]=t*2-1;				
			}
		}		
	}
	for(i=0;i<q;i++)
	   printf("%d\n",arr[i]);
	return 0; 
}

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

ll power(ll a,ll b)
{
   ll res=1;
    while(b)
    {
     if(b&1)res=res*a;
        a=a*a;
        b/=2;
    }
    return res;
}


void solve()
{
int x;
    cin>>x;
    if(x)cout<<0<<endl;
    else cout<<1<<endl;
}


int main()
{
 ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t=1;
  //  cin>>t;
    while(t--)
        solve();
}

Measured memory_bytes: 3644
# coding: utf-8
# Your code here!

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse = True)
quart = sum(A) / (4 * M)
for i in range(M):
    if A[i] < quart:
        print('No')
        exit()
else:
    print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main() {
  speed;
	int n;
	int h[20];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int ans=1;
	for (int i = 1; i < n; i++) {
		int count = 0;
		for (int j = i-1; j >= 0; j--) {
			if (h[i] - h[j] >= 0)count++;
          else{
            count=0;
            break;
          }
		}
		if (count >0 )ans++;
	}
		cout << ans <<endl;
	return 0;
}


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

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

int main(void)
{
    string s; cin>>s;
    int k=s.size();
    cout<<s[0]<<k-2<<s[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll t;
  //cin>>t;
 // while(t--){
ll a,b,c=0,d=0,e=0,f=0;
string s;
string s2;
cin>>s;
cin>>s2;
a=s2.length();
b=s.length();
for(int i=0;i<=b-a;i++){
  for(int j=i;j<i+a;j++){
    if(s[j]==s2[d]){e=e+1;}
    d=d+1;
  }
  d=0;
  if(e>f){f=e;}
  e=0;
}
cout<<a-f<<endl;

 // }
  return 0;
}

Measured memory_bytes: 3624
using System;

class Program
{
	static void Main(string[] args)
	{
        //int a, b,c;
        int[] a = new int[3];

		string[] s = Console.ReadLine().Split(' ');

		// int a = int.Parse(Console.ReadLine());

		a[0] = int.Parse(s[0]);
		a[1] = int.Parse(s[1]);
        a[2] = int.Parse(s[2]);

        Array.Sort(a);

        Console.WriteLine("{0} {1} {2}",a[0],a[1],a[2]);

		//Console.WriteLine("");


	}
}

Measured memory_bytes: 9320
import sys

W, H = map(int, input().split())
Xs = [int(sys.stdin.readline()) for _ in range(W)] + [10**9]
Ys = [int(sys.stdin.readline()) for _ in range(H)] + [10**9]

Xs.sort()
Ys.sort()

ans = 0
iX = iY = 0
for _ in range(W+H):
    if Xs[iX] <= Ys[iY]:
        ans += Xs[iX] * (H-iY+1)
        iX += 1
    else:
        ans += Ys[iY] * (W-iX+1)
        iY += 1

print(ans)


Measured memory_bytes: 11792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        final double r = in.nextDouble();
        System.out.printf("%.5f %.5f\n", r * r * Math.PI, r * 2 * Math.PI);
        // System.out.printf("%f %f\n", r * r * Math.PI, r * 2 * Math.PI);
    }
}

Measured memory_bytes: 28368
s = gets.chomp

gets.to_i.times do
  o, b, e, r = gets.split
  b, e = [b, e].map &:to_i
  case o
  when 'print' then puts s[b..e]  
  when 'reverse' then s[b..e] = s[b..e].reverse
  when 'replace' then s[b..e] = r
  end
end

Measured memory_bytes: 8732
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }

fun main(args: Array<String>) {
    val (a, b) = readInts()
    val quiz = "$a$b".toInt()

    println((1 until 500).map { it * it }.find { it == quiz }?.let { "Yes" } ?: "No")
}

Measured memory_bytes: 35988
N = int(input())
table={}
for _ in input().split():
    i = int(_)
    if i in table.keys():
        table[i] += 1
    else:
        table[i] = 1
ans = 0
for k, v in table.items():
    if k > v:
        ans += v
    else:
        ans += v-k
print(ans)

Measured memory_bytes: 23288
(n,m,),*a=$<.map{|z|z.split.map &:to_i}
r=[-1]*-~n
c=r.dup
f=->x{r[x]>0?r[x]=f[r[x]]:x}
a.map{|u,v|x,y=[f[u],f[v]].sort
(m-=1)>=0&&x!=y&&[r[x]+=r[y],r[y]=y=x]
x==y&&[c[u]-=1,c[v]-=1]}
(1..n).map{|i|p c[i]-r[f[i]]}

Measured memory_bytes: 55520
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	queue<pair<ll,int>>q;
	q.push(mp(3LL,1));
	q.push(mp(5LL,2));
	q.push(mp(7LL,4));
	pair<ll,int>at;
	while(q.front().F <= n){
		at=q.front();
		if(at.S==7){
			ans++;
		}
		q.pop();
		q.push(mp(at.F*10LL+3LL,at.S|1));
		q.push(mp(at.F * 10LL + 5LL, at.S | 2));
		q.push(mp(at.F * 10LL + 7LL, at.S | 4));
		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4580
/*

Author : AllKilled
Date   : 201911166

Contest: AtCoder Beginner Contest 145.
Problem: Task C.
Result :

*/
#include<bits/stdc++.h>
using namespace std;

typedef long long LL;

const LL MAXN = 1e6+7;

///--------------------------------------------///

int n, x[11], y[11], vis[11], dp[11], tot;
double ans = 0.0;

double dist(int a, int b){
    return sqrt(1.0 * a *a + 1.0 * b * b);
}

void dfs(int p, int num){
    if(p > num) return ;
    if(num == 1) {
        double res = 0;
        for(int i = 2; i <= n; ++i) {
            int u = dp[i], v = dp[i-1];
            res += dist(x[u] - x[v], y[u] - y[v]);
        }
        ans += res;
        return ;
    }
    swap(dp[p], dp[num]);
    dfs(1, num - 1);
    swap(dp[p], dp[num]);
    dfs(p + 1, num);
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        dp[i] = i;
        cin >> x[i] >> y[i];
    }
    tot = n;
    //dfs(1, tot);
    vector<int> f;
    int cnt = 1;
    for(int i = 1; i <= n; ++i) f.push_back(i), cnt *= i;
    do {
        for(int i = 1; i < n; ++i){
            int u = f[i], v = f[i-1];
            ans += dist(x[u] - x[v], y[u] - y[v]);
        }
    } while (next_permutation(f.begin(), f.end()));
    ans /= cnt;
    printf("%.12f\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main(){
  int x, y = 1;
  while (1) {
    std::cin >> x >> y;
    if (x == 0 && y == 0) {
      break;
    }
  
    if (x < y) {
      std::cout << x << " " << y << std::endl;
    }
    else{
      std::cout << y << " " << x << std::endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<iostream>
#define ll long long
using namespace std;
int a1,a2,a3;
int main(){
	scanf("%d%d%d",&a1,&a2,&a3);
	if(a1+a2+a3>=22) 
		printf("bust\n");
	else 
		printf("win\n");
	return 0;
}


Measured memory_bytes: 256
matrix_A = []
matrix_B = []
matrix_C = []

height, width = gets.split.map(&:to_i)
height.times{ matrix_A << gets.split.map(&:to_i) }
width .times{ matrix_B << gets.to_i }

height.times do|h|
  tempC = 0
  width.times do|w|
    tempC += matrix_A[h][w] * matrix_B[w]
  end
  matrix_C << tempC
end

puts matrix_C



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

using namespace std;
int n;
long long a[50];
long long k, p, q;

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

  cin >> k;

  n = 50;
//  if (k > 0) {
    p = k % n;
    q = k / n;
//    if (p) {
      for (long long i = 0; i < n; i++) {
        a[i] = 49LL + q - p;
      }

      for (long long i = 0; i < p; i++) {
        a[i] = 100LL + q - p;
      }
  //   } else {
  //     for (long long i = 0; i < n; i++) {
  //       a[i] = 49LL + q;
  //     }
  //   }
  // //}

  cout << n << "\n";
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  return 0;
}
// q == 0 => 99
// q == 1 => 100

// {49} => 0
// {49*48,  1*99}   => 1
// {48*47,  2*98}   => 2
// {47*46,  3*97}   => 3
// {46*45,  4*96}   => 4
// { 0*0,  50*50}   => 50
// {49*49,  1*100}  => 51
// {48*48,  2*99}   => 52
// { 1*1,  49*52}   => 99
// { 0*0,  50*51}   => 100
// { 49*50, 1*101}  => 101
// { 48*49, 2*100}  => 102
// { 2*3,  48*54}   => 148
// { 1*2,  49*53}   => 149
// { 0*0,  50*52}   => 150


// 50*(50 + q - 1) => q * 50


Measured memory_bytes: 256
def Main(K):
    l = (1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51)
    return l[K-1]
                

def main():
    K = int(input())
    print(Main(K))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>
int main(void) {
	int A,B,C,K;
	scanf("%d%d%d%d",&A,&B,&C,&K);
	if(K<=A)
	printf("%d",K);
	else if(A<K&&K<=A+B)
	printf("%d",A);
	else
	printf("%d",2*A-K+B);
	return 0;
}


Measured memory_bytes: 1712
from collections import defaultdict

N = int(input())
S = defaultdict(int)
ans = 0
for _ in range(N):
    s = input()
    sl = []
    for n in s:
        sl.append(n)
    sl.sort()
    s = ''.join(sl)
    S[s] += 1

for value in S.values():
    ans += value * (value-1)//2
print(ans)

Measured memory_bytes: 64856
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b>>1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;


//////////////////////////

int main() {
	ll H, W, K;
	cin >> H >> W >> K;

	mint fr = 1;
	repn(i, K) fr *= (H + W - i + 1);

	mint frr = 1;
	repn(i, K - 2) frr *= (H + W - 2 - i + 1);

	mint ans = 0;
	repn(i, K) {
		ans += fr*(i+1);
		ans += frr * i * (i - 1) * H * W;
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 256
/*
 　　　　　／＞　 フ
 　　　　　| 　_　 _|
 　 　　　／`ミ _x 彡
 　　 　 /　　　 　 |
 　　　 /　  ヽ　　 ?
 　／￣|　　 |　|　|
 　| (￣ヽ＿_ヽ_)_)
 　＼二つ
  */

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
    static short st[30];short tp=0;
    if(x<0) putchar('-'),x=-x;
    do st[++tp]=x%10,x/=10; while(x);
    while(tp) putchar('0'|st[tp--]);
    putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

const int N = 1000500;
const int P = 998244353;
ll fpw(ll x, ll mi) {
    ll res = 1;
    for (; mi; mi >>= 1, x = x * x % P)
        if (mi & 1) res = res * x % P;
    return res;
}
inline int add(int x, int y) {
    return x + y >= P ? x + y - P : x + y; 
}
int A[N], lim, n, inv2 = (P + 1) / 2;
void FWT_xor(int *A, int ty) {
    for (int i = 1;i < lim; i <<= 1) {
        for (int j = 0;j < lim; j += (i << 1)) {
            int *f = A + j, *g = f + i;
            for (int k = 0;k < i; k++) {
                int x = f[k], y = g[k];
                f[k] = add(x, y),  g[k] = add(x, P - y);
                if (ty == -1) f[k] = 1ll * f[k] * inv2 % P,
                    g[k] = 1ll * inv2 * g[k] % P;
            }
        }
    }
}

int p[N], S;
int main() {
    read(n), lim = 1 << n;
    for (int i = 0;i < lim; i++) read(p[i]), S += p[i];
    S = fpw(S, P - 2);
    for (int i = 0;i < lim; i++) p[i] = 1ll * p[i] * S % P;
        /* write(p[i], ' '); */
    /* puts(""); */
    FWT_xor(p, 1);
    for (int i = 0;i < lim; i++) {
        /* write(g[i], ' '), write(p[i]); */
        ll up = i == 0 ? 0 : lim, dw = (p[i] + P - 1) % P;
        /* write(up, ' '), write(dw); */
        A[i] = up * fpw(dw, P - 2) % P;
    }
    FWT_xor(A, -1);
    for (int i = 0;i < lim; i++) write(add(A[i], -A[0] + P));
    return 0;
}

Measured memory_bytes: 5136
import java.util.Scanner;
import java.math.BigInteger;
import java.util.Arrays;


public class Main {
	
	

	public static void main(String[] args) {
		//Scanner myObj = new Scanner(System.in);
		Scanner ret = new Scanner(System.in);
		
		int a,b,t;
		String s;
	
		s=ret.nextLine();
		 if((s.charAt(0)=='R')&&(s.charAt(1)=='R')&&(s.charAt(2)=='R'))
			System.out.println("3");
		 else if((s.charAt(0)=='R')&&(s.charAt(1)=='R')||(s.charAt(1)=='R')&&(s.charAt(2)=='R'))
		    System.out.println("2");
		
		else if((s.charAt(0)=='S')&&(s.charAt(1)=='S')&&(s.charAt(2)=='S'))
			System.out.println("0");
		else
			System.out.println("1");
			
		
		
	}

}

Measured memory_bytes: 35776
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int main(){
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  rep(i, M) cin >> B[i];
  int ans = 0;
  rep(n, N){
    int a;
    int sum = C;
    rep(i, M){
      cin >> a;
      sum += a * B[i];
    }
    if(sum > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int n;
const long long M = 1e9 + 7;
int cnt;
long long ans = 1;
bool pv;
string s;

int main()
{
    scanf("%d", &n);
    cin>>s;
    s = 'W' + s;
    for(int i = 1; i <= 2 * n; i++)
    {
        if((s[i] != s[i - 1]) ^ pv)
        {
            pv = false;
            cnt++;
        }
        else
        {
            pv = true;
            ans *= cnt;
            ans %= M;
            cnt--;
            if(cnt < 0)
            {
                printf("0");
                return 0;
            }
        }
    }
    if(cnt > 0)
    {
        printf("0");
        return 0;
    }
    for(int i = 1; i <= n; i++)
    {
        ans *= i;
        ans %= M;
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 772
s=input()
k=int(input())

lis=[]
for i in range(len(s)):
    lis.append(s[i:i+5])
    lis.sort()

l=[]
for i in lis[:5]:
    for j in range(5):
        l.append(i[:j+1])

l=set(l)
l=list(l)

l.sort()

print(l[k-1])

Measured memory_bytes: 38640
/*
ID: jerrywcy
TASK: AtCoder ABC 105 Problem D
LINK: https://abc105.contest.atcoder.jp/tasks/abc105_d
LANG: C++
*/
#include <bits/stdc++.h>

using namespace std;

int n,m;
int a[100010];
map<int,int> fr;
long long sol;

int main()
{
  	cin>>n>>m;
  	int i,j;
    for(i=1;i<=n;i++)cin>>a[i];
    
    for(i=1;i<=n;i++) {
        a[i]=(a[i-1]+a[i])%m;
        sol+=1LL*fr[a[i]];
        if(a[i]==0)
            sol++;
        fr[a[i]]++;
    }
    cout<<sol<<endl;
  	
	return 0;
}

Measured memory_bytes: 3584
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    K = int(input())
    res = 1
    for _ in range(N):
        if res<K:
            res *= 2
        else:
            res += K
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

ll dp[100010][13];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = s.size();
    dp[0][0] = 1;
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < 13; j++)
        {
            if (s[i] == '?')
            {
                for (ll k = 0; k < 10; k++)
                {
                    (dp[i + 1][(j * 10 + k) % 13] += dp[i][j]) %= MOD;
                }
            }
            else
            {
                ll k = s[i] - '0';
                (dp[i + 1][(j * 10 + k) % 13] += dp[i][j]) %= MOD;
            }
        }
    }
    cout << dp[n][5] << endl;
}

Measured memory_bytes: 10704
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long H, W;
  cin >> H >> W;
 
  if(H==1 || W==1){
  	cout << 1 << endl;  
  }
  else{
  	cout << (H * W + 1) / 2 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,ck,ct,ki;
  cin >> n;
  cin >> ck >> ct >> ki;
  int top[n],cost=ck,ans;
  for(int i=0;i<n;i++) cin >> top[i];
  sort(top,top+n,greater<int>());
  ans = ki / cost;
  for(int i=0;i<n;i++){
      ki += top[i];
      cost += ct;
      if(ans<ki/cost) ans = ki / cost;
      //else goto END;
  }
  //END:
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>

using namespace std;

const ll N = 3e5+100;
const ll MOD = 1e9+7;

int main()
{

	ll a,b;
	cin >> a >>b;

	cout << (a*b)/(__gcd(a,b)) << endl;
	
	return 0;
}

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

int main(){
	int n;
	int m;
	int k;
	cin >> n >> m >> k;
	int have = n*m;
	for (int i = 0; i <= n; i++){
		for (int j = 0; j <= m; j++){
			int bl = i*m + j*n;
			bl -= i*j*2;
			if (bl == k){
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  ll N;
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;
    return 0;
  }
  string S;
  ll i = 1;
  while (N != 0) {
    if (N % (i * -2) != 0) {
      S.push_back('1');
      N -= i;
    } else {
      S.push_back('0');
    }
    i *= -2;
  }
  reverse(S.begin(), S.end());
  cout << S << endl;
}

Measured memory_bytes: 3604
# 拡張ユークリッドアルゴリズム
# (d, x, y): d=ax+by を満たすd, x, yを求める
# aとbが互いに素な整数であればgcd(a,b)=d=1, ax=1 (mod b)
# xは法bの元でaの乗法逆元a^-1になる
def exEuclid(a, b):
    if (b==0):
        return (a, 1, 0)
    else:
        (dd, xx, yy) = exEuclid(b, a % b)
        return (dd, yy, xx - (a//b)*yy)

def mycomb(n, k, p):
    k = min(n-k,k)
    fact=1
    finv=1
    for i in range(k):
        fact=fact*(n-i) % p
        finv=finv*(i+1) % p
    (d, x, y) = exEuclid(finv, p)
    return fact*x % p

x, y = list(map(int,input().split()))

if ((x+y)%3 != 0):
    print(0)
    exit()
else:
    n1 = (-x+2*y)//3
    n2 = (2*x -y)//3
    if( (n1<0) or (n2<0) ):
        print(0)
        exit()
    npath = mycomb(n1+n2, n2, 10**9+7)
    print(npath)



Measured memory_bytes: 3064
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        String s = scanner.next();
        String t = scanner.next();
        System.out.println(t + s);
    }
}


Measured memory_bytes: 22100
const Main = function(input){
function r(input){
var str = new String(input);
var out = "";
 for(var i = str.length; i > 0 ; i--){
   out += str.charAt(i - 1);
 }
return out;
};
S = new String(input.split("\n")[0]);
var n = S.length;
if(r(S) == S){
  var b = S.substring(-1,(n-1)/2);
  if(r(b) == b){
    var c = S.substring((n+3)/2-1,n);
    if(r(c) == c){
      console.log("Yes");
    }else{console.log("No");}
  }else{console.log("No");}
}else{console.log("No");}
};
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

const int N = 305;
int n,a[N][N];
bool b[N][N];

int solve() {
    for(int k=1;k<=n;k++) {
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=n;j++) if(k != i && k != j) {
                int64_t ans = a[i][k] + a[k][j];
                if(ans < a[i][j]) return 0;
                else if(ans == a[i][j]) {
                    b[i][j] = 0;
                }
            }
        }
    }
    return 1;
}

int main() {
    cin >> n;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=n;j++) {
            cin >> a[i][j]; b[i][j] = 1;
        }
    }
    int64_t ans = 0;
    if(solve()) {
        for(int i=1;i<=n;i++) {
            for(int j=i;j<=n;j++) {
                if(b[i][j]) ans += a[i][j];
            }
        }
        cout << ans << endl;
    } else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
/// 10:40 pm 15/08/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)

#include<bits/stdc++.h>

using namespace std;
#define endl '\n'
typedef long long ll;


bool isTriangle(ll a, ll b, ll c) {
    return ((a+b)>c && (b+c)>a && (a+c)>b) && (a!=b && b!=c && c!=a);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> v(n);
    for (ll i = 0; i < n; i++) {
        cin >> v[i];
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        for (ll j = i + 1; j < n; j++) {
            for (ll k = j + 1; k < n; k++) {
                if (isTriangle(v[i], v[j], v[k])) {
                    ans++;
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3640
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	var n int
	fmt.Scan(&n)

	as, bs, cs := make([]int, n), make([]int, n), make([]int, n)
	scanner := wordScanner()
	for i := range as {
		as[i] = getInt(scanner)
	}
	for i := range bs {
		bs[i] = getInt(scanner)
	}
	for i := range cs {
		cs[i] = getInt(scanner)
	}

	sort.Sort(sort.Reverse(sort.IntSlice(as)))
	sort.Sort(sort.Reverse(sort.IntSlice(bs)))
	sort.Sort(sort.Reverse(sort.IntSlice(cs)))

	j := 0
	bc := make([]int, n)
	for i := 0; i < n; i++ {
		if i != 0 {
			bc[i] += bc[i-1] + j
		}
		for ; j < n; j++ {
			if bs[i] >= cs[j] {
				break
			}
			bc[i]++
		}
	}

	ans := 0
	j = 0
	for i := 0; i < n; i++ {
		for ; j < n; j++ {
			if as[i] >= bs[j] {
				break
			}
		}
		if j != 0 {
			ans += bc[j-1]
		}
	}

	fmt.Println(ans)
}


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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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;
}

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

int N;
int ans;

void solve() {
    cin >> N; vector<int> a(N);
    for (auto& i : a) cin >> i;
    sort(a.begin(), a.end());
    for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N - 1; j++) {
			int index = (upper_bound(a.begin(), a.end(), a[i] + a[j] - 1) - a.begin());
			index--;
			ans += index - j;	
		}
	}
	cout << ans;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll testCases = 1; // cin >> testCases;
    while (testCases--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    static int solve(int[] inputs){
        int[] dp = new int[inputs.length];
        dp[0] = 0;
        dp[1] = Math.abs(inputs[0] - inputs[1]);

        for(int i = 2; i < dp.length; i++)
            dp[i] = Math.min(dp[i-1] + Math.abs(inputs[i] - inputs[i-1]), dp[i-2] + Math.abs(inputs[i] - inputs[i-2]));

        return dp[dp.length - 1];
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(); scanner.nextLine();
        int[] inputs = new int[n];
        for(int i = 0; i < n; i++)
            inputs[i] = scanner.nextInt();

        System.out.println(Main.solve(inputs));
        scanner.close();
    }
}

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

using namespace std;

int main () {
	string s;
	cin >> s;
	int ans = s.size ();
	int curs = 0, curt = 0;
	for (int i = 0;i < s.size ();i ++) {
		if (s[i] == 'S') {
			curs ++;
			curt = 0;
		}
		else {         
			curt ++;
			int mn = min (curs, curt);
			curt -= mn;
			curs -= mn;
			ans -= mn * 2;	
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline int Min(int a,int b){return a<b?a:b;}
const int INF=0x3f3f3f3f;
int M,seg[800002],tag[800002];
static inline void upt(int x){seg[x]=Min(seg[x<<1],seg[x<<1|1]);}
static inline void nodeCover(int x,int l,int val){seg[x]=l-val;tag[x]=val;}
static inline void dnt(int x,int l,int r)
{
  if(tag[x])
  {
    int mid=(l+r)/2;
    nodeCover(x<<1,l,tag[x]);nodeCover(x<<1|1,mid+1,tag[x]);
    tag[x]=0;
  }
}
static inline void segCover(int u,int v,int t,int x=1,int l=1,int r=M)
{
  if(u<=l&&r<=v){nodeCover(x,l,t);return;}
  dnt(x,l,r);int mid=(l+r)/2;
  if(u<=mid){segCover(u,v,t,x<<1,l,mid);}
  if(v>mid){segCover(u,v,t,x<<1|1,mid+1,r);}
  upt(x);
}
static inline int segQuery(int p,int x=1,int l=1,int r=M)
{
  if(l==r){return p-seg[x];}dnt(x,l,r);int mid=(l+r)/2;
  return p<=mid?segQuery(p,x<<1,l,mid):segQuery(p,x<<1|1,mid+1,r);
}
int main()
{
  int N=IN(),cur=1,left,right;M=IN();
  for(int i=0;i<N;i++)
  {
    left=IN(),right=IN();
    if(cur>=left&&cur<=right)segCover(cur,right,-INF),cur=right+1;
    else if(cur<left)segCover(left,right,segQuery(left-1));
    if(cur>M){puts("");N-=i;while(N--){puts("-1");}return 0;}
    OUT(i+seg[1]+1);
  }
}

Measured memory_bytes: 5692
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 


using namespace std;

int main(){

	int n,i;
  	cin >> n >> i;
  
  	cout << n - (i - 1) << endl;
  
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
long long a,b;
string st;
bool findnumber(string st,int different)
{
	for(int i=0;i<st.size();i++)
		if(i!=different-1&&st[i]<'0'||i!=different-1&&st[i]>'9') return true;
	return 0;
}
int main()
{
	cin>>a>>b;
	cin>>st;
	if(st[a]!='-'||findnumber(st,a+1)) cout<<"No\n"; else cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 256