akhauriyash/Code-Regression huggingface dataset:
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}




int main(){
    ll x,a;
    cin>>x>>a;
    cout<<(x<a?0:10)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))

    t = sum(A) * (1 / (4 * m))

    if all(item >= t for item in sorted(A, reverse=True)[:m]):
        print('Yes')
    else:
        print('No')
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 38492
n, m = map(int, input().split())
h = [int(i) for i in input().split()]
l = []
for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] == h[b - 1]:
        l.append(a)
        l.append(b)
    else:
        l.append(min(a, b, key=lambda x: h[x - 1]))
l = set(l)
print(n - len(l))

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

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //string[] str = Console.ReadLine().Split(' ');
            //int n = int.Parse(Console.ReadLine());

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

            long n = int.Parse(str[0]);
            long k = int.Parse(str[1]);

            long min = k * (k - 1) / 2;
            long max = k * n - min;

            long ans = max - min + 1;
            ans %= 1000000007;

            //Console.WriteLine("ans is {0}", ans);

            for(long i=k+1; i < n + 2; i++)
            {
                min += i - 1;
                max += n - i + 1;

                if(min>1000000007 && max > 1000000007)
                {
                    long temp = min / 1000000007;
                    min -= 1000000007*temp;
                    max -= 1000000007*temp;
                }
                ans += max - min + 1;
                ans %= 1000000007;
                //Console.WriteLine("i={0} のとき、min={1}, max={2}, ans={3}", i, min, max, ans);
                /*if (ans < 0)
                {
                    Console.WriteLine("yabai");
                    return;
                }*/
            }


            Console.WriteLine(ans);
        }
    }

}


Measured memory_bytes: 27476
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}

int main() {
	int a, b, c; cin >> a >> b >> c;
	if (c - (a - b) > 0) cout << c - (a - b);
	else cout << 0;



	cout << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split()))

s1 = 0
s2 = sum(w)
min_diff = s2

for x in w:
    x2 = x * 2
    if min_diff < x2:
        min_diff = min(x2 - min_diff, min_diff)
        break       
    min_diff -= x2
print(min_diff)


Measured memory_bytes: 61712
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
#include<iomanip>
using namespace std;

#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);

#define csh(a,n) memset(a,n,sizeof(a));

int main(){
	char arr[1010];
	cin>>arr;
	for(int i=0;i<strlen(arr);i++){
		cout<<'x';
	}
}

Measured memory_bytes: 256
#include<iostream>

int main(){
  int a[]={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};
  int k;
  std::cin>>k;
  std::cout<<a[k-1]<<std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    ll N; cin >> N;
    ll ans = 0;
    FOR(a,1,N) {
        auto b = N/a;
        if (N%a == 0) ans--;
        ans += b;
    }
    cout << ans << endl;
}

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

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


def dfs(V, start):
    q = [(start, 0)]
    used = [False] * (n+1)
    farthest = 0
    pos = 0

    while q:
        s, cost = q.pop()
        if farthest < cost:
            pos = s
            farthest = cost
        used[s] = True
        for t, c in V[s].items():
            if used[t]:
                continue
            q.append((t, cost + c))
    
    return farthest, pos


if __name__ == "__main__":
    n = int(input())
    V = {i:dict() for i in range(n)}

    for _ in range(n - 1):
        s, t, w = map(int, input().split())
        V[s][t] = w
        V[t][s] = w

    print(dfs(V, dfs(V, 0)[1])[0])



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

using namespace std;

int main() {
  int64_t A, B, C, K;
  cin >> A >> B >> C >> K;
  int64_t a = min(A, K);
  K -= a;
  int64_t b = min(B, K);
  K -= b;
  int64_t c = min(C, K);
  K -= c;

  int64_t answer = a - c;
  cout << answer << endl;

  return 0;
}


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

int main()
{
  int N;
  cin >> N;
  
  int ans;
  
  if(N<10)
    ans=N;
  
  if(N>=10&&N<100)
    ans=9;
  
  if(N>99&&N<1000)
    ans=N-100+10;
  
  if(N>999&&N<10000)
    ans=909;
  
  if(N>9999&&N<100000)
    ans=N-9999+909;
  
  if(N>99999&&N<1000000)
    ans=90909;
  
  cout << ans;
  
  return 0;
}


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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    int n;
    cin >> n;
    vl l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));

    int cnt = 0;
    rep(i, n) repeat(j, i + 1, n) repeat(z, j + 1, n) {
        if (l[i] != l[j] and l[j] != l[z] and l[i] + l[j] > l[z]) cnt++;
    }
    out(cnt);

    return 0;
}


