akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 50;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N;
    vec a(N);
    S = "YES";
    ll sum = 0;
    rep(i,N){
        cin>>a[i];
        sum += a[i];
    }
    if(sum%(N*(N+1)/2) != 0) S = "NO";
    ll num = sum / (N*(N+1)/2), freq = num;
    rep(i,N){
        ll temp = a[i] + num - a[(i+1)%N];
        if(temp < 0 || temp%N != 0) S = "NO";
        freq -= temp/N;
    }
    if(freq != 0) S = "NO";
    cout<<S<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

int main(){
  string a,b;
  cin>>a>>b;
  if(a.size()>b.size())cout<<"GREATER"<<endl;
  else if(a.size()<b.size())cout<<"LESS"<<endl;
  else if(a.size()==b.size()){
    for(int i=0;i<a.size();i++){
      
      if(a[i]>b[i]){
	cout<<"GREATER"<<endl;
	return 0;
      }else if(a[i]<b[i]){
	cout<<"LESS"<<endl;
	return 0;
      }
    }
    cout<<"EQUAL"<<endl;
    
  } else cout<<"EQUAL"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;


int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   long int n;
   cin>>n;

   map<long int,long int> m;

   for(long int i = 0; i < n - 1; i++){
    long int x;
    cin>>x;
    m[x]++;
   }

   for(long int i = 1; i <= n; i++)
    cout<<m[i]<<endl;
   return 0;
}

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

#define LL long long

#define FOR(INDEX, START, END) for (int INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (int INDEX = 0; INDEX < (COUNT); ++INDEX)

int main()
{
	LL N, M;
	cin >> N >> M;

	map<int, int> counts;
	REP(i, N) {
		LL K;
		cin >> K;
		REP(t, K) {
			LL v;
			cin >> v;
			counts[v]++;
		}
	}

	int result = 0;
	for (auto p : counts) {
		if (p.second == N) {
			result++;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		boolean l = 1 <= S / 100 && S / 100 <= 12, r = 1 <= S % 100 && S % 100 <= 12;
		if (l && r) System.out.println("AMBIGUOUS");
		else if (l && !r) System.out.println("MMYY");
		else if (!l && r) System.out.println("YYMM");
		else System.out.println("NA");
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

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

		String st = s.next();

		char[] cs = st.toCharArray();

		int max = 0;
		int tmp = 0;

		for (char c : cs) {
			if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
				tmp++;
			} else {
				if (tmp > max) {
					max = tmp;
				}
				tmp = 0;
			}
		}

		System.out.println(max < tmp ? tmp : max);
	}
}

Measured memory_bytes: 23764
#pragma GCC optimize("trapv")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>

using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 + 100, INF = 1e9 + 10, MOD = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 100;
int lp[N + 1];
vector<ll> s;

signed main()
{
    fastInp;

    ll n;
    cin >> n;

    vector<ll> vec(n);
    for (int i = 0; i < n; i++) cin >> vec[i];

    for (ll i = 2; i <= N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            s.push_back(i);
        }
        for (ll j = 0; j < (ll)s.size() && s[j] <= lp[i] && i*s[j] <= N; ++j)
            lp[i * s[j]] = s[j];
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < s.size(); j++) {
            while (vec[i] % (s[j] * s[j] * s[j]) == 0) {
                vec[i] /= (s[j] * s[j] * s[j]);
            }

            ll q = (s[j] * s[j] * s[j]);
            if ((s[j] * s[j] * s[j]) > (SIZE * SIZE)) {
                break;
            }
        }
    }

    ll ans = 0;

    map<ll, ll> cnt;
    for (int i = 0; i < n; i++) {
        cnt[vec[i]]++;
    }

    ll add = 0;
    set<ll> usd;
    for (auto cur : cnt) {
        ll vl = cur.first, sv = cur.first;
        if (usd.find(cur.first) != usd.end()) continue;
        if (vl > SIZE) {
            add += cur.second;
            continue;
        }
        map<ll, ll> dls;
        while (vl != 1) {
            dls[lp[vl]]++;
            vl /= lp[vl];
        }

        ll snd = 1;
        for (auto cur : dls) {
            ll am = 3 - cur.second % 3;

            if (am == 1) snd *= cur.first;
            if (am == 2) snd *= cur.first * cur.first;
        }

        usd.insert(sv);
        usd.insert(snd);
        if (sv == 1) {
            add++;
            continue;
        }
        if (cnt.find(snd) == cnt.end()) {
            add += cnt[sv];
            continue;
        }
        add += max(cnt[sv], cnt[snd]);
    }

    cout << ans + add;
    return 0;
}

Measured memory_bytes: 17656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

