akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
using namespace std;
typedef long long ll;

int Q;

ll inf = 1000003;
ll fact[1000010] = {0};
ll inv[1000010] = {0};

ll mult(ll n, ll m){
	if(m==1) return n%inf;
	else if(m%2==0){
		ll t = mult(n,m/2);
		return (t*t)%inf;
	}else{
		ll t = mult(n,m-1);
		return (t*n)%inf;
	}
}

void factorial(ll N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			fact[i] = 1;
			inv[i] = 1;
		}
		else{
			fact[i] = (i*fact[i-1])%inf;
			inv[i] = mult(fact[i],inf-2);
		}
	}
}

ll mod_fact(ll n,ll p,ll& e){
    e = 0;
    if(n==0) return 1;
    ll res = mod_fact(n/p,p,e);
    e += n/p;
    if(n/p%2!=0) return res*(p-fact[n%p])%p;
    else return res*fact[n%p]%p;
}

int main(){
    cin >> Q;
    factorial(inf);
    ll x,d,n;
    for(int i=0;i<Q;i++){
        cin >> x >> d >> n;
        ll ans = mult(d,n);
        if(d==0){
            cout << mult(x,n) << endl;
            continue;
        }
        ll s = x*mult(d,inf-2)%inf;
        ll r = s+n-1,l = s-1;
        if(r/inf-l/inf>=1) ans = 0;
        else{
            (ans *= fact[r%inf])%=inf;
            if(l!=0) (ans *= inv[l])%=inf;
        }
        cout << ans << endl;
    }    
}

Measured memory_bytes: 16512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            IO io = new IO();

            //ここから
            int[] num = io.ReadLineToIntArray();
            int[] target = io.ReadLineToIntArray();

            if (num[0] >= num[1])
            {
                Console.Write(0);
            }
            else
            {

                int movecount = num[1] - num[0];

                target = target.OrderBy(t => t).ToArray();
                int[] dif = new int[num[1] - 1];

                for (int i = 0; i < target.Count() - 1; i++)
                {
                    dif[i] = Math.Abs(target[i] - target[i + 1]);
                }

                dif = dif.OrderBy(d => d).ToArray();

                int ans = 0;

                for (int i = 0; i < movecount; i++)
                {
                    ans += dif[i];
                }

                Console.Write(ans);

                Console.ReadKey();
            }
        }
    }

    //IOを担う関数群
    public class IO
    {
        //stringの入力
        public string ReadLineToString()
        {
            return Console.ReadLine();
        }

        //intの入力
        public int ReadLineToInt()
        {
            return int.Parse(Console.ReadLine());
        }

        //空白区切りの複数の文字列の入力をstring[]にして返す
        public string[] ReadLineToStringArray()
        {
            return Console.ReadLine().Split(' ').ToArray();
        }


        //空白区切りの複数の整数の入力をint[]にして返す
        public int[] ReadLineToIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        //空白区切りの複数の文字列の入力をList<string>で受け取る
        public List<string> ReadLineToStringList()
        {
            return Console.ReadLine().Split(' ').ToList();
        }

        //空白区切りの複数の整数の入力をList<int>で受け取る
        public List<int> ReadLineToIntList()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        }

    }

}