Measured memory_bytes: 3632
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


def factorize(n):
    result = {1:1}
    i = 2
    x = n
    while i*i <= x:
        if n % i != 0:
            i += 1
            continue
        num = 0
        while n % i == 0:
            num += 1
            n = n / i
        result[i] = num
        i += 1
    if int(n) != 1:
        result[int(n)] = 1
    return result


A, B = map(int, input().split())
gcd_num = gcd(A, B)
print(len(factorize(gcd_num)))

Measured memory_bytes: 3064
N = int(input())
A = list(map(int,input().split()))
G = {i:A[i-1] for i in range(1,N+1)}
B = list(G.items())
B = sorted(B,key=lambda x:x[1])
C = [B[i][0] for i in range(len(B))]
print(*C)

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

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<int> b(n+1);
    for (int i = 0; i < n+1; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    b[n] = 0;

    int r = 0;
    ll m = 0;
    for (int i = 0; i < n+1; i++) {
        if (a[i] <= b[i] + r) {
            m += a[i];
            r = b[i] - max(a[i] - r, 0);
        } else {
            m += b[i] + r;
            r = 0;
        }
    }
    cout << m << endl;


    return 0;
}



Measured memory_bytes: 1024
a,b,c,d=map(int, input().split())
c_count = (b // c) -((a-1) // c )
d_count = (b // d) -((a-1) // d)
import fractions
cd  = (c * d) // fractions.gcd(c, d)
cd_count = (b // cd) -((a-1) // cd)
print(b-a+1-(c_count+d_count-cd_count))

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

ll nxt(ll n){
  ll add=0;
  ll nn = n;
  for (int i = 0; ; nn/=10,i++) {
    int d = nn % 10;
    if(d==7){
      add -= 4 * pow(10, i);
      continue;
    } else if(d==3 || d==5) {
      add += 2 * pow(10, i);
      break;
    } else {
      add += 3 * pow(10, i);
      break;
    }
  }

  return n+add;
}
  
bool valid(ll n){
  bool have[10]={false};
  for(;n;n/=10){
    have[n%10] = true;
  }

  return have[3] && have[5] && have[7];
}

ll next(ll n){
  while(true){
    n = nxt(n);
    if(valid(n)) return n;
  }
}

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

  int res;
  ll nn = 357;
  for (int i=0; ; nn=next(nn),i++) {
    if(n<nn){
      res=i;
      break;
    }
  }

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


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int R = in.nextInt();
			int G = in.nextInt();
			out.println((G - R) * 2 + R);
		}
	}
	
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000

int main() {
    int N; cin >> N;
    int t = 0, x = 0, y = 0;
    for (int i = 0; i < N; i++) {
        int tn, xn, yn; cin >> tn >> xn >> yn;
        int dst = abs(xn-x)+abs(yn-y);
        if (dst <= tn-t) {
            if ((tn-t)%2 == 0 && dst%2 != 0) {
                cout << "No" << endl;
                return 0;
            } else if ((tn-t)%2 != 0 && dst%2 == 0) {
                cout << "No" << endl;
                return 0;
            }
        } else {
            cout << "No" << endl;
            return 0;
        }
        t = tn; x = xn; y = yn;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.Linq;


namespace ConsoleApp1
{
    class Program
    {
        static void print(string s)
        {
            Console.WriteLine(s);
        }

        static string scan()
        {
            return Console.ReadLine();
        }

        static void Main(string[] args)
        {
            string[] lineArray = scan().Split(" ");
            int x = int.Parse(lineArray[0]);
            int n = int.Parse(lineArray[1]);

            if (n == 0)
            {
                print(x.ToString());
            }
            else
            {
                lineArray = scan().Split(" ");
                int[] p = new int[102];
                for (int i = 0; i < p.Length; i++)
                {
                    p[i] = i;
                }
                for (int i = 0; i < lineArray.Length; i++)
                {
                    p[int.Parse(lineArray[i])] = -1;
                }

                int point = 0;
                while (true)
                {
                    if (p[x - point] != -1)
                    {
                        print(p[x - point].ToString());
                        break;
                    }
                    if (p[x + point] != -1)
                    {
                        print(p[x + point].ToString());
                        break;
                    }
                    point++;
                }
            }
        }
    }
}


Measured memory_bytes: 27488
#include <bits/stdc++.h>
//#include "atcoder/all"
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const ll mod = 1e9 + 7;
int main() {
  int s;
  string k;
  cin >> k >> s;

  vector<string> ss;

  for (int i = 0; i < k.size(); i++) {
    string temp;
    for (int j = i; j < k.size(); j++) {
      temp.push_back(k[j]);

      if (temp.size() <= s) ss.push_back(temp);
    }
  }

  auto func = [&](string a, string b) { return a < b; };

  sort(ss.begin(), ss.end(), func);
  ss.erase(unique(ss.begin(), ss.end()), ss.end());

  cout << ss[s - 1] << endl;
}

Measured memory_bytes: 4228
def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split())) if N else []

    ans = X

    for i in range(100):
        if X-i not in P:
            ans = X-i
            break
        if X+i not in P:
            ans = X+i
            break

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
   ll a, b;
   cin >> a >> b;
   cout << max(a+b, max(a-b, a*b));
}

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