template <class U>
inline void dkstr(vector<vector<pair<int,U>>>& v,int n,int s,vector<U>& d,U inf){
    d.resize(n,inf);
    d[s]=0;
    vector<bool> vis(n);
    priority_queue<pair<U,int>,vector<pair<U,int>>,greater<>> pq;
    pq.emplace(0,s);
    while(!pq.empty()){
        pair<U,int> p=pq.top();pq.pop();
        U D=p.first;
        int i=p.second;
        if(vis[i]) continue;
        vis[i]=1;
        for(auto q:v[i]){
            if(vis[q.first]) continue;
            if(d[q.first]<=D+q.second) continue;
            d[q.first]=D+q.second;
            pq.emplace(D+q.second,q.first);
        }
    }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,s,a,b,w;
    cin>>n>>m>>s;
    vector<vector<pair<int,ll>>> v(n);
    fr(i,m){
        cin>>a>>b>>w;
        v[a].emplace_back(b,w);
    }
    vector<ll> d;
    dkstr(v,n,s,d,LONG_LONG_MAX);
    fr(i,n){
        if(d[i]<LONG_LONG_MAX) cout<<d[i]<<endl;
        else cout<<"INF"<<endl;
    }
}


Measured memory_bytes: 19356
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define iso ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int main()
{
    iso;
     ll n;
     cin>>n;  ll sum=0;
     for(ll i=1;i*(i+1)<n;i++)
        {   if(n%i==0)
		      sum+=n/i-1; 
          	
		 } 
	 cout<<sum;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}


const int MAX_N = 505;
int t[MAX_N][MAX_N];
int ex[MAX_N][MAX_N];

