akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static int n;
    static int w;
    static int[] weights;
    static long[] values;
    static long[][] dp;

    static long dp() {

        for (int i = 0; i <= n ; i++) {
            for (int j = 0; j <= w ; j++) {
                if (i==0||j==0)
                    dp[i][j]=0;
                else if (weights[i-1]<=j)
                    dp[i][j]=Math.max(values[i-1]+dp[i-1][j-weights[i-1]],dp[i-1][j]);
                else
                    dp[i][j]=dp[i-1][j];
            }
        }


        return dp[n][w];
    }


    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        n = Integer.parseInt(st.nextToken());
        w = Integer.parseInt(st.nextToken());
        dp = new long[n + 1][w + 1];

        weights = new int[n];
        values = new long[n];

        for (int i = 0; i < n; i++) {
            st = new StringTokenizer(br.readLine());
            weights[i] = Integer.parseInt(st.nextToken());
            values[i] = Long.parseLong(st.nextToken());
        }

        System.out.println(dp());

    }
}


Measured memory_bytes: 130468
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  str S;
  cin >> S;
  ll ans = 0;
  rep(i,1,S.size()){
    if(S[i] == S[i-1]){
      if(S[i] == '0') S[i] = '1';
      else S[i] = '0';
      ans++;
    }
  }

  print(ans);

 return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)


typedef long long int ll;


using namespace std;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int i,j,k;
    long n,m,tmp,max=0,min,minnum,maxnum,max2=0;
    string s[200000];

    cin >> n;
    rep(i,n){
        cin>>j;
        if(max<j) {
        max=j;
        maxnum=i;
        }else if(max2<j){
            max2=j;
        }
    }
    rep(i,n){
        if(i==maxnum){
                  cout << max2 << endl;
        }else{
        cout << max << endl;
            }    
        }
    


    cout<< *s << endl;

    return 0;
}

Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int length = s.length();

        int count =0;
        for(int i=0;i<length/2;i++){
            char a = s.charAt(i);
            char b = s.charAt(length - 1 -i );
            if(a != b){
                count++;
            }

//            System.out.println(String.valueOf(a) + String.valueOf(b));

        }
        System.out.println(count);






    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define debug(x) cout<<#x<<"::"<<x<<endl;
using namespace std;
typedef long long ll;

void solve()
{
    int h,a;
    cin>>h>>a;
    int x=ceil((double)h/a);
    cout<<x<<'\n';
}

int main()
{
    
    int t;
    t=1;
    while(t--)
        solve();
    return 0;
}

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

int main(){
	int a,b,c,d;cin>>a>>b>>c>>d;
	int x=(c+b-1)/b,y=(a+d-1)/d;
	if(x<=y)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 3636
using System;
using System.Linq;

namespace AtCoderPractic0718
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int YY = int.Parse(s.Substring(0,2));
            int MM = int.Parse(s.Substring(2, 2));

            if(MMcheck(YY) && MMcheck(MM))
            {
                Console.WriteLine("AMBIGUOUS");
            }

            if (!MMcheck(YY) && MMcheck(MM))
            {
                Console.WriteLine("YYMM");
            }
            if (MMcheck(YY) && !MMcheck(MM))
            {
                Console.WriteLine("MMYY");
            }
            if (!MMcheck(YY) && !MMcheck(MM))
            {
                Console.WriteLine("NA");
            }

        }

        public static bool MMcheck(int MM)
        {
            if(MM >=1 && MM <= 12)
            {
                return true;
            }
            else { return false; }
        }

    }
}