float ans;
int r;
int main(){
	cin>>r;
	ans=r*2*3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647;
	cout<<(ans)<<"\n";
}

Measured memory_bytes: 3784
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce

N = a_int()
A = ints()
ans=0
for a in A[::2]:
    ans += a & 1
print(ans)


Measured memory_bytes: 68148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll A[N];
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  ll ans[N];
  ll oddsum = 0;
  for (int i = 1; i < N; i+=2) {
    oddsum += A[i];
  }
  ans[0] = sum - (oddsum * 2);
  for (int i = 0; i < N - 1; i++) {
    ans[i + 1] = (2 * A[i]) - ans[i];
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i] << " ";
  }
  return 0;
}

Measured memory_bytes: 5136
#include<bits/stdc++.h>
using namespace std;
const int N=100050;
int n,k,cnt,ans,p=1;
string s;
vector<int> vec;

int main()
{
cin>>n>>k>>s;
cnt=(s[0]=='0');
  for (int i=0; i<n; i++)
  {
	if(i && s[i]=='1' && s[i-1]=='0')
	  cnt--;
	while(p<n)
	{
	  if(s[p-1]==s[p])
		p++;
	  else if(s[p]=='1')
		p++;
	  else if(cnt<k)
		cnt++,p++;
	  else
		break;
	}
	ans=max(ans,p-i);
  }
cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
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; }

int main(){
  int n;
  cin >> n;
  vl a(n);
  rep(i,n) cin >> a.at(i);
  vl sum(n+1,0);
  rep(i,n){
    sum.at(n-1-i) = sum.at(n-i) + a.at(n-1-i);
    sum.at(n-1-i) %= MOD;
  }
  long ans = 0;
  rep(i,n){
    ans += a.at(i) * sum.at(i+1) % MOD;
  }
  cout << ans % MOD << endl;
}

Measured memory_bytes: 6424
object Main extends App {
    val hands = List("Rock", "Fire", "Scissors", "Snake", "Human", "Tree", "Wolf", "Sponge", "Paper", "Air", "Water", "Dragon", "Devil", "Lightning", "Gun") 
    val in = io.Source.stdin.getLines
    for (n <- in if n != "0") {
        val x = in.take(n.toInt).map(h => hands.indexWhere(h == _)).toList
        val y = x.map(i => (i+1 to i+7).map(_%15)).flatten.distinct
        x.filterNot(y.contains _) match {
            case z@(h::_) if z.size != n.toInt => println(hands(h))
            case _ => println("Draw")
        }
    }
}

Measured memory_bytes: 87212
n, m, q = gets.split.map(&:to_i)
arr1 = gets.split.map(&:to_i)
arr2 = gets.split.map(&:to_i)
baton, member = 0, [*0...n]

m.times do |i|
  baton = arr1[i].even? ? (baton + arr1[i]) % (n - i) : (baton - arr1[i]) % (n - i)
  member.delete_at(baton)
end

arr2.each do |elm|
  puts member.include?(elm) ? 1 : 0
end