int main2() {
  int N = nextInt();

  vector<int> P(N * N);
  REP(i, N * N) P[i] = nextInt() - 1;

  REP(i, N) {
    REP(j, N) {
      int d = N + 1;
      chmin(d, i);
      chmin(d, j);
      chmin(d, N-1-i);
      chmin(d, N-1-j);
      t[i][j] = d;
      ex[i][j] = 1;
    }
  }

  const int di[4] = {0, 1, 0, -1};
  const int dj[4] = {1, 0, -1, 0};

  int ans = 0;
  REP(pi, N*N) {

    int i = P[pi] / N;
    int j = P[pi] % N;
    ans += t[i][j];
    ex[i][j] = 0;

    queue<int> q;
    q.push(i);
    q.push(j);
    while (!q.empty()) {
      i = q.front(); q.pop();
      j = q.front(); q.pop();
      REP(d, 4) {
        int ni = i + di[d];
        int nj = j + dj[d];
        if (0 <= ni && ni < N && 0 <= nj && nj < N) {
          if (t[ni][nj] > t[i][j] + ex[i][j]) {
            t[ni][nj] = t[i][j] + ex[i][j];
            q.push(ni);
            q.push(nj);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	int ans = (int)1e9;
	for (int target = -100; target <= 100; target++) {
		int tmp = 0;
		for (auto x : a) {
			tmp += (target - x) * (target - x);
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;

	return 0;
}

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



int main() {
    int N;
    cin>>N;
    vector<string> s(N);
    rep(i,N)cin>>s.at(i);
    rep(i,N){
        sort(s.at(i).begin(),s.at(i).end());
    }
    sort(s.begin(),s.end());
    string now=s.at(0);
    ll ans=0;
    ll same=1;
    rep(i,N-1){
        if(now==s.at(i+1)){same++;}
        else{ans+=same*(same-1)/2;now=s.at(i+1);same=1;}
    }
    ans+=same*(same-1)/2;
    cout<<ans<<endl;
}

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

int func(int n) {
    if (n == 0) {
        return 0;
    }
    return func(n-1) + n;
}

int main() 
{
    int A,B;
    cin >> A >> B;
    cout << func(B-A)-B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int inf=1e9;
const double PI=acos(-1);
const double eps=1e-6;
const int mod=1e9+7;
const int maxn=1e5+10;
int a[11],k;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	for(int i=1;i<=5;i++) cin>>a[i];
	cin>>k;
	for(int i=1;i<=5;i++){
		for(int j=i+1;j<=5;j++){
			if(abs(a[j]-a[i])>k){
				cout<<":("<<endl;
				return 0;
			}
		}
	}
	cout<<"Yay!"<<endl;
	return 0;
}

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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

signed main() {
    int A,B,C;
    cin>>A>>B>>C;
    cout<<max(0LL,C-(A-B))<<endl;
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
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);
        AKenKenRace solver = new AKenKenRace();
        solver.solve(1, in, out);
        out.close();
    }

    static class AKenKenRace {
        static final String YES = "Yes";
        static final String NO = "No";
        static final char ROCK = '#';

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            int a = in.nextInt() - 1, b = in.nextInt() - 1, c = in.nextInt() - 1, d = in.nextInt() - 1;

            char[] s = in.next().toCharArray();

            for (int i = a; i + 1 < c; i++) {
                if (s[i] == ROCK && s[i + 1] == ROCK) {
                    out.println(NO);
                    return;
                }
            }
            for (int i = b; i + 1 < d; i++) {
                if (s[i] == ROCK && s[i + 1] == ROCK) {
                    out.println(NO);
                    return;
                }
            }

            if (c < d) {
                out.println(YES);
                return;
            }

            for (int i = b; i <= d; i++) {
                if (i - 1 >= 0 && i + 1 < n && s[i - 1] != ROCK && s[i] != ROCK && s[i + 1] != ROCK) {
                    out.println(YES);
                    return;
                }
            }

            out.println(NO);
        }

    }

    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: 26068
import sys
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    C = input().strip()

    cnt = collections.Counter(C)

    ans = min(cnt["W"], cnt["R"])

    if N <= 2:
        print(ans)
        return

    tmp = 0
    for i in range(N):
        if cnt["R"] == 0:
            break
        if C[i] == "W":
            cnt["R"] -= 1
            tmp += 1
        else:
            cnt["R"] -= 1

    ans = min(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9764
N = int(input())
def shime(s):
    if int(s) > N:
        return 0
    if '7' in s and '5' in s and '3' in s:
        tmp = 1
    else:
        tmp = 0
    tmp += shime(s+'7')
    tmp += shime(s+'5')
    tmp += shime(s+'3')
    return tmp
print(shime('0'))

Measured memory_bytes: 3060
N, A, B = map(int, input().split())
S = input()
cnt = 0
over = 0
for i in range(N):
    # print(S[i])
    if S[i] == 'c':
        print('No')
        continue
    if S[i] == 'a':
        if cnt < A + B:
            print('Yes')
            cnt += 1
        else:
            print('No')
    else:
        if cnt < A + B:
            if over + 1 <= B:
                print('Yes')
                cnt += 1
                over += 1
            else:
                print('No')
        else:
            print('No')

Measured memory_bytes: 52824
using System;
using System.Numerics;
using System.Linq;

class Program
{
    static long MOD = 1000000000 + 7;


    static void Main(string[] args)
    {

        var l1 = ReadLongArray();

        long N = l1[0];
        long a = l1[1];
        long b = l1[2];

        long numMax = Math.Min(N, 200000);
        long total = Pow_mod(2, N, MOD) -1;
        total -= Combination(N, a, MOD);
        if (total < 0) total += MOD;

        total -= Combination(N, b, MOD);
        if (total < 0) total += MOD;

        var result = total;

        Console.WriteLine(result);
    }


    /// <summary>
    /// 剰余指定がある場合のべき乗計算
    /// </summary>
    static long Pow_mod(long x, long n, long mod)
    {
        long res = 1;
        while (n > 0)
        {
            var bit = n & 1;
            if (bit != 0) res = res * x % mod;
            x = x * x % mod;
            n >>= 1;
        }
        return res;
    }

    /// <summary>
    /// 組み合わせnCRの数を返す
    /// </summary>
    static long Combination(long n, long r, long mod)
    {
        if (r * 2 > n) r = n - r;
        long dividend = 1;
        long divisor = 1;
        for (long i = 1; i <= r; ++i)
        {
            dividend *= (n - i + 1);
            dividend %= mod;

            divisor *= i;
            divisor %= mod;
        }

        return (dividend * Pow_mod(divisor, mod - 2, mod)) % mod;
    }



    /// <summary>
    /// 「入山徳夫氏によるnCrを高速に求めるアルゴリズム」
    /// https://kadzus.hatenadiary.org/entry/20081211/1229023326
    /// </summary>
    /// <param name="n"></param>
    /// <param name="r"></param>
    /// <param name="mod"></param>
    /// <returns></returns>
    public static long Combination_Iri(long n, long r, long mod)
    {
        if (n < 0 || r < 0 || r > n) throw new ArgumentException("不正な引数です．");

        if (n - r < r) r = n - r;
        if (r == 0) return 1;
        if (r == 1) return n;

        long[] numerator = new long[r];
        long[] denominator = new long[r];

        for (int k = 0; k < r; k++)
        {
            numerator[k] = n - r + k + 1;
            denominator[k] = k + 1;
        }

        for (int p = 2; p <= r; p++)
        {
            long pivot = denominator[p - 1];
            if (pivot > 1)
            {
                long offset = (n - r) % p;
                for (int k = p - 1; k < r; k += p)
                {
                    numerator[k - offset] /= pivot;
                    denominator[k] /= pivot;
                }
            }
        }

        long result = 1;
        for (int k = 0; k < r; k++)
        {
            if (numerator[k] > 1)
            {
                result *= numerator[k];
                result %= mod;
            }
        }

        return result;
    }







    static string[] ReadStringArray()
    {
        return Console.ReadLine().Trim().Split(' ');
    }

    static int[] ReadIntArray()
    {
        return ReadStringArray().Select(_ => int.Parse(_)).ToArray();
    }

    static long[] ReadLongArray()
    {
        return ReadStringArray().Select(_ => long.Parse(_)).ToArray();
    }
}
 


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;

bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}

void swap(int *a,int *b){
   int temp=*a;
   *a=*b;
   *b=temp;
}

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

int main(void){
   long long a,b;
   cin>>a>>b;
   if(a>0&&b>0){
      cout<<"Positive"<<endl;
   }else if(a<0&&b<0){
      if((b-a+1)%2==0){
         cout<<"Positive"<<endl;
      }else{
         cout<<"Negative"<<endl;
      }
   }else if(a<=0&&b>=0){
      cout<<"Zero"<<endl;
   }
   return 0;
}


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

typedef long long int ll; 

int main(void)
{
	ll x,k,d;
    cin >> x >> k >> d;

    ll mul = (abs(x))/d;
    /// if x == 0,it will go in else
    
    if(k < mul)
    {
        if(x < 0)
            x += k*d;
        else if(x > 0)
            x -= k*d;
        else if(x == 0)
        {
            if(k%2 == 1)
                x += d;
        }
        cout << abs(x) << endl;
    }
    else if(k > mul)
    {
        if(x < 0)
        {
            x += mul*d;
            k -= mul;
            if(k%2 == 1) //odd no of steps left
                cout << abs(x+d) << endl;
            else
                cout << abs(x) << endl;
        }
        else if(x > 0)
        {
            x -= mul*d;
            k -= mul;
            if(k%2 == 1) //odd no of steps left
                cout << abs(x-d) << endl;
            else
                cout << abs(x) << endl;
        }
        else if(x == 0)
        {
            if(k%2 == 1) 
                cout << abs(x+d) << endl;
            else
                cout << abs(x) << endl;   
        }
    }
    else if(k == mul)
    {
        if(x > 0)
            x -= mul*d;
        else if(x < 0)
            x += mul*d;
        else if(x == 0)
        {
            if(k != 0 && k%2 == 1)
                x = x+d;
        }
        cout << abs(x) << endl;        
    }

	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define int ll
#define endl "\n"
#define all( x ) x.begin(), x.end()
#define fast ios::sync_with_stdio(0);cin.tie(0);

typedef unsigned long long ull;

const int inf = 1e9 + 5;
const long double PI = 3.141592653589793;

void solve(){
  int n;
  cin >> n;
  vector<int> h(n+1);
  for(int i = 1;i<n+1;i++){
    cin >> h[i];
  }
  vector<int> dp(n+1, inf);
  dp[0] = dp[1] = 0;
  for(int i = 1; i<n+1;i++){
    for(int d:{1, 2}){
      if(i - d > 0){
        dp[i] = min(dp[i], dp[i-d] + abs(h[i] - h[i - d]));
      }
    }
  }
  cout << dp[n] <<endl;
  return;
}  
signed main(){
  fast;
  int t;
  t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}



Measured memory_bytes: 4756
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	nums := make([]int, n)
	min := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nums[i])
		if i == 0 {
			min[0] = nums[0]
		}
		if i > 0 && nums[i] < min[i-1] {
			min[i] = nums[i]
		} else if i > 0 && nums[i] >= min[i-1] {
			min[i] = min[i-1]
		}
	}
	counter := 0
	for i, num := range nums {
		if num == min[i] {
			counter++
		}
		if num == 1 {
			fmt.Println(counter)
			return
		}
	}
	fmt.Println(counter)
}


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

using namespace std;

long long num[200010],zzs[200010];

int main()
{
	int n;
	long long ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&num[i]);
		zzs[i]=zzs[i-1]+num[i];
	}
	for(int i=1;i<=n;i++)
	{
		ans+=(num[i]%1000000007)*((zzs[n]-zzs[i])%1000000007);
		ans%=1000000007;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6896
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n;
    cin>>n;
    set<string> s;
    for (int i = 0; i < n; ++i)
    {
        string d;
        cin>>d;
        s.insert(d);
    }
    int ans = s.size();
    cout<<ans;


    printclock;
    return 0;
}


Measured memory_bytes: 19420
#include "bits/stdc++.h"
using namespace std;
const int K = 43;
int main() {
	int N;
	cin >> N;
	vector<long long>A(N);
	long long x = 0;
	for (int n = 0;n<N; ++n) {
		cin >> A[n];
	}
	for (int n = 2;n<N;++n) {
		x = x xor A[n];
	}
	long long s = A[0] + A[1];

	long long DP[43][2][2];
	for (int i =0;i<43;++i) {
		for (int j = 0;j<2;++j) {
			for (int k = 0;k<2;++k) {
				DP[i][j][k] = -1;
			}
		}
	}
	DP[0][0][0] = 0;
	long long a = A[0];
	long long v = 1;
	for (int i = 0;i < K-1; ++i) {
		int cx = x & 1;
		int cs = s & 1;
		int ca = a & 1;
		for (int j = 0;j<2;++j) {
			for (int k = 0; k < 2; ++k) {
				if (-1 == DP[i][j][k]) {
					continue;
				}
				for (int na = 0; na < 2; ++na) {
					for (int nb = 0; nb < 2; ++nb) {
						int ni = i + 1;
						int nj = 0;
						int nk = k;
						if (cx != (na^nb)) {
							continue;
						}
						int ns = na + nb + j;
						if (cs != ns % 2) {
							continue;
						}
						if (ns >= 2) {
							nj = 1;
						}
						if (ca < na) {
							nk = 1;
						}
						else if (ca == na) {
							nk = k;
						}
						else {
							nk = 0;
						}
						DP[ni][nj][nk] = max(DP[ni][nj][nk], DP[i][j][k] | (v*na));
					}
				}
			}
		}
		x >>= 1;
		s >>= 1;
		a >>= 1;
		v <<= 1;
	}
	a = DP[K-1][0][0];
	if ((-1 == a)||(0 == a)) {
		cout << -1 <<endl;
		return 0;
	}

	cout <<A[0]-a<<endl;


	return 0;
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(void)
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int N, i;
  long long int sum = 0;
  cin >> N;
  for (i = 1; i <= N; i++)
    if (i % 3 != 0 && i % 5 != 0)
      sum += i;
  cout << sum << '\n';
  return 0;
}


Measured memory_bytes: 3640
s = input()
n = len(s) - 1
ans = 0
for i in range(1,1<<n):
    l = [0]
    dummy = 0
    for j in range(n):
        if i>>j & 1 == 1:
            l.append(n-j)
    l.append(n+1)
    l.sort()
    # print(bin(i))
    # print(l)
    for i in range(len(l)-1):
        dummy += int(s[l[i]:l[i+1]])
    # print(bin(i),dummy)
    ans += dummy
print(ans+int(s))

Measured memory_bytes: 40176
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define here(x) cout << " #x = " << x << endl;
#define show(x) {for( auto ii : x) cout << ii << setw(4); cout << endl;}
#define shop(n,x) {for(int i = 0; i < n; i++) cout << x << setw(4); cout << endl;}
#define ff first
#define ss second
#define sq(x) (x*x)
#define endl '\n'
#define en " "
#define pb push_back
#define mpair make_pair
ll mod=1000000007;
double pi=3.1415926536;
ll dp[4000][4000];
ll win(ll a[], ll l, ll h)
{
	if(dp[l][h] != -1)
		return dp[l][h];

	if(l == h)
		return a[l];

	ll n = h - l + 1;

	if(n % 2)
		return dp[l][h] = max(a[l] + win(a, l + 1, h), a[h] + win(a, l, h - 1));

	return dp[l][h] = min(- a[l] + win(a, l + 1, h), - a[h] + win(a, l, h - 1));
}
int main()
{
	fastio();
	int tt = 1;
	//cin >> tt;
	while(tt--)
	{
		// go fast 		check		//		CHECK -> if()   else if()
		
		ll n, x=0, m=0, y=0, d=1, k=mod;
		cin >> n;
		ll a[n];
		for(ll i = 0; i < n; i++)
			cin >> a[i];
		memset( dp, -1, sizeof(dp));
		x = win(a, 0, n - 1);
		if(n % 2)
			cout << x << endl;
		else
			cout << - x << endl;
	}
}

Measured memory_bytes: 125440
import heapq

n,m=map(int,input().split())
mm=10**5+5
c=[[0] for i in range(mm)]

for i in range(n):
  a,b=map(int,input().split())
  c[a].append(b)

#print(c)

ans=0
h=[]
for i in reversed(range(m)):
  d=m-i
  for j in c[d]:
    heapq.heappush(h,-j)
  #heapq.heapify(h)
  ans+=-heapq.heappop(h)

print(ans)

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

  
  
int main(){
  ll n,m,i,l;
  cin >> n >> m;
  if(n%2==1){
    l=2*m;
    for(i=1;i<=m;i++){
      cout << i << " " << l-i+1 << endl;
    }
  }
  else{
    l=n/4;
    for(i=1;i<=m;i++){
      if(i<=l){
        cout << i << " " << 2*l-i+1 <<endl;
      }
      else{
        cout << l+i << " " << n-i+l <<endl;
      }
    }
  }
}

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

int main() {
  int D,N;
  cin >> D >> N;
  int t;
  vector<int> num(3);
  for(int i=1;i<=1010000;i++){
    t=i;
    if(i%100==0 && i%10000!=0){
      num[1]++;
    }
    else if(t%10000==0 && t%1000000!=0){
      num[2]++;
    }
    else if(t%100!=0)num[0]++;

    if(num[D]==N){
      cout << i << endl;
      return 0;
    }
  }
}
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

struct UnionFind{
private:
    vector<int> par;
    vector<int> rank;
    vector<int> sz;

public:
    //n要素で親を初期化、par[x]はxの親を表す
    UnionFind(int n){
        par.resize(n,0);
        rank.resize(n,0);
        sz.resize(n,1);
        rep(i,n){
            par[i] = i;
        }
    }

    //木の根を求める
    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    //xとyの属する集合を併合
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        else{
            par[y] = x;
            sz[x] += sz[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    //xとyが同じ集合に属するか否か
    bool same(int x, int y){
        return root(x) == root(y);
    }

    //xが属する集合のサイズを返す
    int size(int x){
        return sz[root(x)];
    }

    // 集合の数を返す
    int num_of_s(){
        set<int> st;
        rep(i,par.size()) st.insert(root(i));
        return st.size();
    }
};

int main(){
    ll n,m; cin >> n >> m;
    vector<ll> a(n);
    ll sum = 0;
    rep(i,n) {
        cin >> a[i];
        sum += a[i];
    }
    UnionFind uf(n);
    rep(i,m){
        ll x,y; cin >> x >> y;
        uf.unite(x, y);
    }

    ll num = uf.num_of_s();

    if((num - 1) * 2 > n){
        cout << "Impossible" << endl;
        return 0;
    }

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

    vector<vector<ll>> graph(n);
    rep(i,n){
        graph[uf.root(i)].emplace_back(a[i]);
    }
    vector<ll> rest;
    rep(i,n){
        if(graph[i].size() <= 1)continue;
        sort(all(graph[i]), greater<ll>());
        rep(j,graph[i].size() - 1)rest.emplace_back(graph[i][j]);
    }

    sort(all(rest), greater<ll>());
    rep(i,n - (num - 1) * 2)sum -= rest[i];

    cout << sum << endl;
}

Measured memory_bytes: 7308
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    S = readline().strip()
    T = readline().strip()
    N, M = len(S), len(T)

    dp = [[0] * (M + 1) for _ in range(N + 1)]
    prev = [[0] * (M + 1) for _ in range(N + 1)]
    for i in range(N):
        for j in range(M):
            if S[i] == T[j]:
                dp[i + 1][j + 1] = dp[i][j] + 1
                prev[i + 1][j + 1] = (i, j)
            elif dp[i + 1][j] > dp[i][j + 1]:
                dp[i + 1][j + 1] = dp[i + 1][j]
                prev[i + 1][j + 1] = (i + 1, j)
            else:
                dp[i + 1][j + 1] = dp[i][j + 1]
                prev[i + 1][j + 1] = (i, j + 1)

    ans = []
    i, j = N, M
    while i and j:
        p, q = prev[i][j]
        if i > p and j > q:
            ans.append(S[p])
        i, j = p, q

    print(''.join(reversed(ans)))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 405896
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] a = new int[n];
		int pos = 0, neg = 0, max = 0;
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
			if(a[i]>0)
				pos++;
			if(a[i]<0)
				neg++;
			if(Math.abs(a[i])>Math.abs(a[max]))
				max = i;
		}
		
		if(pos==0 && neg==0) {
			System.out.println(0);
		}
		else {
			int m = 0;
			StringBuilder ans = new StringBuilder();
			
			if(pos!=0 && neg!=0) {
				if(a[max]>0) {
					for(int i=0;i<n;i++) {
						if(a[i]<0) {
							a[i]+=a[max];
							m++;
							ans.append((max+1)+" "+(i+1)+"\n");
						}
					}
					neg = 0;
				}
				else {
					for(int i=0;i<n;i++) {
						if(a[i]>0) {
							a[i]+=a[max];
							m++;
							ans.append((max+1)+" "+(i+1)+"\n");
						}
					}
					pos = 0;
				}
			}
			
			if(pos==0) {
				for(int i=n-1;i>=1;i--) {
					if(a[i-1]>a[i]) {
						a[i-1]+=a[i];
						m++;
						ans.append((i+1)+" "+(i)+"\n");
					}
				}
			}
			else {
				for(int i=0;i<n-1;i++) {
					if(a[i]>a[i+1]) {
						a[i+1]+=a[i];
						m++;
						ans.append((i+1)+" "+(i+2)+"\n");
					}
				}
			}
			
			System.out.println(m);
			System.out.print(ans);
		}
	}
}


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

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