Measured memory_bytes: 23008
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
print((n-1)//2)


Measured memory_bytes: 38384
/*
मनस्वी म्रियते कामं कार्पण्यं न तु गच्छति ।
अपि निर्वाणमायाति नानलो याति शीतताम् ॥
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define imx INT_MAX
#define imn INT_MIN
#define inf 9000000000000000000
#define minf -inf
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
#define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
#define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
    ll n;
    cin>>n;

    ll a,b;

    ll total = (n*(n+1)*(n+2))/6;

    forn(i,0,n-1)
    {
        cin>>a>>b;

        if(a > b) swap(a,b);

        total -= a*(n-b+1);

    }
        
        
    cout<<total;











    return 0;
}


Measured memory_bytes: 3664
from sys import stdin
input=stdin.readline().rstrip().split()
#print(input)
for i in range(len(input)):
    input[i]=int(input[i])

A=input[0]
B=input[1]
T=input[2]

x=0
output=0
while x<100:
    x+=A
    if x>T:
        break
    output+=B

print(output)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
		 int N = sc.nextInt();
		 String S = sc.next();
		 int count = 0;
		 for(int i=0; i<N-2; i++) {
			 if(S.substring(i, i+3).equals("ABC")){
				 count++;
			 }
		 }
		 System.out.println(count);
	}
}
		 


Measured memory_bytes: 35636
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class A
{
	public static void Main()
	{		
		string[] args = Console.ReadLine().Split(' ');
		long A = Int64.Parse(args[0]);
		long B = Int64.Parse(args[1]);
		long C = Int64.Parse(args[2]);
		long K = Int64.Parse(args[3]);

		long ans = (K % 2 == 1) ? B - A : A - B;
		if(ans > (long)Math.Pow(10,18))
		{
			Console.WriteLine("Unfair");
		}
		else
		{
			Console.WriteLine(ans);
		}
	}
}





Measured memory_bytes: 11220
""" D
    https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d
"""
import sys
import math
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return [lambda _: readIntegerSet(m) for _ in range(0, n)]

def div_by(n, x, k):
    result = 0
    for i in n:
        if x[i] == "1":
            result = (result + pow(2, n-i-1)) % k
    return result

def popcount(x):
    return sum([int(c) for c in x])

def main(N, A):
    kabu = 0
    money = 1000
    for i in range(1, N):
        if A[i-1] < A[i]:
            kabu += money // A[i-1]
            money %= A[i-1]
        else:
            money += A[i-1] * kabu
            kabu = 0

    money += A[N-1] * kabu

    return money

if __name__ == "__main__":
    _N = readInteger()
    _A = readIntegerSet(_N)

    print(main(_N, _A))

Measured memory_bytes: 9268
import java.io.*;
import java.util.*;
import java.lang.Math;

public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);
        final int MOD = 1000000007;

        int n = sc.nextInt();
        int m = sc.nextInt();

        ArrayList<Integer>[] arr = new ArrayList[m];
        for(int i=0;i<m;i++) arr[i] = new ArrayList<>();

        for(int i=0;i<n;i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(m - a >= 0) {
                arr[m-a].add(b);
            }
        }

        PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
        long ans = 0;
        for(int i=m-1;i>=0;i--) {
            for(int x : arr[i]) {
                pq.add(x);
            }
            if(!pq.isEmpty()) {
                ans += pq.poll();
            }
        }

        pw.println(ans);
        pw.close();
    }
}


Measured memory_bytes: 57664
#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 main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);    
    long long int a,b,N;
    cin>>a>>b>>N;
    long long n=b-1;
    if(n>N)
    n=N;
    cout<<(a*n)/b;
}

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

int main() {
  int64_t Ans = 1e9;  // 回答：

  // １．割り切れる時０
  // ２．割り切れない時 min(余り,Ｋ－余り)
  int64_t N; cin >> N;  // 元の数
  int64_t K; cin >> K;  // 割る数

  if ( N%K == 0 ) { Ans = 0; }
  else {
    int64_t J = N % K;
    Ans = min(J,abs(K-J));
  }

  cout << Ans << endl;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;

//conversion
//------------------------------------------
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(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

inline ll floor(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return a / llb;
	}
	else
	{
		return - ( (-a + llb - 1) / llb);
	}
}

inline ll ceil(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return (a + llb - 1) / llb;
	}
	else
	{
		return - (-a / llb);
	}
}

inline ll getLowestOneBit(ll a)
{
	return a & (-a);
}

inline ll getHighestOneBit(ll a)
{
	while ((a & (a - 1)) != 0)
	{
		a = a & (a - 1);
	}
	return a;
}

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline ll getSpecifiedBit(ll a, unsigned bit)
{
	return (a & (1LL << bit)) >> bit;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

template<class Integer>
inline Integer getPower(Integer base, ull exponential)
{
	Integer result = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			result = result * base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return result;
}

vector<ll> z_algorithm(string S) {
	vector<ll> As(S.size());

	ll base_pos = 0;
	for (ll curr_pos = 1; curr_pos < S.size(); curr_pos++)
	{
		if (curr_pos + As[curr_pos - base_pos] < base_pos + As[base_pos])
		{
			As[curr_pos] = As[curr_pos - base_pos];
		}
		else
		{
			int check_pos = max(0LL, base_pos + As[base_pos] - curr_pos);
			while (curr_pos + check_pos < S.size() && S[check_pos] == S[curr_pos + check_pos]) ++check_pos;
			As[curr_pos] = check_pos;
			base_pos = curr_pos;
		}
	}
	As[0] = S.size();

	return As;
}

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

	ll N;
	string S;
	cin >> N >> S;

	ll result = 0;
	for (ll i = 0; i + 1 < S.size(); ++i)
	{
		auto v = z_algorithm(S.substr(i));
		for (ll j = 0; j < v.size(); ++j)
		{
			result = max(result, min(j, v[j]));
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

typedef long long ll;

int n;
bool a[25][25];
ll dp[(1 << 22) + 5];
const ll mod = (int)1e9 + 7;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0 ; i < n ; ++i){
	for(int j = 0 ; j < n ; ++j){
		cin >> a[i][j];
	}
}
dp[0] = 1;
for(int mask = 0 ; mask < (1 << n) ; ++mask){
	int i = __builtin_popcount(mask);
	for(int j = 0 ; j < n ; ++j){
		if(!((mask >> j) & 1) && a[i][j]){
			dp[mask | (1 << j)] = (dp[mask | (1 << j)] + dp[mask]) % mod;
		}
	}
}
cout << dp[(1 << n) - 1] << endl;

return 0;
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int dp[3001][3001];

int main() {
  string s, t;
  cin >> s >> t;

  rep (i, sz(s)) rep (j, sz(t)) {
    if (s[i] == t[j]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
    else dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
  }

  string ans = "";
  int a = sz(s);
  int b = sz(t);
  while (a > 0 && b > 0) {
    if (s[a - 1] == t[b - 1] && dp[a][b] == dp[a - 1][b - 1] + 1) {
      ans += s[a - 1];
      a--;
      b--;
    } else if (dp[a][b] == dp[a - 1][b]) {
      a--;
    } else {
      b--;
    }
  }

  reverse(all(ans));

  cout << ans << endl;
}


Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}
 
typedef pair<ll,ll> Pair;
const ll inf =1000000007;

ll llabs(ll a){
    if(a<0) a*=-1;
    return a;
}

int main(){
    ll n;
    cin >>n;
    ll x[n],y[n],h[n];
    ll xx,yy,hh;
    rep(i,n) {
        cin >> x[i] >> y[i] >>h[i];
        if (h[i] != 0) {
          xx = x[i]; yy = y[i]; hh = h[i];
        }
    }
    
    ll ansx=0,ansy=0,ansh=0;
    ll b=0;
    for(ll i=0;i<=100;i++){
        for(ll j=0;j<=100;j++){
            bool can=true;
            ll hyp=abs(i-xx) + abs(j-yy) + hh;
            rep(k,n){
                if(h[k]!=max(hyp-llabs(i-x[k])-llabs(j-y[k]),b)) {
                    can=false;
                    break;
                }
            }
            if(can) {
                ansx=i;ansy=j;ansh=hyp;
                cout << ansx << " " << ansy <<" " << ansh << endl;
            }
        }
    }
}


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

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long num = 0;

            for (var i = 1; i <= N; ++i)
            {
                if (i % 5 != 0 && i % 3 != 0)
                    num += i;  
            }
            Console.WriteLine(num);
        }
    }
}


Measured memory_bytes: 27460
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

		Scanner scan = new Scanner(System.in);

		String A = scan.next();
		String B = scan.next();

		if (A.equals("H")) {
			//正直者
			System.out.println(B);
		} else {
			//嘘つき
			if (B.equals("H")) {
				System.out.println("D");
			} else {
				System.out.println("H");
			}
		}
	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 26912
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int cur = 0;
    vector<vector<int> > grid(h, vector<int>(w));
    for(int i = 0; i < h; i++){
        if(i%2 == 0){
            for(int j = 0; j < w; j++){
                if(a[cur] > 0){
                    grid[i][j] = cur + 1;
                    a[cur]--;
                }
                else{
                    grid[i][j] = ++cur + 1;
                    a[cur]--;
                }
            }
        }
        else{
            for(int j = w-1; j >= 0; j--){
                if(a[cur] > 0){
                    grid[i][j] = cur + 1;
                    a[cur]--;
                }
                else{
                    grid[i][j] = ++cur + 1;
                    a[cur]--;
                }
            }
        }
    }
    rep(i,h){
        rep(j,w) cout << grid[i][j] << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout << ((f) ? "Yes" : "No") << endl;
#define YORN(f) cout << ((f) ? "YES" : "NO") << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define put(x) cout << x << endl;
using namespace std;
int main()
{
    ll n;
    cin >> n;
    ll sum = 0;
    rep(j, n)
    {
        ll i = j + 1;
        if (i % 15 == 0)
        {
        }
        else if (i % 3 == 0)
        {
        }
        else if (i % 5 == 0)
        {
        }
        else
        {
            sum += i;
        }
    }
    put(sum)
    return 0;
}

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

int main() {
    long long a, b, c;
    cin >> a >> b >> c;
    if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) cout << 0 << endl;
    else cout << min({a * b, a * c, b * c}); 
}

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

#define endl "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define deb(x) cerr << #x << " => " << x << "\n"
#define deba(x) cerr << #x << "\n"; for (auto a : x) cerr << a << " "; cerr << "\n";
#define debm(x) cerr << #x << "\n"; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << "\n";}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)

int fastpow(int a, int b, int m) {
    int res = 1; a %= m; while (b > 0) {
        if (b & 1) res = (res * a) % m;
        a = (a * a) % m; b >>= 1;
    } return res;
}

vector<int> fact(4e6 + 5);

int nck(int n, int k) {
    return ((fastpow(fact[n - k], HELL - 2, HELL)) * 
            ((fact[n] * fastpow(fact[k], HELL - 2, HELL)) % HELL)) % HELL;
}

int now() {
    return chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now()
    .time_since_epoch()).count();
}

int32_t main() { fastio;
    time_t start = now();

    fact[0] = 1;
    for (int i = 1; i < fact.size(); i++) {
        fact[i] = (i * fact[i - 1]) % HELL;
    }

    // using hockey stick identity
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int res = 0;
    for (int i = r1; i <= r2; i++) {
        res = (res + nck(i + c2 + 1, i + 1)) % HELL;
        res = (res + HELL - nck(i + c1, i + 1)) % HELL;
    }
    cout << res << endl;

    cerr << "TIME => " << now() - start << endl;
    return 0;
}

Measured memory_bytes: 31488
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main() {
	vector<vector<int>> mat(3, vector<int>(3));
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> mat.at(i).at(j);
		}
	}

	int diffB[2] = {mat.at(0).at(1) - mat.at(0).at(0), mat.at(0).at(2) - mat.at(0).at(1)};
	bool ret = true;
	for (int i = 0; i < 2; ++i) {
		if (mat.at(i + 1).at(1) - mat.at(i + 1).at(0) != diffB[0]) {
			ret &= false;
		}
		if (mat.at(i + 1).at(2) - mat.at(i + 1).at(1) != diffB[1]) {
			ret &= false;
		}
	}

	if (ret) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

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

const int INF = INT_MAX;
const int MAXN = 5000;
const int B = 200;
const int BNUM = MAXN / B;

int n, m;
pair<int, int> ps[MAXN];
int x[MAXN], y[MAXN];
vector<int> bucket[BNUM];

int main() {
  while(scanf("%d%d", &n, &m) != EOF) {
    for(int i = 0; i < n; ++i) {
      scanf("%d%d", &ps[i].first, &ps[i].second);
    }
    sort(ps, ps+n);
    fill(bucket, bucket + BNUM, vector<int>());
    for(int i = 0; i < n; ++i) {
      x[i] = ps[i].first;
      y[i] = ps[i].second;
      bucket[i/B].push_back(y[i]);
    }
    for(int b = 0; b < BNUM; ++b) {
      sort(bucket[b].begin(), bucket[b].end());
    }
    while(m--) {
      int s, t, u, v; 
      scanf("%d%d%d%d", &s, &t, &u, &v);
      int l = lower_bound(x, x+n, s) - x;
      int r = upper_bound(x, x+n, u) - x;
      int res = 0;
      while(l < r && l % B != 0) {
        res += (t <= y[l] && y[l] <= v);
        ++l;
      }
      while(l < r && r % B != 0) {
        --r;
        res += (t <= y[r] && y[r] <= v);
      }
      while(l < r) {
        int b = l / B;
        res += upper_bound(bucket[b].begin(), bucket[b].end(), v)
          - lower_bound(bucket[b].begin(), bucket[b].end(), t);
        l += B;
      }
      printf("%d\n", res);
    }
  }
  return 0;
}

Measured memory_bytes: 1316
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const int mod = 1e9;
using namespace std;
#define INF 1<<30

int N,A,B,C;
vector<int>l(8,0);

int dfs(int depth, int a, int b, int c) {
	if (depth == N) {
		if (a == 0 || b == 0 || c == 0)return INF;//限りなく大きい数を返して最小値の議論に入らないようにしている
		else return abs(a - A) + abs(b - B) + abs(c - C) - 30;//0本始まりであることと、ＡＢＣすべて1以上であることから
		//ＡＢＣの最初の竹のコストは考えなくてよいから余分に足した30を引いている
		//またこのときの差はＡＢＣそれぞれの増減魔法のコストを表している。(ここにたどり着いたということは合体魔法は終わっており、あと使えるのは増減魔法しかないから)
	}
	//recはコスト
	int rec = dfs(depth + 1, a, b, c);
	int rec_a = dfs(depth + 1, a + l[depth], b, c) + 10;
	int rec_b = dfs(depth + 1, a, b + l[depth], c) + 10;
	int rec_c = dfs(depth + 1, a, b, c + l[depth]) + 10;
	return min({ rec,rec_a,rec_b,rec_c });
}

int main() {
	cin >> N >> A >> B >> C;
	repp(i, 0, N)cin >> l[i];
	cout << dfs(0, 0, 0, 0)<< endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define NIL NULL

typedef struct node{
  int key;
  struct node *p;
  struct node *l;
  struct node *r;
}Node;

Node *T;

void insert(int);
void print(Node *);
void inorder(Node *);
void preorder(Node *);
Node *find(Node *,int);

int main()
{
  int n,i,k,j;
  char command[10];
  Node *z;

  //T->l=NIL;
  //T->r=NIL;
  
  scanf("%d",&n);
  if(n>500000) exit(1);
  for(i=0;i<n;i++){
      scanf("%s",command);
    if(command[0] == 'i'){
      scanf("%d",&k);
      insert(k);
    }
    else if(command[0] == 'p')
      print(T);
    else{
      scanf("%d",&k);
      z = find(T,k);
      if(z!=NIL) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

void insert(int k)
{
  Node *x,*y,*z;

  y = NIL; //xの親
  x = T;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->l=NIL;
  z->r=NIL;
  
  while(x != NIL){
    y = x; //親を設定
    if(z->key < x->key) x = x->l; //左の子に移動
    else x = x->r; //右の子に移動
  }
  z->p = y;
  
  if(y==NIL) //Tが空の場合
    T = z;
  else if(z->key < y->key)
    y->l = z; //zをyの左の子にする
  else
    y->r = z; //zをyの右の子にする
  //printf(" %d",x->p);
}

void print(Node *root)
{
  if(root==NIL) return;
  
  inorder(root); //左→上→右
  printf("\n");
  preorder(root); //左→右→上
  printf("\n");
}

void inorder(Node *root)
{
  if(root==NIL) return;
  inorder(root->l);
  printf(" %d",root->key);
  inorder(root->r);
}

void preorder(Node *root)
{
  if(root==NIL) return;
  printf(" %d",root->key);
  preorder(root->l);
  preorder(root->r);
}

Node *find(Node *x,int k)
{
  while(x != NIL && k != x->key){ //insertのとこと同じ要領
    if(k<x->key) x = x->l;
    else x = x->r;
  }
  return x;
}



Measured memory_bytes: 20500
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int gcdImpl(int a, int b) {
	return b ? gcdImpl(b, a % b) : a;
}

int gcd(int a, int b) {
	if (b > a) swap(a,b);
	return gcdImpl(a,b);
}

int gcdOnBlackboard(vector<int>& A) {
	int N = A.size(), ans = 0;
	vector<int> left(N);
	vector<int> right(N);
	
	left[0] = A[0];
	right[N-1] = A[N-1];
	
	for(int i = 1; i < N; i++)
		left[i] = gcd(left[i-1], A[i]);
	for(int i = N-2; i >= 0; i--)
		right[i] = gcd(right[i+1], A[i]);
	
	ans = max(left[N-2], right[1]);
	for(int i = 1; i < N-1; i++)
		ans = max(ans, gcd(left[i-1], right[i+1]));
	
	return ans;
}

int main() {
	int N;
	vector<int> A;
	
	int maxA = 0;
	scanf("%d", &N);
	for(int i = 0; i < N; i++) {
		int a;
		scanf("%d", &a);
		A.push_back(a);
	}
	
	printf("%d", gcdOnBlackboard(A));
}



Measured memory_bytes: 1528
n = int(input())
flg = False

res = []
for i in range(n):
    d1, d2 = map(int, input().split())
    res.append(int(d1 == d2))

for i in range(n):
    try:
        a = res[i] + res[i+1] + res[i+2]
    except:
        break
    if a == 3:
        flg = True
        break

if flg:
    print('Yes')
else:
    print('No')

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

int main() {
  int k;
  string s;
  cin >> k >> s;
  if(s.size()<=k) cout << s << endl;
  else cout << s.substr(0,k) << "..." << endl;

}


Measured memory_bytes: 3624
// D - Road to Millionaire
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int N; cin>>N;
	int64_t yen = 1000, stock = 0;
	int nxt; cin>>nxt;
	rep(i, N-1){
		int now = nxt; cin>>nxt;
		if(now < nxt){
			stock += yen / now;
			yen -= yen / now * now;
		}
		else{
			yen += stock * now;
			stock = 0;
		}
	}
	yen += stock * nxt;
	cout<< yen <<endl;
}


Measured memory_bytes: 3572
n, k = map(int, input().split())
A = list(map(int, input().split()))

all_sum = sum(A)

# 答え（約数）の候補リスト
divisors = []

# 全整数を足した値の約数が答えの候補
for i in range(1,all_sum+1):
    if i * i > all_sum:
        break
    if all_sum % i != 0:
        continue
    divisors.append(i)
    if all_sum // i != i:
        divisors.append(all_sum // i)

# 大きい値から順番に探索
divisors.sort(reverse=True)

def ok(d):
    # 答えの候補dで全値を割った余り
    a = [x % d for x in A]
    
    # 値を大きくする対象の整数の数（dを基準として、それより大きい/小さいの数を求める）
    move = n - sum(a) // d
    a.sort()
    # dで割り切れる値まで変化させる（大きく/小さくする）対象の整数について、
    # 目標の値まで値を変化させる合計値が、k以内に収まるか？
    return sum(a[:move]) <= k

for d in divisors:
    if ok(d):
        print(d)
        break

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define SORT(s) sort((s).begin(),(s).end())
#define SORTR(s) sort((s).begin(),(s).end(),greater<int>())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

int N; vi L;

void solve(){
    cin>>N;
    rep(i,N){int a; cin>>a; L.push_back(a);}
    SORT(L);
    int ans=0;
    rrepr(i,N-1,1){
        rrepr(j,i-1,0){
            auto iter=upper_bound(L.begin(),L.end(),L[i]-L[j]);
            int d=distance(iter,L.begin()+j);
            if(d>0) ans+=d;
            // cout<<L[i]<<" "<<L[j]<<" d: "<<distance(iter,L.begin()+j)<<"\n";
        }
    }
    cout<<ans<<endl;
    return;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <limits.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE 100100
#define NIL -1
#define MAX_N 100100

double sq(double num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;

int main() {
	cin >> n;
	ll ans = 0;
	rep(i, n) {
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
  std.functional, std.container, std.typecons;

void main() {
  auto input = readln.split.to!(int[]);
  int N = input[0], D = input[1];

  int[][] ps = new int[][N];
  foreach(ref p; ps) {
    p = readln.split.to!(int[]);
  }

  int[] tbl = new int[0];
  {
    int i = 1;
    int maxL = D * 40 * 40;
    while(i*i < maxL) { tbl ~= i*i; i++; }
  }
  auto dic = assumeSorted(tbl);

  ulong ans = 0;
  foreach(i; 0..(N-1)) {
    foreach(j; i..N) {
      int l = 0;
      foreach(k; 0..D) {
        auto a = ps[i][k] - ps[j][k];
        l += a*a;
      }
      if (dic.contains(l)) ans++;
    }
  }
  ans.writeln;
}


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

int main() {
  vector<int> vec1(4);
  for (int i=0; i<4; i++){
    cin >> vec1.at(i);
  }
  sort(vec1.begin(), vec1.end());
  vector<int> vec2;
  vec2 = {1, 4, 7, 9};
  if (vec1 == vec2){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;

}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// min b[i+1] + (w[n] - w[i + 1]) 0 <= i < n
func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	b := make([]int, n+1)
	for i := 0; i < n; i++ {
		b[i+1] = b[i]
		if s[i] == '#' {
			b[i+1]++
		}
	}
	ans := n
	for i := 0; i <= n; i++ {
		ans = min(ans, b[i]+n-i-b[n]+b[i])
	}
	fmt.Println(ans)
}


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

int n;
const int mod = 998244353;
using ll = long long;

void add(int &a, int b)
{
	a += b;
	if (a >= mod)
		a -= mod;
}
void sub(int &a, int b)
{
	a -= b;
	if (a < 0)
		a += mod;
}
int mult(int a, int b)
{
	return ll(a) * b % mod;
}
int bp(int a, int b)
{
	if (b == 0)
	{
		return 1;
	}
	if (b % 2 == 0)
	{
		int bv = bp(a, b / 2);
		return mult(bv, bv);
	}
	int bv = bp(a, b - 1);
	return mult(bv, a);
}
vector<int>facts(20000007), ofacts(20000007), inv(20000007);
void calc()
{
	facts[0] = 1;
	ofacts[0] = 1;
	facts[1] = 1;
	ofacts[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < 20000006; ++i)
	{
		int c1 = mod / i, md = mod % i, val=inv[md];
		val = mult(val, c1);
		inv[i] = mod - val;
	//	inv[i] = bp(i, mod - 2);
		facts[i] = mult(facts[i - 1], i);
		ofacts[i] = mult(ofacts[i - 1], inv[i]);
	}
}
int c(int a, int b)
{
	if (a < 0)
	{
		return 0;
	}
	if (b < 0)
	{
		return 0;
	}
	if (a > b)
	{
		return 0;
	}
	int bv = facts[b];
	bv = mult(bv, ofacts[b - a]);
	bv = mult(bv, ofacts[a]);
	return bv;
}
int main()
{
	calc();
	int n, a, b, ans=0;
	//cout << (inv[3]*3)%mod <<endl;
	cin >> n >> b >> a;
	b++;
	a++;
	for (int d = 0; d <= n; d++)
	{
		int anew = a - 1, bnew = b - 1 - d, turns = n - anew - bnew;
		if (turns>=0)
		{
			if (bnew >=0)
			{
				int val1 = 0, val2 = 0;
				if (anew > 0)
				{
					add(val1, c(bnew, bnew + anew - 1));
					sub(val1, c(bnew - 1, bnew + anew - 1));
				}
				else
				{
					if (anew == 0)
					{
						if (bnew == 0)
						{
							val1 = 1;
						}
					}
				}
				add(val2, c(turns , turns + d));
				sub(val2, c(turns , turns + d - 1));
				//cout << anew << ' ' << bnew << ' ' << turns << ' '<<d<<' '<<val1<<' '<<val2<<endl;
				add(ans, mult(val1, val2));
			}
		}
	}
	cout << ans << endl;
	cin >> n;
}


Measured memory_bytes: 234624
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
	cin >>n;
	int t;
	int sum=0;
	for(t=1;;t++){
		sum+=t;
		if(n<=sum){
			break;
		}
	}
	cout<< t<<endl;
	

}


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

char Right[11] = {'y','u','i','o','p','h','j','k','l','n','m'};

int main(){
	string str;
	while(cin >> str){
		if(str[0] == '#') break;
		int ans = 0;
		bool position = false;
		for(int i = 0; i < 11; i++){
			if(Right[i] == str[0]){
				position = true;
				break;
			}
		}
		for(int i = 1; i < str.size(); i++){
			bool now = false;
			for(int j = 0; j < 11; j++){
				if(Right[j] == str[i]){
					now = true;
					break;
				}
			}
			if(position != now){
				ans++;
				position = now;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1180
function main(input) {
    var n, k, a, b, tmp, i, m = new Map(), keys=[], size, cnt = 0;
    tmp = input[0].split(" ");
    n = parseInt(tmp[0], 10);
    k = parseInt(tmp[1], 10);

    for (i = 0; i < n; i++) {
        tmp = input[1+i].split(" ");
        a = (parseInt(tmp[0], 10));
        b = (parseInt(tmp[1], 10));
        if(m.has(a)){
            m.set(a, m.get(a)+b);
        }else{
            m.set(a, b);
            keys.push(a);
        }
    }

    size = keys.length;
    keys.sort(function (self, other) {
        if (self < other) {
            return -1;
        } else if (self > other) {
            return 1;
        } else {
            return 0;
        }
    });
    for (i = 0; i < size; i++) {
        cnt += m.get(keys[i]);
        if(cnt >= k){
            console.log(keys[i]);
            break;
        }
    }
}

main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));

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

using namespace std;
typedef long long ll;

const int N = 2e5 + 5;
int n;
ll h[N], a[N], tree[N], answer;
map<ll, ll> val;

void update(ll x, ll v) {
	for (; x <= N; x += x & -x) {
		tree[x] = max(tree[x], v);
	}
}

ll query(ll idx) {
	ll ret = -1e18;
	while (idx > 0) {
		ret = max(ret, tree[idx]);
		idx -= idx & -idx;
	}
	return ret;
}

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

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> h[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		val[h[i]] = a[i];
	}
	for (int i = 1; i <= n; i++) {
		update(h[i], query(h[i]) + val[h[i]]);
	}
	for (int i = 1; i < N; i++) {
		answer = max(answer, tree[i]);
	}
	cout << answer;

	return 0;
}


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

int main(){

ll X;
cin>>X;

ll x = 100;

for(ll i = 1 ; ; i++){
    x = x / 100 + x ;
    if(x>=X){
        cout<<i<<endl;
        return 0;
    }
}



}


Measured memory_bytes: 3636
#中国人郵便問題 
import sys
input = sys.stdin.readline

INF = float('inf')

v, e = map(int, input().split())
adj = [[INF]*v for _ in range(v)]
for i in range(v):
    adj[i][i] = 0
odd_vertices = [0]*v
total_d = 0

for _ in range(e):
    s, t, d = map(int, input().split())
    adj[s][t] = adj[t][s] = min(adj[s][t], d)
    odd_vertices[s] ^= 1
    odd_vertices[t] ^= 1
    total_d += d

def warshall():
    for k in range(v):
        for i in range(v):
            for j in range(v):
                if adj[i][k] != INF and adj[k][j] != INF:
                    adj[i][j] = min(adj[i][j],adj[i][k] + adj[k][j])
def solve():
    if sum(odd_vertices) == 0:
        return total_d
    else:
        warshall()
        odd = []
        for i in range(v):
            if odd_vertices[i] == 1:
                odd += [i]
        n = len(odd)
        dp = [INF]*(1<<n)
        dp[0] = 0
        for state in range(1<<n):
            for sp in range(n):
                if not((state>>sp) & 1):
                    for ep in range(n):
                        d = adj[odd[sp]][odd[ep]]
                        if sp != ep and not((state>>ep) & 1) and d != INF:
                            new_state = state|(1<<sp)|(1<<ep)
                            dp[new_state] = min(dp[new_state], dp[state]+d)

    return total_d + dp[-1]

print(solve())


Measured memory_bytes: 5648
#include <bits/stdc++.h>
using namespace std;
int mod=1000000007;
int main(){
  int n;
  cin >> n;
  vector<int> s;
  vector<int> c(n);
  for(int i=2;i<=n;i++){
    bool f=true;
    for(int j=2;j<i;j++){
      if(i%j==0){
        f=false;
      }
    }
    if(f){
      s.push_back(i);
    }
  }
  for(int i=1;i<=n;i++){
    int k=i;
    for(int j=0;j<s.size();j++){
      while(k%s[j]==0){
        k/=s[j];
        c[j]++;
      }
    }
  }
  long long ans=1;
  for(int i=0;i<n;i++){
    if(c[i]!=0){
      ans=ans*(c[i]+1)%mod;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int h, w;
    cin >> h >> w;
    vector<int> acnt(26);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            char c;
            cin >> c;
            ++acnt[c - 'a'];
            acnt[c - 'a'] %= 4;
        }
    }

    int cnt[4];
    for (int i = 0; i < 26; ++i) {
        ++cnt[acnt[i]];
    }

    if (h % 2 != w % 2) {
        int even = h % 2 == 0 ? h : w;
        cout << (cnt[1] == 0 && cnt[2] <= even / 2 && cnt[3] == 0 ? "Yes" : "No") << endl;
    } else if (h % 2 == 0) {
        cout << (cnt[1] == 0 && cnt[2] == 0 && cnt[3] == 0 ? "Yes" : "No") << endl;
    } else {
        cout << (cnt[1] == 1 && (cnt[2] <= h / 2 + w / 2) && cnt[3] == 0 ? "Yes" : "No") << endl;
    }
    return 0;
}

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

int a[500],b,c,d,e,f,g,n,alice,bob;

int main(){

    cin>>n;

    for(int i=0;i<n;i++){
        cin>>a[i];
    }

    sort(a,a+n);
    reverse(a,a+n);

    for(int i=0;i<n;i++){
        if(i%2==0)alice+=a[i];
        if(i%2==1)bob+=a[i];
    }
    cout<<alice-bob<<endl;

}



Measured memory_bytes: 256
#include <stdio.h>

int main (){
	//belum selesai masalah kalau input angka 0
	int A,B,x,y,z;
	scanf("%d %d",&A,&B);
	x=A+B;
	y=A-B;
	z=A*B;
	if(x>y && x>z){
		printf("%d\n",x);
	}
	else if(y>x && y>z){
		printf("%d\n",y);
	}
	else if(z>y && z>x){
		printf("%d\n",z);
	}
	else if(A==0 && B==0){
		printf("0\n");
	}
	else if(A==0||B==0){
		printf("%d\n",x);
	}
	return 0;
}

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

int main() {
	int n;
	char str[10], com[13];
	map<string, bool> T;

	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%s%s", com, str);
		if (com[0] == 'i')T[string(str)] = true;
		else {
			if (T[string(str)]) printf("yes\n");
			else printf("no\n");
		}
	}
	return 0;
}


Measured memory_bytes: 47496
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;

LL ans = 0,mxd;
LL edg[55][55],dis[55][55];
LL n,a[55],b[55];

LL highbit(LL x){
	LL cnt = 0;
	while(x){ cnt ++; x >>= 1; }
	return cnt - 1;
}

void del(LL x){
	for(LL i = 0;i <= 50;i ++) edg[i][i % x] = 0;
}

void floyd(){
	memset(dis,INF,sizeof(dis));
	for(LL i = 0;i <= 50;i ++){
		for(LL j = 0;j <= 50;j ++){
			dis[i][j] = edg[i][j];
		}
	}
	for(LL k = 0;k <= 50;k ++){
		for(LL i = 0;i <= 50;i ++){
			for(LL j = 0;j <= 50;j ++){
				dis[i][j] = min(dis[i][j],dis[i][k] + dis[k][j]);
			}
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	memset(edg,INF,sizeof(edg));
	for(LL i = 0;i <= 50;i ++) edg[i][i] = 0;
	for(LL i = 0;i <= 50;i ++){
		for(LL j = 1;j <= 50;j ++){
			edg[i][i % j] = min(edg[i][i % j],(1LL << j));
		}
	}
	floyd();
	
	cin >> n;
	for(LL i = 1;i <= n;i ++) cin >> a[i];
	for(LL i = 1;i <= n;i ++) cin >> b[i];
	for(LL i = 1;i <= n;i ++) if(a[i] < b[i]){ cout << -1 << endl; return 0; }
	
	while(1){
		mxd = 0;
		for(LL i = 1;i <= n;i ++) mxd = max(mxd,dis[a[i]][b[i]]);
		if(!mxd) break;
		if(mxd == INF){ cout << -1 << endl; return 0; }
		
		del(highbit(mxd)); floyd();
		ans += (1LL << highbit(mxd));
	}
	cout << ans << endl;
	return 0;
}

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

leftCount = 0
rightCount = 0
mod = 10**9 + 7

for i in range(n):
    for j in range(n):
        if arr[i] > arr[j]:
            if i < j:
                rightCount +=1
            else:
                leftCount +=1
leftCount = leftCount*k*(k-1)//2
rightCount = rightCount*k*(k+1)//2
count = (leftCount % mod) + (rightCount % mod)
count %= mod
print(count)

Measured memory_bytes: 3188