Measured memory_bytes: 24000
encode = {"A"=>"00000","B"=>"00001","C"=>"00010","D"=>"00011","E"=>"00100","F"=>"00101","G"=>"00110","H"=>"00111","I"=>"01000",
  "J"=>"01001","K"=>"01010","L"=>"01011","M"=>"01100","N"=>"01101","O"=>"01110","P"=>"01111","Q"=>"10000",
  "R"=>"10001","S"=>"10010","T"=>"10011","U"=>"10100","V"=>"10101","W"=>"10110","X"=>"10111","Y"=>"11000",
  "Z"=>"11001"," "=>"11010","."=>"11011",","=>"11100","-"=>"11101","'"=>"11110","?"=>"11111"}
decode ={"101"=>" ","000000"=>"'","000011"=>",","10010001"=>"-","010001"=>".","000001"=>"?","100101"=>"A","10011010"=>"B",
  "0101"=>"C","0001"=>"D","110"=>"E","01001"=>"F","10011011"=>"G","010000"=>"H","0111"=>"I","10011000"=>"J",
  "0110"=>"K","00100"=>"L","10011001"=>"M","10011110"=>"N","00101"=>"O","111"=>"P","10011111"=>"Q","1000"=>"R","00110"=>"S","00111"=>"T",
  "10011100"=>"U","10011101"=>"V","000010"=>"W","10010010"=>"X","10010011"=>"Y","10010000"=>"Z"}
while line = gets
  if line.chomp==""
    puts ""
    next
  end
  input=line.chomp.split("")
  str =""
  input.each do |c|
    str+=encode[c]
  end
  str = str.split("")
  i=0
  j=7
  ans =""
  while i<str.size
    tmp = str[i..i+j].join("")
    if decode.include?(tmp)
      ans << decode[tmp]
      i+=j+1;
      j=7
    elsif tmp==""
      break
    else
      j-=1
    end
  end
  puts ans
end

Measured memory_bytes: 2768
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int main(){
  int A;
  int B;
  int C;
  rd(A);
  rd(B);
  rd(C);
  if(A==B && B==C){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// {
//   int A,B,C;
//   rd(A,B,C);
//   wt(if[A==B==C, "Yes", "No"]);
// }


Measured memory_bytes: 256
def calc(N, A):
    _exist = False
    counter = {}
    for a in A:
        counter[a] = 1 + (counter[a] if a in counter else 0)
    if (N % 3 == 0 and len(counter) == 3):
        keys = list(counter.keys())
        values = list(counter.values())
        d = max(values) - min(values)
        _exist = d == 0 and keys[0] ^ keys[1] == keys[2]
    elif (N % 3 == 0 and len(counter) == 2):
        keys = list(counter.keys())
        values = list(counter.values())
        d = max(values) - min(values)
        _exist = d == N // 3 and (keys[0] == 0 or keys[1] == 0)
    else:
        _exist = 0 in counter and counter[0] == N
    print('Yes' if _exist else 'No')


N = int(input())
A = [int(s) for s in input().split(' ')]
calc(N, A)

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INF = 2147483647;
const long long LINF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

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

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

int main(void){
    ll N,K; cin >> N >> K;
    ll ans = 0;
    REP(i,N){
        ll b = i+1;
        ans += (N+1)/b * max((ll)0, b-K);
        ll q = (N+1)%b;
        ans += max((ll)0, q-K);
    }
    if(K == 0) ans -= N;
    cout << ans << endl;
    return 0;
}

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

#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n-1; i >= (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
// #define M_PI 3.14159265358979323846 // CFでは定義しておく必要あり
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

void print() {
  cout << endl;
};

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
};

const ll tmp = 1e18;

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

  ld a;
  ld b;
  cin >> a >> b;
  ld ans = a * b;
  ans = floor(ans);
  cout << fixed << setprecision(0) << ans << endl;


  return 0;
};


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

int main(void)
{
  ll k;
  cin >> k;
  deque<ll> q;
  if (k < 10)
  {
    cout << k << endl;
    return 0;
  }
  rep(i, 9) q.emplace_back(i + 1);
  k -= 9;
  while (k != 0)
  {
    ll i = q.front();
    q.pop_front();
    for (int j = max(ll(0), i % 10 - 1); j < min(ll(10), i % 10 + 2); ++j)
    {
      q.emplace_back(10 * i + j);
      --k;
      if (k == 0)
      {
        cout << q.back() << endl;
        return 0;
      }
    }
  }
  cout << q.back() << endl;
  return 0;
}