using namespace std;

int gcd(int a, int b);
int lcm(int a, int b);

void solve_A(){
    int n;
    cin >> n;
    string s[n];
    int t[n];
    REP(i,n) cin >> s[i] >> t[i];
    string x;
    cin >> x;

    int ans = 0;
    REP(i,n){
        if(s[i] == x){
            for(int j = i + 1; j < n; j++){
                ans += t[j];
            }
        }
    }

    cout << ans ;
}

int main(void){
    solve_A();
    
    return 0;
}

int gcd(int a, int b){
    if(a < b) swap(a, b);

    int r = a % b;
    while(r != 0){
        a = b;  b = r;  r = a % b;
    }
    return b;
}

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

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

int n;

bool check () {
	for (int i = 1; i <= n; i <<= 1) {
		if (i == n) return true;
	}
	return false;
}
int main () {
	scanf("%d", &n);
	bool flag = check();
	if (check()) {
		printf("No\n");
		return 0;
	}
	else {
		printf("Yes\n");
		printf("%d %d\n", 1, 2);
		printf("%d %d\n", 2, 3);
		printf("%d %d\n", 3, n + 1);
		printf("%d %d\n", n + 1, n + 2);
		printf("%d %d\n", n + 2, n + 3);

		int n_ = n - (n & 1 ^ 1);
		for (int i = 4; i <= n_; i += 2) {
			printf("%d %d\n", n + 1, n + i);
			printf("%d %d\n", n + i, n + i + 1);
			printf("%d %d\n", n + 1, i + 1);
			printf("%d %d\n", i + 1, i);
		}

		if (n & 1 ^ 1) {
			int x, y;
			for (int i = 2; i < n; i++) {
				if ((n ^ 1 ^ i) >= 2 && (n ^ 1 ^ i) < n) {
					x = i, y = n ^ 1 ^ i;
				}
			}
			if (x & 1 ^ 1) x += n;
			if (y & 1 ^ 1) y += n;
			printf("%d %d\n", n, x);
			printf("%d %d\n", n << 1, y);
		}
	}
	return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int n;
    string s;

    cin >> n >> s;

    string t = s;

    int l = 0, r = 0;

    while (true)
    {
        bool u = false;
        for (int i = 0; i < (int)s.size() - 1; i++)
        {
            if (s[i] == '(' && s[i + 1] == ')')
            {
                s = s.substr(0, i) + s.substr(i + 2, s.size() - (i + 2)), u = true;
                break;
            }
        }

        if (!u)
            break;
    }

    for (int i = 0; i < s.size(); i++)
        if (s[i] == ')')
            l++;
        else
            r++;

    REP(i, l)
    cout << "(";
    cout << t;
    REP(i, r)
    cout << ")";
    cout << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int	main(void)
{
	int n,a,min,max,i;
	long sum;
	scanf("%d",&n);
	scanf("%d",&a);
	min=max=sum=a;
	for(i=1;i<n;i++){
		scanf("%d",&a);
		min=(a<min ? a : min);
		max=(a>max ? a : max);
		sum+=a;
	}
	printf("%d %d %ld\n",min,max,sum);
	return	0;
}

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

int main(){

    int n,k;
    cin >> n >> k;
    vector<int> num(n,0);
    for(int i = 0;i < n;i++){
        cin >> num[i];
    }
    int ans = 0;
    sort(num.begin(),num.end(),greater<int>());
    for(int i = 0;i < k;i++){
        ans+=num[i];
    }

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

Measured memory_bytes: 256
n = int(input())
w = [input() for _ in range(n)]
w_used = set()
pre_word = ""
for i in range(n):
    if i == 0:
        pre_word = w[i]
        w_used.add(w[i])
        continue
    if pre_word[-1] != w[i][0] or w[i] in w_used:
        print("No")
        break
    w_used.add(w[i])
    pre_word = w[i]
else:
    print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
#define ALL(a)  (a).begin(),(a).end()
const int MOD = 998244353;
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int ngcd(vector<int> a) {
    int res;
    res = a[0];
    for (int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
int main() {
	int n,ans =0; cin >> n; vector<int> v(n);
	rep(i, n) cin >> v[i];
    cout << ngcd(v) << endl;
}

Measured memory_bytes: 1024
/* ALDS1_1_D */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(br.readLine());
      int max = 0, min = 0;

      for(int i = 0; i < n; i++){
        int v = Integer.parseInt(br.readLine());
        if(i == 0){
          min = v;
          continue;
        }

        if(max < v - min || i == 1){
          max = v - min;
        }
        if(min > v) min = v;
      }
      System.out.println(max);
    }catch(Exception e){
      System.out.println(e);
    }
  }
}

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

using namespace std;

int main()
{
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> route;

    for (int i = 0; i < n; i++)
    {
        int time, cost;
        cin >> cost >> time;
        route.push_back({cost, time});
    }

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

    int answer = -1;
    for (auto x : route)
    {
        if (x.second <= t)
        {
            answer = x.first;
            break;
        }
    }

    if (answer == -1)
        cout << "TLE" << endl;
    else
        cout << answer << endl;
    return 0;
}

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

int convert(int x, int n){
    int y=0, i=0, z;
    while(x > 0){
        z = x%n;
        y += z*pow(10, i);
        x = x/n;
        i++;
    }
    return i;
}

int main(int argc, const char * argv[]) {
    int N, K;
    cin >> N;
    cin >> K;
    
    int ans = convert(N, K);
    std::cout << ans;
    return 0;
}

Measured memory_bytes: 888
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int n = Integer.parseInt(str[0]);
		long x = Long.parseLong(str[1]);

		str = br.readLine().split(" ");

		long a[] = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = Long.parseLong(str[i]) - x;
		}

		long g = Math.abs(a[0]);

		for (int i = 1; i < n; i++) {
			g = gcd(g, Math.abs(a[i]));
		}

		System.out.println(g);
	}

	static long gcd(long m, long n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}
}


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