Measured memory_bytes: 27492
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        String s = stdIn.next();
        if(s.equals("AAA") || s.equals("BBB")){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
#define int long long 

using namespace std ;

int n , m ;
pair<int,int>arr[100001];
multiset<int>mst;

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

        cin >> n >> m ; 
        for(int i=0;i<n;i++)
                cin >> arr[i].first >> arr[i].second;

        sort(arr,arr+n);
        int nxt = 0 , ans = 0;
        for(int i=1 ; i<=m ; i++ ){
                while(nxt < n and arr[nxt].first == i ){
                        mst.insert(arr[nxt].second);
                        nxt++;
                }
                if(!mst.empty()){
                        ans += *(prev(mst.end()));
                        mst.erase(prev(mst.end()));
                }
        }

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

Measured memory_bytes: 6528
package main

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

func getNextLine(fp *os.File) string {
	scanner := bufio.NewReader(fp)
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getNextWord(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextWord(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)

	h := getNextInt(scanner)
	w := getNextInt(scanner)
	ss := make([]string, h)
	for i := 0; i < h; i++ {
		ss[i] = getNextWord(scanner)
	}
	left := make([][]int, h)
	right := make([][]int, h)
	for i := 0; i < h; i++ {
		left[i] = make([]int, w+2)
		right[i] = make([]int, w+2)
		for x := 0; x < w; x++ {
			if ss[i][x] == '.' {
				left[i][x+1] = left[i][x] + 1
			} else {
				left[i][x+1] = 0
			}
			if ss[i][w-x-1] == '.' {
				right[i][w-x] = right[i][w-x+1] + 1
			} else {
				right[i][w-x-1] = 0
			}
		}
	}

	up := make([][]int, w)
	down := make([][]int, w)
	for i := 0; i < w; i++ {
		up[i] = make([]int, h+2)
		down[i] = make([]int, h+2)
		for y := 0; y < h; y++ {
			if ss[y][i] == '.' {
				up[i][y+1] = up[i][y] + 1
			} else {
				up[i][y+1] = 0
			}
			if ss[h-y-1][i] == '.' {
				down[i][h-y] = down[i][h-y+1] + 1
			} else {
				down[i][h-y-1] = 0
			}
		}
	}

	max := 0
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			if ss[y][x] == '#' {
				continue
			}
			sum := left[y][x+1] + right[y][x+1] + up[x][y+1] + down[x][y+1] - 3
			if max < sum {
				max = sum
			}
		}
	}

	fmt.Fprintln(writer, max)

	writer.Flush()
}


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