Measured memory_bytes: 4124
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct node *link;

struct node
{
	int key;
	link parent,left,right;
};

link root;
link in;

void insert(link z)
{
	link p=NULL;
	link x=root;
	while(x!=NULL)
	{
		p=x;
		if(z->key<x->key)
		{
			x=x->left;
		}
		else
		{
			x=x->right;
		}
		z->parent=p;
	}
	if(p==NULL)
	{
		root=z;
	}
	else if(z->key<p->key)
	{
		p->left=z;
	}
	else
	{
		p->right=z;
	}
}

void traverse1(link a)
{
	if(a==NULL) return;
	printf(" %d",a->key);
	traverse1(a->left);
	traverse1(a->right);
}

void traverse2(link a)
{
	if(a==NULL) return;
	traverse2(a->left);
	printf(" %d",a->key);
	traverse2(a->right);
}

void find(link a,int k)
{
	while(a!=NULL&&k!=a->key)
	{
		if(k<a->key)
		{
			a=a->left;
		}
		else
		{
			a=a->right;
		}
	}
	if(a!=NULL)
	{
		printf("yes\n");
	}
	else
	{
		printf("no\n");
	}
}

void delete(int a)
{
	link p=NULL;
	link x=root;
	link next;
	int f=0;
	while(x!=NULL&&a!=x->key)
	{
		p=x;
		if(a<x->key)
		{
			x=x->left;
		}
		else
		{
			x=x->right;
		}
	}
	if(x!=NULL)
	{
		if(x->left==NULL&&x->right==NULL)
		{
			if(a<p->key)
			{
				p->left=NULL;
			}
			else
			{
				p->right=NULL;
			}
		}
		else if(x->left==NULL)
		{
			if(a<p->key)
			{
				p->left=x->right;
			}
			else
			{
				p->right=x->right;
			}
		}
		else if(x->right==NULL)
		{
			if(a<p->key)
			{
				p->left=x->left;
			}
			else
			{
				p->right=x->left;
			}
		}
		else
		{
			p=x;
			next=x->right;
			if(next->left==NULL)
			{
				f=1;
			}
			while(next->left!=NULL)
			{
				p=next;
				next=next->left;
			}
			x->key=next->key;
			if(next->right==NULL)
			{
				if(f==0)
				{
					p->left=NULL;
				}
				else
				{
					p->right=NULL;
				}
			}
			else
			{
				if(f==0)
				{
					p->left=next->right;
				}
				else
				{
					p->right=next->right;
				};
			}
		}
	}
}

int main(void)
{
	root=NULL;

	int i,num,N;
	char get[10];

	scanf("%d",&N);

	for(i=0;i<N;i++)
	{
		scanf("%s",get);

		if(strcmp(get,"insert")==0)
		{
			scanf("%d",&num);
			in=malloc(sizeof(*in));
			in->key=num;
			in->left=NULL;
			in->right=NULL;
			in->parent=NULL;
			insert(in);
		}
		else if(strcmp(get,"print")==0)
		{
			traverse2(root);
			printf("\n");
			traverse1(root);
			printf("\n");
		}
		else if(strcmp(get,"find")==0)
		{
			scanf("%d",&num);
			find(root,num);
		}
		else if(strcmp(get,"delete")==0)
		{
			scanf("%d",&num);
			delete(num);
		}
	}

	return 0;
}



Measured memory_bytes: 20484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(string A){
	map<ll, ll> m;
	rep(i, A.length()) {
		m[A[i]-'a']++;
	}
	ll res = A.length()*(A.length()-1)/2;
	rep(i, 26) {
		res -= m[i]*(m[i]-1)/2;
	}
	res++;
	cout << res << endl;
}

int main(){	
	string A;
	cin >> A;
	solve(A);
	return 0;
}



Measured memory_bytes: 772
# coding: utf-8
N, M = map(int, input().split())
d = {}
ans = ["0" for _ in range(N)]
for i in range(M):
    s, c = map(int, input().split())
    if str(s) not in d.keys():
        d[str(s)] = c
        ans[s-1] = str(c)
    else:
        if d[str(s)] != c:
            print(-1)
            exit()