using namespace std;

long long ans = INT_MAX, n, m, x, c[12], a[12][12];
long long understand[12];

int main(){
	cin >> n >> m >> x;
	for(int i = 0; i < n; ++i){
		cin >> c[i];
		for(int j = 0; j < m; ++j){
			cin >> a[i][j];
		}
	}

	for(int b = 0; b < (1<<n); ++b){
		long long price = 0;
		for(int j = 0; j < m; ++j) understand[j] = 0;

		for(int i = 0; i < n; ++i){
			if(b&(1<<i)){
				price += c[i];
				for(int j = 0; j < m; ++j){
					understand[j] += a[i][j];
				}
			}
		}

		bool ok = true;
		for(int i = 0; i < m; ++i) if(understand[i] < x) ok = false;

		if(ok) ans = min(ans, price);
	}
	if(ans == INT_MAX){
		cout << -1 << endl;
	}else cout << ans << endl;
}

Measured memory_bytes: 3636
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0

output:
4
"""
import sys


def solve():
    dp = [[0] * (W + 1) for _ in range(H + 1)]

    for i in range(H):
        for j in range(W):
            if not int(carpet_info[i][j]):
                dp[i + 1][j + 1] = min(dp[i][j], dp[i][j + 1], dp[i + 1][j]) + 1

    max_width = max(map(max, dp))
    return pow(max_width, 2)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    H, W = map(int, _input[0].split())
    carpet_info = list(map(lambda x: x.split(), _input[1:]))
    print(solve())

Measured memory_bytes: 60312
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
    
p = list(map(int, input().split()))

ans = 0
tmp = float("inf")
for i in range(1000):
    if i not in p:
        if abs(x - i) < tmp:
            tmp = abs(x - i)
            ans = i

print(ans)

Measured memory_bytes: 61908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define push_back pb

const int mod = 1000000007;
const int inf = 1e9;

int gcd(int a, int b)
{
   if (a%b == 0)
   {return(b);}
   else
   {return(gcd(b, a%b));}
}

int main(){
    int k;
    cin >> k;
    ll ans = 0;
    repn(i, 1, k){
        repn(j, 1, k){
            repn(l, 1, k){
                ans += __gcd(__gcd(i, j), l);
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3636
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

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

 //   Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int a = cin.nextInt();
    int b = cin.nextInt();
    int k = cin.nextInt();

    for (int i=0;i<k;i++){
      if (i%2==0) {
        if (a%2==1) {
          a--;
          a = a/2;
          b +=a;
        }
        else {
          a = a/2;
          b +=a;
        }
      }
      else {
        if (b%2==1) {
          b--;
          b = b/2;
          a +=b;
        }
        else {
          b = b/2;
          a +=b;
        }
      }

    }

    System.out.println(a + " " + b);
  }

}


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

typedef long long ll;

const int N = 1e5 + 20;
ll a[N], dp[N];

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	dp[0] = 0;
	dp[1] = dp[0] + abs(a[0] - a[1]);
	for (int i = 2; i < n; i++)
	{
		dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << dp[n - 1];
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef long double LD;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()

int keta(LL p)
{
    int t=0;
    while(p>0)
    {
        p/=10;
        t++;
    }
    return t;
}

int main()
{
    LL n;
    cin>>n;
    int ans=10;
    FOR(i,1,sqrt(n)+2)
    {
        if(n%i==0)
        {
            ans=min(ans, keta(n/i));
        }
    }
    cout<< ans<<endl;
}



Measured memory_bytes: 256
A,B,C,D = map(int, input().split())
takaAttackNum = C//B
aokiAttackNum = A//D

if takaAttackNum != C/B:
  takaAttackNum+=1
if aokiAttackNum != A/D:
  aokiAttackNum+=1

if takaAttackNum <= aokiAttackNum :
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 9104
#include <iostream>
#include <algorithm>
using namespace std;
int X[100];
int main()
{
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> X[i];
  int ans = 100*100*100;
  for (int P = 1; P <= 100; P++) {
    int cost = 0;
    for (int i = 0; i < N; i++) {
      cost += (abs(P-X[i])*abs(P-X[i]));
    }
    ans = min(ans, cost);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n, a, b;
	scanf("%lld %lld %lld", &n, &a, &b);
	if ((n > 1 && b >= a) || (n == 1 && a == b)) printf("%lld\n", (b - a) * (n - 2) + 1);
	else printf("0\n");
	return 0;
}

Measured memory_bytes: 256