int main() {
    int N; string S; cin >> N >> S;
    int ans = 0;
    for (int i = 0; i <= 999; i++) {
        int dig[3] = {i/100, i/10%10, i%10};
        int flag = 0;
        for (int j = 0; j < N; j++) {
            if (S[j] == dig[flag] + '0') flag++;
            if (flag == 3) break;
        }
        if (flag == 3) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define LOOP(i, N) for (int i = 1; i <= (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define RLOOP(i, N) for (int i =(int)N; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int main(){
  int n;
  int y;
  cin>>n>>y;
  for(int i=n;i>=0;i--){
    for(int j=n-i;j>=0;j--){
      int tmp=10000*i+5000*j+1000*(n-i-j);
      if(tmp==y){
        cout<<i<<" "<<j<<" "<<n-i-j<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<" "<<-1<<" "<<-1<<endl;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int H = l[0], W = l[1];
            var x = 0;
            var A = new string[H];
            
            var count = 0;
            var totalSharp = 0;
            for (var i = 0; i < H; i++) {
               var line = Console.ReadLine();
               totalSharp += line.Count(z => z == '#');
               for (var j = x; j < W; j++) {
                  if (line[j] == '#') {
                     x = j;
                     count++;
                  }
                  else
                      break;
               }
            }
            
            Console.WriteLine(count == totalSharp ? "Possible" : "Impossible");
        }
    }
}


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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    int ans = 0;
    for(int i = 1; i < n; i++) {
        ans += (n - 1) / i;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=200005;

int main()
{
    IO;
    int n;
    cin >> n;
    cout<<2*n/__gcd(2,n)<<endl;
    re 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int N;
  cin >> N;
  
  vector<int> number_list(N);
  for(int i = 0; i < N; i++) {
    cin >> number_list.at(i);
  }
  
  int devide_count = 0;
  bool done = false;
  while (1) {
  	for(int i = 0; i < N; i++) {
      if (number_list.at(i) % 2 != 0) {
        done = true;
        break;
      }
      number_list.at(i) /= 2;
    }
    
    if (done) {
      break;
    }
    
    devide_count++;
  }
  
  cout << devide_count << endl;
}

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

#define fl(k, n) for(int i = k; i < n; i++)
#define flr(k, n) for(int i = n - 1; i >= k; i--)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define ll long long
#define llu long long unsigned int
#define mod 1000000007

using namespace std;

int binary_search(vector<int> nums, int target_val){
  int begin = 0;
  int end = nums.size();
  int mid;

  while(begin <= end){
    mid = begin + (end - begin) / 2;
    if(nums[mid] == target_val)
      return mid;
    else if(nums[mid] <= target_val && nums[mid + 1] > target_val)
      return mid;
    else if(nums[mid] > target_val)
      end = mid - 1;
    else
      begin = mid + 1;
  }

  if(begin == 0)
    return -1;
  else 
    return nums.size();
}

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

  int n;
  cin >> n;

  vector<ll> nums(n);
  fl(0, n)
    cin >> nums[i];

  vector<vector<ll>> max_diff(n, vector<ll>(n));

  for(int l = n - 1; l >= 0; l--){
    for(int r = l; r < n; r++){
      if(l == r)
        max_diff[l][r] = nums[l];
      else{
        max_diff[l][r] = max(nums[l] - max_diff[l + 1][r], nums[r] - max_diff[l][r - 1]);
      }
    }
  }

  cout << max_diff[0][n - 1] << "\n";

}

Measured memory_bytes: 73668
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    string s;
    cin >> s;
    for (size_t i = 0; i < (s.size()+1)/2; i++)
    {
        cout << s.at(2*i);
    }
    cout << endl;
}

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

int main()
{
  int h,w,n;
  cin>>h>>w>>n;
  if(h>w){
     int a=n/h;
     if(n>h*a)
      cout<<(n/h)+1; 
     else
       cout<<n/h; 
  }
  else
    {  int b=n/w;
     if(n>w*b)
      cout<<(n/w)+1; 
     else
       cout<<n/w;
     }
     return 0;
}


Measured memory_bytes: 888
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a > mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	ll n;
	cin>>n;
	if(n == 2){
		cout<<1;
		return 0;
	}
	ll ans = 2;
	ll a = n - 1;
	for(ll i = 2;i*i<=a;i++){
		if(a % i == 0){
			ans++;
			if(i != (a/i)){
				ans++;
			}
		}
	}
	for(ll i = 2;i*i<=n;i++){
		if(n % i == 0){
			// cout<<i<<"\n";
			ll x = n;
			while(x % i == 0){
				x /= i;
			}
			if(x % i == 1){
				// cout<<i<<" ";
				ans++;
			}
			if(n/i != i){
				ll x = n;
				while( x % (n/i) == 0){
					x /= (n/i);
				}
				if(x % i == 1){
					ans++;
					// cout<<(n/i)<<" ";
				}
			}
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long Q,H,S,D,N,ans,k;
int main(){
    cin>>Q>>H>>S>>D>>N;
    k=min(Q*4,min(H*2,S));
    if(k*2<=D) cout<<k*N<<endl;
    else cout<<((N%2)*k)+N/2*D<<endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n-1);
    for(auto& e: a) cin >> e;
    for(auto& e: b) cin >> e;
    for(auto& e: c) cin >> e;
    int happy = 0;
    for(int i=0;i<n;i++){
        happy += b[a[i]-1];
        if(i == 0) continue;
        if(a[i-1] + 1 == a[i]){
            happy += c[a[i-1] - 1];
        }
    }
    cout << happy << endl;
    return 0;
}

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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int k, n, ma = 0;
	cin >> k >> n;
	vi A(n);
	for (int i=0; i<n; i++) {
		cin >> A[i];
	}
	for (int i=1; i<n; i++) {
		ma = max(abs(A[i] - A[i-1]), ma);
	}
	ma = max(ma, k - A[n-1] + A[0]);
	cout << k - ma;
}

Measured memory_bytes: 1024
a,b = map(int,input().split())
s = input()
li = list(map(str,[0,1,2,3,4,5,6,7,8,9]))
for i in range(a):
  if not s[i] in li:
    print("No")
    exit()
if s[a] != "-":
  print("No")
  exit()
for i in range(a+1,a+b+1):
  if not s[i] in li:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 3064
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

BC.sort(key=lambda x: x[1], reverse=True)
A.sort()
l, r = 0, N
for B, C in BC:
    if A[l] >= C:
        break
    a, b = l, r
    if A[r - 1] >= C:
        while a + 1 < b:
            i = a + (b - a) // 2
            if A[i] >= C:
                b = i
            else:
                a = i
        r = b
    n = B + l
    if n > r:
        n = r
        B = n - l
    if n <= b:
        A[l:n] = [C] * B
        l = n
    else:
        A[l:b] = [C] * B
        l = b
    if l == r:
        break

print(sum(A))

Measured memory_bytes: 32960
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int n,m,a,b,ans;
void solve(){
	cin>>n>>m;
	vector<int> mn(n+1,n+1); 
	rep(i,0,m){
		cin>>a>>b;
		mn[a] = min(mn[a],b);
	}
	int board = n+1;
	for(int i=n-1;i;i--){
		if(mn[i]<board){
			board = i+1;
			ans++;
		}
	}
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  int A, B;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  A = vec.size();
  sort(vec.begin(), vec.end());
  decltype(vec)::iterator result = unique(vec.begin(), vec.end());
    vec.erase(result, vec.end());
  B = vec.size();
  
  if(A==B){
    cout << "YES";
  }
  else{
    cout << "NO";
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using intl = long long;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define INF = 1e9;
#define debug(x) cout << #x << ":" << x << endl
using namespace std;
int main(){
    intl n;
    cin >> n;
    string s[n];
    rep(i,n){
        cin >> s[i];
    }
    sort(s, s + n);
    int max = 0;
    int cnt = 1;
    rep(i,n-1){
        if(s[i] == s[i+1]){
            cnt++;
        }
        else {
            max = max(max,cnt);
            cnt = 1;
        }
    }
    if(cnt > max)max = cnt;
    cnt = 1;
    rep(i,n-1){
        if(s[i] == s[i+1]){
            cnt++;
        }
        else {
            if(cnt >= max)cout << s[i] << endl;
            cnt = 1;
        }
    }
    if(cnt >= max)cout << s[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 14208
//temprates
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

using ll = long long;
using namespace std;

#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define LFOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define FORR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LFORR(i,a,b) for(ll i = (int)(a); i >= (ll)(b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define LREP(i,n) LFOR(i,0,(ll)(n)-1)
#define REPR(i,n) FORR(i,(int)(n)-1,0)
#define LREPR(i,n) LFORR(i,(ll)(n)-1,0)

#define SIZ(v) int(v.size())
const int INF = 1e8;
const ll LINF = 1e15;
const int MOD = 1e9+7;




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
char aa[4];
  cin >> aa[0] >> aa[1] >> aa[2] >> aa[3];
  if (aa[0]==aa[1]||aa[1]==aa[2]||aa[2]==aa[3])
    cout << "Bad" << endl;
  else cout << "Good" << endl;

}


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

// 未AC

int main() {
  int N, M;
  cin >> N >> M;
  vector<int64_t> alist(N);
  for (int i = 0; i < N; i++) {
    cin >> alist.at(i);
  }
  sort(alist.begin(), alist.end());
  
  vector<pair<int64_t, int64_t>> cblist(M);
  for (int i = 0; i < M; i++) {
    cin >> cblist.at(i).second >> cblist.at(i).first;
  }
  sort(cblist.begin(), cblist.end());
  reverse(cblist.begin(), cblist.end());

  /*
  int bsum=0;
  for (int i = 0; i < M; i++) {
    bsum += cblist.at(i).second;
  }
  */
  
  int sansyou=0;
  for (int i = 0; i < N; i++) {
    if (cblist.at(sansyou).second<=0 && sansyou<M-1) sansyou++;
    if (cblist.at(sansyou).second<=0 && sansyou==M-1) break;
    if (cblist.at(sansyou).first >= alist.at(i)) {
      alist.at(i)=cblist.at(sansyou).first;
      cblist.at(sansyou).second--;
    }
    else break;
  }
  
  int64_t ans = 0;
  for (int i = 0; i < N; i++) {
    ans += alist.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  for(int i=0;i<a.size();i++){
    cout<<a[i];
    if(b.size()==i)break;
    cout<<b[i];
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a, b, c, d, p;

  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  scanf("%d", &d);
  scanf("%d", &p);

  if (p < c){
    if (c < a){
      printf("%d\n", b);
    }
    else{
      printf("%d\n", a * p);
    }
  }

  else if (p > c){
    if ((a * p) > ((p - c) * d + b)){
      printf("%d\n", ((p - c) * d + b));
    }
    else{
      printf("%d\n", a * p);
    }
  }
  return (0);
}

Measured memory_bytes: 596
import scala.io.StdIn.{readDouble,readLine}

object Main extends App {
  val n = readInt
  val d = new Array[Int](6)
  for(i<- 0 until n) {
    val h = readDouble
    if(h < 165D) d(0) = d(0)+1
    else if(h >= 165D && h < 170D) d(1) = d(1)+1
    else if(h >= 170D && h < 175D) d(2) = d(2)+1
    else if(h >= 175D && h < 180D) d(3) = d(3)+1
    else if(h >= 180D && h < 185D) d(4) = d(4)+1
    else if(h >= 185D) d(5) = d(5)+1
  }

  for(i<-1 to 6) { println(i + ":" + ("*" * d(i-1))) }
}

Measured memory_bytes: 43912
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int solve() {
    string x, y;
    cin >> x >> y;
    vector<vector<int>> dp(x.size() + 1, vector<int>(y.size() + 1, 0));

    for (int i = 1; i <= x.size(); i++) {
        for (int j = 1; j <= y.size(); j++) {
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            if (x[i - 1] == y[j - 1]) {
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
            }
        }
    }

    return dp[x.size()][y.size()];
}

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

Measured memory_bytes: 5040
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int c,n;
  int sm;
  while(cin>>n&&n){
    sm=0;
    for(i=0;i<n*(n-1)/2;i++){
      cin>>c;
      sm+=c;
    }
    cout<<sm/(n-1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

bool local_success(const vector<string>& from, const vector<string>& to, const int i, const int j)
{
    const int m = to.size();

    for (int ii = 0; ii < m; ii++)
    {
        for (int jj = 0; jj < m; jj++)
        {
            if (from[i + ii][j + jj] != to[ii][jj])
            {
                return false;
            }
        }
    }
    return true;
}

bool success(const vector<string>& from, const vector<string>& to)
{
    const int n = from.size();
    const int m = to.size();

    for (int i = 0; i + m <= n; i++)
    {
        for (int j = 0; j + m <= n; j++)
        {
            if (local_success(from, to, i, j))
            {
                return true;
            }
        }
    }
    return false;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<string> from(n);
    for (auto& v : from)
    {
        cin >> v;
    }
    vector<string> to(m);
    for (auto& v : to)
    {
        cin >> v;
    }

    cout << (success(from, to) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
local h, w = io.read("*n", "*n")
if h == 1 then
  print(1)
elseif w == 1 then
  print(1)
elseif h % 2 == 0 or w % 2 == 0 then
  print((h * w) // 2)
else
  local a = w // 2
  local b = h // 2
  print(a * b + (a + 1) * (b + 1))
end


Measured memory_bytes: 760
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<pair<int,int>,int> p3;
typedef pair<int,int> p2;



int main(){
	int m,t,p,r;

	while(true){
		cin>>m>>t>>p>>r;
		if(m==t && t==p && p==r && m==0){
			break;
		}

		vector<p3> corrects; //first:correct number, second:time , third team number-1
		vector< vector<int> > submits;
		vector<int> times;

		for(int i=0;i<t;i++){
			corrects.push_back(p3(p2(0,0),i));
			times.push_back(0);
			submits.push_back(vector<int>(p));
			for(int j=0;j<p;j++){
				submits[i][j]=0;
			}
		}

		for(int i=0;i<r;i++){
			int mi,ti,pi,ri;
			cin>>mi>>ti>>pi>>ri;
			ti--;pi--;

			if(ri != 0){
				submits[ti][pi]++;
			}else{
				corrects[ti].first.second-=mi+submits[ti][pi]*20;
				corrects[ti].first.first++;
			}
		}

		sort(corrects.begin(),corrects.end());
		reverse(corrects.begin(),corrects.end());
		for(int i=0;i<corrects.size();i++){
			cout<<corrects[i].second+1;
			//cout<<" "<<"corrects:"<<corrects[i].first.first<<"time:"<<corrects[i].first.second;
			if(i+1 == corrects.size()){
				cout<<endl;
				break;
			}
			if(corrects[i].first.first==corrects[i+1].first.first){
				if(corrects[i].first.second==corrects[i+1].first.second){
					cout<<"=";
				}
				else{
					cout<<",";
				}
			}else{
				cout<<",";
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1232
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi x(n), y(n), p(n);
    rep(i, n) cin >> x[i] >> y[i] >> p[i];

    vvi px(1<<n, vi(n)), py(1<<n, vi(n));
    rep(i, 1<<n) {
        rep(j, n) {
            px[i][j] = abs(x[j]);
            py[i][j] = abs(y[j]);
            rep(k, n) if(i>>k&1) {
                chmin(px[i][j], abs(x[k]-x[j]));
                chmin(py[i][j], abs(y[k]-y[j]));
            }
        }
    }

    int nn = 1;
    vector<ll> ans(n+1, INT64_MAX);
    rep(i, n) nn *= 3;
    rep(i, nn) {
        int gx = 0, gy = 0;
        int k = i;
        int kl = 1;
        int an = 0;
        while(k) {
            int l = k%3;
            if(l == 1) gx |= kl;
            if(l == 2) gy |= kl;
            if(l) an++;
            kl <<= 1;
            k /= 3;
        }
        ll res = 0;
        rep(j, n) {
            res += ll(p[j]) * min(px[gx][j], py[gy][j]);
        }
        chmin(ans[an], res);
    }

    rep(i, n+1) {
        cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 9752
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int limW = sc.nextInt();
        int[] w = new int[n+1], v = new int[n+1];
        int sumV = 0;
        for(int i = 1; i <= n; i++) {
        	w[i] = sc.nextInt();
        	v[i] = sc.nextInt();
        	sumV += v[i];
        }

        System.out.println(solve(n, limW, w, v, sumV));

    }

	private static long solve(int n, int limW, int[] w, int[] v, int sumV) {
		long[][] dp = new long[n+1][sumV+1];
		Arrays.fill(dp[0], Long.MAX_VALUE);
		dp[0][0] = 0;

		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= sumV; j++) {
				if(j < v[i]) {
					dp[i][j] = dp[i-1][j];
				}else if(dp[i-1][j-v[i]] != Long.MAX_VALUE){
					dp[i][j] = Math.min(dp[i-1][j], dp[i-1][j-v[i]]+w[i]);
				}else {
					dp[i][j] = dp[i-1][j];
				}

			}
		}

		long maxValue=-1;
		for(int i = dp[0].length -1; i >= 0; i--) {
			if(dp[n][i] <= limW) {
				maxValue = i;
				break;
			}
		}

		return maxValue;

	}
}

Measured memory_bytes: 126804
#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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
//const ll mod = 1000000007;
multiset<ll> st;
ll N, M;
vector<l_l> v;

int main() {
  int n;
  cin >> n;
  
  vector<double> v(n);
  rep(i,n) cin >> v[i];
  
  sort(v.begin(),v.end());

  
  rep(i,n-1){
	v[i+1] = ( v[i] + v[i+1] ) / 2.0;
  }
  
  cout << v[n-1] << endl;
  
    

  
  
  
  
  
  
  
  
  
  
  
}


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

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

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

#define ALL(V) (V).begin(),(V).end()

using namespace std;

typedef pair<int,int> ii_t;

#define MAX 100010
#define RMAX 1000
char is_prime[MAX];
#define PMAX 100000
int prime[PMAX];

bool comp(const ii_t& a,const ii_t& b){
    if (a.second == b.second)
        return a.first < b.first;
    else
        return a.second < b.second;
}

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

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

    sort(ALL(v),comp);

    bool result = true;
    long long sum = 0;
    for (int i=0;i<n;i++) {
        sum += v[i].first;
        if (sum > v[i].second) {
            result = false;
            break;
        }
    }

    if (result) 
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <typeinfo>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)

#define PI M_PI
#define INF 1000000000
#define MOD 1000000007;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;
typedef vector<vector<string>> vvs;

constexpr int dir[4][2] = { { -1, 0 }, { 0, -1 }, { 1, 0 }, { 0, 1 } };



int main()
{
	vi a(3);
	rep(i, 3) cin >> a[i];
	sort(a.begin(), a.end());

	cout << a[0] + a[1] << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	//static long[,] dp;
	//static	Dictionary<string, long> dp;
	//static int[] weight, value;
    //static List<string> str = new List<string>();
	static void Main(string[] args)
	{
		// 入力フェーズ
		int N = Int32.Parse(Console.ReadLine());
		//string[] input = Console.ReadLine().Split(' '); // A,B,C
		//int A = Int32.Parse(input[0]);
		//int B = Int32.Parse(input[1]);
		//int C = Int32.Parse(input[2]);
		/*weight = new int[N];
		value = new int[N]; // 重さと価値の入力値
		for(int i=0; i<N; i++){
			string[] items = Console.ReadLine().Split(' ');
			weight[i] = Int32.Parse(items[0]);
			value[i] = Int32.Parse(items[1]);
		}*/
//Console.WriteLine(weight[0] + "");
int ret = 0;
		for(int i=1; i<=N; i++)
		{
			// iの桁数が奇数かどうかを調べる
			int digit = 0;
			int n = i;
			for(; n>0; digit++)
			{
				//Console.Write(n + " ");
				n /= 10;
			}
			//Console.WriteLine(" ans"  + digit);
			if(digit%2 == 1)
			{
				ret++;
			}
		}

		Console.WriteLine(ret+ "");

    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

struct edge{
  int src,dst,cost;
  edge(int s,int d,int c):src(s),dst(d),cost(c){}
};

struct state{
  int pos,dist,balls;
  state(int p,int d,int b):pos(p),dist(d),balls(b){}
};
bool operator<(const state &a,const state &b){
  if(a.dist!=b.dist)return a.dist>b.dist;
  return a.pos<b.pos;
}

// [at][balls]
int times[50][1<<7];
// ??¶?????°??????????????? N * 2^L * K

bool solve(){
  int n,m,l,k;
  cin>>n>>m>>l>>k;
  if(!n)return false;
  assert(n<=50);
  assert(m<=1225);
  assert(l<=7);
  assert(k<=10);
  vector<edge> edges[n];
  REP(i,m){
    int u,v,c;
    cin>>u>>v>>c;
    --u; --v;
    edges[u].push_back(edge(u,v,c));
    edges[v].push_back(edge(v,u,c));
  }
  int start,goal;
  cin>>start>>goal;
  --start; --goal;
  int ball[n]; REP(i,n)ball[i]=0;
  REP(i,l){
    int b;
    cin>>b;
    ball[b-1] = 1<<i;
  }
  int maxball = (1<<l)-1;
  REP(i,n)REP(j,1<<l){
    times[i][j]=0;
  }
  priority_queue<state> Q;
  Q.push(state(start,0,0|ball[start]));
  int result = -1;
  while(!Q.empty()){
    state S = Q.top(); Q.pop();
    if(times[S.pos][S.balls] >= k)continue;
    times[S.pos][S.balls] ++;
    if(S.pos==goal && S.balls==maxball && times[S.pos][S.balls]==k){
      result = S.dist;
      break;
    }
    REP(i,edges[S.pos].size()){
      edge E = edges[S.pos][i];
      Q.push(state(E.dst,S.dist+E.cost,S.balls|ball[E.dst]));
    }
  }
  if(result==-1){
    cout<<"NA"<<endl;
  }else{
    cout<<result<<endl;
  }
  return true;
}

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

Measured memory_bytes: 76940
#include <iostream>
#include <map>

using namespace std;

typedef pair<int,int> pii;
typedef pair<pii,int> piii;

int main()
{
  long long int H, W, N;
  cin >> H >> W >> N;
  map<pii,int> m;
  for(int i = 0; i < N; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
        int x = a-j;
        int y = b-k;
        if(x >= 0 && x < H - 2 && y >= 0 && y < W - 2){
          map<pii,int>::iterator ite = m.find(pii(x,y));
          if(ite != m.end())
            (ite->second)++;
          else
            m.insert(piii(pii(x,y),1));
        }
      }
    }
  }
  long long int ans[10] = {};
  ans[0] = (H-2)*(W-2)-m.size();
  for(map<pii,int>::iterator ite = m.begin(); ite != m.end(); ite++)
    ans[ite->second]++;
  for(int i = 0; i < 10; i++)
    cout << ans[i] << endl;
}

Measured memory_bytes: 56448
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;
 
#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define mem(a,val) memset(a, val, sizeof a)
 
#define maxn 100010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;
 
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int n, k;
int cum[maxn], sum[maxn];
string s;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  cin >> s;
  vector<int> v;
  int cnt = 1;
  for (int i = 1; i < n; ++i) {
    if (s[i] != s[i - 1]) {
      v.push_back(cnt);
      if (s[i - 1] == '0') cum[(int)v.size()] = 1;
      cnt = 1;
    }
    else cnt++;
  }
  v.push_back(cnt);
  if (s[n - 1] == '0') cum[(int)v.size()] = 1;
  n = v.size();
  for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + v[i - 1];
  for (int i = 1; i <= n; ++i) cum[i] += cum[i - 1];
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int lo = 0, hi = n - i - 1;
    while (lo <= hi) {
      int mid = (lo + hi) >> 1;
      if (cum[mid + i + 1] - cum[i] <= k) {
        ans = max(ans, sum[mid + i + 1] - sum[i]);
        lo = mid + 1;
      }
      else hi = mid - 1;
    }
  }
  cout << ans << endl;
}





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

#define debug_input freopen("stdin.in", "r", stdin)
#define debug_output freopen("stdout.out", "w", stdout)
#define FOR(i, a, b) for(ll i = a; i <= b; i++)
#define FORALL(i, n) for(ll i = 0; i < n; i++)
#define FORD(i, a, b) for(ll i = a; i >= b; i--)
#define SORT(a) sort(a.begin(), a.end())
#define REV(a) reverse(a.begin(), a.end())
#define NP(a) next_permutation(a.begin(), a.end())
#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

ll n;
ll a[200005];
ll sum[200005];

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

	ll mod = 1e9 + 7;
	ll tot = 0;
	ll ans = 0;

	cin >> n;	

	sum[0] = 0;
	FOR(i, 1, n) {
		cin >> a[i];
		sum[i] = (sum[i - 1] + a[i]) % mod;
	}

	FOR(i, 1, n) {
		ans = (ans + (a[i] * ((mod + sum[n] - sum[i]) % mod) % mod)) % mod;
	}

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

Measured memory_bytes: 6780
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(register int i=(a);i<=(b);i++)
#define dep(i,a,b) for(register int i=(a);i>=(b);i--)
using namespace std;
const int maxn=2e5+5;
//const double pi=acos(-1.0);
//const double eps=1e-9;
//const ll mo=1e9+7;
int n,m,k,l,q;
int a[maxn],c[maxn];
int f[maxn][25];
int ans,tmp,cnt;
int flag;
char s[maxn];
bool ok[maxn];
int main()
{
    int T,cas=1;
    //scanf("%d",&T);
    while(scanf("%d",&n)!=EOF)
    {
        rep(i,0,n) c[i]=1;
        int j=1;
        rep(i,1,n) scanf("%d",&a[i]);
        scanf("%d",&l);
        rep(i,0,20)
        for(int j=0;j<=n;j++)
        f[j][i]=inf;
        rep(i,1,n){
            while(a[i]>a[j]+l) {f[j][0]=i-1;j++;}
        }
        rep(i,1,20)
        {
            c[i]=c[i-1]<<1;
            for(int j=1;j<=n;j++)
            if(f[j][i-1]!=inf){
                //cout<<f[j][i-1]<<endl;
                f[j][i]=f[f[j][i-1]][i-1];
            }
        }
        ans=0;
        scanf("%d",&q);
        rep(t,1,q)
        {
            int x,y,ans=0;
            scanf("%d%d",&x,&y);
            if(x>y) swap(x,y);
            dep(i,20,0)
            {
                if(f[x][i]<y)
                {
                    x=f[x][i];
                    ans+=c[i];
                }
            }
            printf("%d\n",ans+1);
        }
    }
    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

struct Cake{
  ll sum, i, j, k;
  bool operator < (const Cake& other) const
  {
    return sum < other.sum;
  }
};

void solve()
{
  int x, y, z, k;
  //*
  cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  for(int i = 0; i < x; ++i) cin >> a[i];
  for(int i = 0; i < y; ++i) cin >> b[i];
  for(int i = 0; i < z; ++i) cin >> c[i];
  //*/

  /*
  x = y = z = 30;
  // k = min(3000, x*y*z);
  k = 5;
  vector<ll> a(x), b(y), c(z);
  for(int i = 1; i <= x; ++i)
  {
    a[i] = i;
    b[i] = i * 10;
    c[i] = i * 100;
  }
  //*/

  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end(), greater<ll>());

  set< tuple<ll, ll, ll> > seen;

  priority_queue<Cake> que;
  que.push( Cake{a[0] + b[0] + c[0], 0, 0, 0} );
  int cnt = 0;
  while(cnt++, cnt <= k)
  {
    Cake now = que.top();
    que.pop();
    cout << now.sum << endl;


    if (now.i + 1 < x && seen.find(make_tuple(now.i + 1, now.j, now.k)) == seen.end())
    {
      que.push( Cake{a[now.i + 1] + b[now.j] + c[now.k], now.i + 1, now.j, now.k} );
      seen.insert( make_tuple(now.i + 1, now.j, now.k) );
    }

    if (now.j + 1 < y && seen.find(make_tuple(now.i, now.j + 1, now.k)) == seen.end())
    {
      que.push( Cake{a[now.i] + b[now.j + 1] + c[now.k], now.i, now.j + 1, now.k} );
      seen.insert( make_tuple(now.i, now.j + 1, now.k) );
    }

    if (now.k + 1 < z && seen.find(make_tuple(now.i, now.j, now.k + 1)) == seen.end())
    {
      que.push( Cake{a[now.i] + b[now.j] + c[now.k + 1], now.i, now.j, now.k + 1} );
      seen.insert( make_tuple(now.i, now.j, now.k + 1) );
    }
  }

}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4072
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
    int n;cin>>n;
    vector<int>a(n);rep(i,n)cin>>a[i];
    int ans=0,b=0;
    rep(i,n){
        sort(a.begin(),a.end());
        if((i+1)%2){
            ans+=a[a.size()-1];
        }else{
            b+=a[a.size()-1];
        }
        a.pop_back();
    }
    cout<<ans-b<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

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

        int count = 0;
        String moji = "";

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

                if(split[i].equals(split[j])){
                    count++;
                }
            
            }
        }

        if(count == 8){
            System.out.println("Yes");    
        }
        else{
            System.out.println("No");
        }
        
    }


}

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

using namespace std;

main(){
  int data[10000];
  int n;
  while(1){
    cin >> n;
    if(n==0) break;
    for(int i=0;i<n;i++){
      cin >> data[i];
    }
    sort(data, data+n);
    long long sum=0;
    long long ans=0;
    for(int i=0;i<n;i++){
      ans+=sum;
      sum+=data[i];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
using namespace std;
int n, a[30], b[30], c[30], res;

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) cin >> b[i];
  for (int i = 1; i <= n - 1; ++i) cin >> c[i];
  for (int i = 1; i <= n; ++i) {
    res += b[a[i]];
    if (i < n && a[i + 1] - a[i] == 1) res += c[a[i]];
  }
  cout << res << '\n';
  return 0;
}

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

int main(int argc, const char * argv[])
{
    int A, B;
    cin >> A;
    cin >> B;
    
    int sub;
    int big, small;
    if (abs(A) > abs(B)) {
        big = A;
        small = B;
    }else {
        big = B;
        small = A;
    }
    
    sub = big - small;
    
    if (sub%2 != 0) {
        cout << "IMPOSSIBLE" << endl;
    }else {
        cout << (big - (sub / 2)) << endl;
    }
    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using ll = long long;
using namespace std;        
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define ar array


void solve(){
		ll n;cin>>n;n--;
	   	if(n==0){
			cout<<'a'<<endl;
			return;
		}	
		vector<char> name;
		while(n>0){
		  name.pb('a'+n%26);
		  n/=26;
		  n--;
		  if(n==0){
			  name.pb('a');
			  break;
		  }		  
		}
		reverse(name.begin(),name.end());
		for(auto x: name){
			cout<<x;
		}
		cout<<endl;		
		

}

int main(){
	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
//	freopen("input.txt",r,"stdin");
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}





Measured memory_bytes: 3580