if N == 1:
    print("".join(ans))
    exit()
if "1" not in d.keys():
    ans[0] = "1"
ans = "".join(ans)
if ans[0] == "0" and N != 1:
    print(-1)
else:
    print(int(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const ll MAX_N=2e5+10;
ll par[MAX_N];
ll RANK[MAX_N];

void init(ll n){
    for(ll i=0;i<n;i++){
        par[i]=i;
        RANK[i]=0;
    }
}

ll find(ll x){
    if(par[x]==x){
        return x;
    }
    else {
        return par[x]=find(par[x]);
    }
}

void unite(ll x,ll y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(RANK[x]<RANK[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(RANK[x]==RANK[y])RANK[x]++;
    }
}

bool same(ll x,ll y){
    return find(x)==find(y);
}

int main() {
    ll N,M;
    cin >> N >> M;
    ll a,b;
    vector<ll>A,B;
    for(ll i=0;i<M;i++){
        cin >> a >> b;
        a--;b--;
        A.push_back(a);
        B.push_back(b);
    }
    init(N);
    for(ll i=0;i<M;i++){
        unite(A[i],B[i]);
    }
    vector<ll>C(N,0);
    for(ll i=0;i<N;i++){
        C[find(i)]++;
    }
    ll ans=0;
    for(ll i=0;i<N;i++){
        ans=max(ans,C[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 11068
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600

inline int code(string s){
  int ret=0;
  for(auto c : s) ret = ret*100 + c;
  return ret;
}

set<int> s;

bool dfs(string str, int d, int p){
  if(d==0){
    cout << str << endl;
    return true;
  }
  str.pb('a');
  int l = str.size();
  rep(i,26){
    if(l>=p && s.count(code(str.substr(l-p)))){}
    else if(dfs(str, d-1, p)) return true;
    str[l-1]++;
  }
  return false;
}

int main(){
  int n;
  cin>>n;
  vector<string> vec(n);
  rep(i,n) cin>>vec[i];

  repl(i,1,6){
    s.clear();
    for(auto &str : vec){
      int l = str.size();
      rep(j,l-i+1) s.insert(code(str.substr(j,i)));
    }
    if(dfs("", i, i)) break;
  }

  return 0;
}

Measured memory_bytes: 21824
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#define rep(index,num) for(int index=0;index<num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
int main(){
	int N,K;
	scan(N); scan(K);
	if(N%K==0){
		prin("0");
	}
	else{
		prin("1");
	}
	return 0;
}


Measured memory_bytes: 256
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

fn dfs(a: &mut Vec<usize>, i: usize, k: &mut usize, is_zero: bool) {
    if i == a.len() {
        if *k == 1 {
            let mut tmp = 0u64;
            for j in 0..a.len() {
                tmp *= 10;
                tmp += a[j] as u64;
            }
            println!("{}", tmp);
        }
        if *k != 0 {
            *k -= 1;
        }
    } else {
        if is_zero {
            for j in 0..=9 {
                a[i] = j;
                dfs(a, i + 1, k, j == 0);
            }
        } else {
            if a[i - 1] != 0 {
                a[i] = a[i - 1] - 1;
                dfs(a, i + 1, k, false);
            }
            a[i] = a[i - 1];
            dfs(a, i + 1, k, false);
            if a[i - 1] != 9 {
                a[i] = a[i - 1] + 1;
                dfs(a, i + 1, k, false);
            }
        }
    }
}

//#[proconio::fastout]
fn main() {
    input! {
        mut k: usize,
    }

    let mut a = vec![0; 11];
    k += 1;
    dfs(&mut a, 1, &mut k, true);
}


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

unsigned gaps[] = {1,8,23,77,281,1073,4193,16577,65921,262913,1050113};
// generated from pow(4,i)+3*pow(2,i-1)+1 (prefixed with 1)

unsigned insertion_sort(unsigned a[], unsigned n, unsigned gap){
  unsigned count = 0;
  for(unsigned i = gap; i < n; i++){
    unsigned v = a[i];
    int j = i - gap;
    while(j >= 0 && a[j] > v){
      a[j+gap] = a[j];
      j -= gap;
      count++;
    }
    a[j+gap] = v;
  }
  return count;
}

void shell_sort(unsigned a[], unsigned n){
  uint8_t gap_num = 11;
  while(gaps[--gap_num] > n);

  unsigned count = 0;
  for(int8_t i = gap_num; i >= 0; i--) count += insertion_sort(a,n,gaps[i]);

  cout << (gap_num+1) << '\n';

  for(int8_t i = gap_num; i; i--) cout << gaps[i] << ' ';
  cout << gaps[0] << '\n';

  cout << count << '\n';
}

int main(){
  std::ios::sync_with_stdio(false);
  unsigned n,i;
  cin >> n;
  auto a = new unsigned[n];
  for(i = 0; i < n; i++) cin >> a[i];
  shell_sort(a,n);
  for(i = 0; i < n; i++) cout << a[i] << '\n';
  delete[](a);
}

Measured memory_bytes: 4956
N = int(input())
SP = [[i+1] + [int(x) if x.isdigit() else x for x in input().split()]
      for i in range(N)]

SP = sorted(sorted(SP, key=lambda e: e[2], reverse=True), key=lambda e: e[1])

for i, _, _ in SP:
    print(i)


Measured memory_bytes: 3060
# sを文字列として取得
s = gets.chomp
# tを文字列として取得
t = gets.chomp

# if s == t[0..-2]であればyesと出力
if s.eql?(t[0..-2])
  puts "Yes"
# if s !== t[0..-2]であればnoと出力
else
  puts "No"
end

Measured memory_bytes: 14252
x, y = map(int, input().split())
total = 0
data = [x, y]

for d in data:
    if d==1:
        total += 300000
    elif d==2:
        total += 200000
    elif d==3:
        total += 100000

if (x==1)and(y==1):
    total += 400000
print(total)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int min_index(int *a,int n){
    int result=0;
    int temp = a[0];
    for(int i=1;i<n;i++){
        if(a[i]<temp){temp = a[i];result=i;}
    }
    return result;
}

int main(){
    int N,T,A;
    cin >> N >> T >> A;

    int h[N];
    int tx[N];
    for(int i=0;i<N;i++){
        cin >> h[i];
        tx[i] = A*1000 - (T*1000 - h[i]*6);
        if(tx[i]<0)tx[i] *= -1;
        //cout << tx[i] <<endl; 
    }

    cout << min_index(tx,N)+1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int w,h;
char l[55][55],r[55][55];
int alr[55][55][55][55];
int lsy,lsx,rsy,rsx,ley,lex,rey,rex;

int main(){
	while(1){
		cin>>w>>h;
		if(w==0&&h==0)break;
		REP(i,55)
			REP(j,55)
				REP(k,55)
					REP(l,55)
					alr[i][j][k][l]=0;
		REP(i,h){
			REP(j,w){
				cin>>l[i][j];
				if(l[i][j]=='%'){
					ley=i;
					lex=j;
				}else if(l[i][j]=='L'){
					lsy=i;
					lsx=j;
				}
			}
			REP(j,w){
				cin>>r[i][j];
				if(r[i][j]=='%'){
					rey=i;
					rex=j;
				}else if(r[i][j]=='R'){
					rsy=i;
					rsx=j;
				}
			}
		}
		queue<pair<Pi,Pi>> qq;
		qq.push(pair<Pi,Pi>(Pi(lsy,lsx),Pi(rsy,rsx)));
		alr[lsy][lsx][rsy][rsx]=1;
		int ans=0;
		while(qq.size()){
			pair<Pi,Pi> p1=qq.front();qq.pop();
			int ly=p1.first.first;
			int lx=p1.first.second;
			int ry=p1.second.first;
			int rx=p1.second.second;
			//cout<<ly<<" "<<lx<<" "<<ry<<" "<<rx<<endl;
			if(ly==ley&&lx==lex&&ry==rey&&rx==rex){
				ans=1;
				break;
			}
			if((ly==ley&&lx==lex)||(ry==rey&&rx==rex)){
				continue;
			}
			for(int i=0;i<4;i++){
				int nly=ly+dy[i];
				int nlx=lx+dx[i];
				if(!(0<=nly&&nly<h&&0<=nlx&&nlx<w&&l[nly][nlx]!='#')){
					nly=ly;
					nlx=lx;
				}
				int nry=ry+mdy[i];
				int nrx=rx+mdx[i];
				if(!(0<=nry&&nry<h&&0<=nrx&&nrx<w&&r[nry][nrx]!='#')){
					nry=ry;
					nrx=rx;
				}
				if(!alr[nly][nlx][nry][nrx]){
					qq.push(pair<Pi,Pi>(Pi(nly,nlx),Pi(nry,nrx)));
					alr[nly][nlx][nry][nrx]=1;
				}
			}
		}
		if(ans)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}
			


Measured memory_bytes: 40600
#include <stdio.h>

int main(void)
{
    char n[4];
    int i, num = 0;
    scanf("%s", n);
    for (i = 0; i < 4; i++)
    {
        if (n[i] == '+')
        {
            num++;
        }
        else if (n[i] == '-')
        {
            num--;
        }
    }

    printf("%d\n", num);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

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

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

	if (a[1]==a[0] && a[0] == 5 && a[2] == 7) {
		cout << "YES" << endl;
	}

	else {
		cout << "NO" << endl;
	}

	return 0;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(3e3 + 5);
const int MAX_T = (int)(3e3 + 5);

int n, t;

vector<pair<int, int>> ab;

int dp_l[MAX_N][MAX_T];

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &t);

  for (int i = 0; i < n; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    ab.push_back(make_pair(a, b));
  }

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

  ab.insert(ab.begin(), make_pair(-1, -1));

  for (int i = 1; i <= n; ++i) {
    for (int c = 1; c <= t; ++c) {
      if (c < ab[i].first) {
        dp_l[i][c] = dp_l[i - 1][c];
      } else {
        dp_l[i][c] = max(dp_l[i - 1][c], dp_l[i - 1][c - ab[i].first] + ab[i].second);
      }
    }
  }

  int ans = -1;

  for (int i = 1; i <= n; ++i) {
    ans = max(ans, dp_l[i - 1][t - 1] + ab[i].second);
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 35584
#include<iostream>
#include<vector>
#include <cfenv>
#include <cmath>
#include <utility>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

typedef pair<int, int> pair;

int main(){
    ll N,A,B,C;
    cin >> N >> A >> B >> C;
    vector<string> s(N,"");
    string T[N];
    for (int i = 0; i < N; i++){
        cin >> s[i];
    }
    for (int i = 0; i < N; i++){
        if(s[i] == "AB"){
            if(A > B){
                A--;
                B++;
                T[i] = 'B';
            }else if(A < B){
                A++;
                B--;
                T[i] = 'A';
            }else{
                if(i == N-1){
                    A--;
                    B++;
                    T[i] = 'B';
                }else if(s[i+1] == "AC"){
                    A++;
                    B--;
                    T[i] = 'A';
                }else if(s[i+1] == "BC"){
                    A--;
                    B++;
                    T[i] = 'B';
                }else{
                    A++;
                    B--;
                    T[i] = 'A';
                }
            }
        }else if (s[i] == "AC"){
            if(A > C){
                A--;
                C++;
                T[i] = 'C';
            }else if(A < C){
                A++;
                C--;
                T[i] = 'A';
            }else{
                if(i == N-1){
                    A--;
                    C++;
                    T[i] = 'C';
                }else if(s[i+1] == "AB"){
                    A++;
                    C--;
                    T[i] = 'A';
                }else if(s[i+1] == "BC"){
                    A--;
                    C++;
                    T[i] = 'C';
                }else{
                    A++;
                    C--;
                    T[i] = 'A';
                }
            }
        }else{
            if(B > C){
                B--;
                C++;
                T[i] = 'C';
            }else if(B < C){
                B++;
                C--;
                T[i] = 'B';
            }else{
                if(i == N-1){
                    B--;
                    C++;
                    T[i] = 'C';
                }else if(s[i+1] == "AC"){
                    B--;
                    C++;
                    T[i] = 'C';
                }else if(s[i+1] == "AB"){
                    B++;
                    C--;
                    T[i] = 'B';
                }else{
                    B++;
                    C--;
                    T[i] = 'B';
                }
            }
        }
        if(A < 0 || B < 0 || C < 0){
            cout << "No" << endl;
            return 0;
        }
    } 
    if(A>=0 && B>=0 && C>=0){
        cout << "Yes" << endl;
        for(int i=0; i<N; i++){
            cout << T[i] << endl;
        }
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 9544