akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <iostream>
#define mod 1000000007
using namespace std;
int n, p[22], e[55][22], dp[55][55][22]; string s[55];
int solve(int l, int r, int k) {
	if(r - l == 0) return 1;
	if(r - l == 1) return p[e[l][k]];
	if(dp[l][r][k]) return dp[l][r][k] - 1;
	int dp2[55][30] = {0}; dp2[l][0] = 1;
	for(int a = l + 1; a <= r; a++) {
		int sum[55] = {0};
		for(int b = 1; b <= 26; b++) {
			for(int c = l; c < r; c++) sum[c] = (sum[c] + dp2[c][b - 1]) % mod;
			for(int c = a - 1; c >= l; c--) {
				if((s[c][k] != '?' && s[c][k] != b + 96) || (c + 1 != a && s[c + 1].size() == k + 1)) break;
				int res = (s[c].size() == k + 1) ? solve(c + 1, a, k + 1) : solve(c, a, k + 1);
				dp2[a][b] = (dp2[a][b] + 1LL * sum[c] * res) % mod;
			}
		}
	}
	int ret = 0;
	for(int i = 1; i <= 26; i++) ret = (ret + dp2[r][i]) % mod;
	dp[l][r][k] = ret + 1;
	return ret;
}
int main() {
	cin >> n; p[0] = 1;
	for(int i = 1; i <= 20; i++) p[i] = 1LL * p[i - 1] * 26 % mod;
	for(int i = 0; i < n; i++) {
		cin >> s[i];
		for(int j = s[i].size() - 1; j >= 0; j--) e[i][j] = e[i][j + 1] + (s[i][j] == '?' ? 1 : 0);
	}
	printf("%d\n", solve(0, n, 0));
}

Measured memory_bytes: 3688
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int A, B;
  int ans = 0;

  cin >> A >> B;

  if(B % A == 0){
    cout << A+B << endl;
  }else{
    cout << B-A << endl;
  }
}


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

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  if(n&1){
    cout<<"No"<<endl;
    return 0;
  }
  for(int i=0,j=n/2;j<n;j++,i++){
    if(s[i]!=s[j]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> A(N, vector<int>(M, 0));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            cin >> A[i][j];
            A[i][j] --;
        }
    }

    vector<bool> used(M, false);

    int ans = N;
    for (int i = 0; i < M; ++i) {
        vector<int> num(M, 0);
        for (int j = 0; j < N; ++j) {
            for (int a : A[j]) {
                if (!used[a]) {
                    num[a] ++;
                    break;
                }
            }
        }
        auto it = max_element(num.begin(), num.end());
        int id = std::distance(num.begin(), it);
        int k = *it;
        // cout << id << ", " << k << endl;
        used[id] = true;
        ans = min(ans, k);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair< ll, ll > pll;
typedef pair< int, int > pii;

const double pi = 3.14159265358979323846;

// #define fio() cin.tie(0); ios::sync_with_stdio(false);
// template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
// template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define TG0 get< 0 >
#define TG1 get< 1 >
#define TG2 get< 2 >
#define F first
#define S second
#define VL vector< ll >

// to_string(123)
// atoi("123"); atoi(s.c_str());
// "abc".size()
// s.find('+') == string::npos
// 1e18

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

  ll N, M;
  cin >> N >> M;

  ll s[M], c[M];
  for (ll i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }

  string S;
  ll slen;
  bool bingo;
  for (ll i = 0; i <= 999; i++) {
    S = to_string(i);
    slen = S.length();

    bingo = true;

    if (slen != N) {
      bingo = false;
      continue;
    }

    for (ll i = 0; i < M; i++) {

      if (slen < s[i]) {
        bingo = false;
        break;
      }

      if (S[s[i] - 1] != (c[i] + '0')) {
        // cerr << S << endl;
        bingo = false;
        break;
      }
    }

    if (bingo) {
      cout << S << endl;
      return 0;
    }
  }

  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[207];
int main(){
    int n;
    for(int i=0;i<3;i++){
    	cin>>n;
    	a[n+100]++;
    }
    for(int i=0;i<=200;i++){
    	if(a[i]==1)printf("%d\n",i-100);
    }
}


Measured memory_bytes: 256
/*input
4 5
1 2
2 3
2 4
4 1
4 3
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=1005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int main() {
	int n;
	cin >> n;
	int ans = 0;
	map<int, int> mp;
	vector<int> b(n);
	REP(i,n){
		cin >> b[i];
		mp[b[i]] = 0;
	}
	int cnt = 0;
	for (auto &i : mp) {
		i.second = ++cnt;
	}

	REP(i,n){
		if (mp[b[i]] % 2 == i % 2) {
			ans++;
		}
	}
	cout<<ans/2;
}


Measured memory_bytes: 5376
import math
n=int(input())
l=math.floor(math.sqrt(n))
k=math.floor(math.log10(n))+1

for i in range(2,l+1):
    if n%i==0:
        a,b=i,n//i
        x=max(math.floor(math.log10(a))+1,math.floor(math.log10(b))+1)
        k=min(x,k)
print(k)

Measured memory_bytes: 64372
line = input().split()
stack = []
ans = 0
for elem in line:
    if elem in ['+', '-', '*']:

        ele2 = int(stack.pop())
        ele1 = int(stack.pop())
        if elem == '+':
            tmp = ele1 + ele2
        if elem == '-':
            tmp = ele1 - ele2
        if elem == '*':
            tmp = ele1 * ele2
        stack.append(tmp)
    else:
        stack.append(elem)
print(stack[0])



Measured memory_bytes: 5600
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long gap = 0;
		if (A%2 != 0 && B%2 != 0 && C%2 != 0) {
			long max = Math.max(A, Math.max(B, C));
			long min = Math.min(A, Math.min(B, C));
			long mid = A+B+C-max-min;
			long a = max/2;
			long b = max - a;
			gap = b*min*mid - a*min*mid;
		}
		System.out.println(gap);
	}
}

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

int main() {
	int A, B;
	cin >> A >> B;
	if (A <= 8 && B <= 8) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1020000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 998244353;



int main(){
	ll n; cin >> n;
	vl a(n); rep(i,n) cin >> a[i];
	if(n & 1){
		ll s = 0;
		rep(i,n) s += a[i];
		if(s & 1) puts("First");
		else puts("Second");
	}else{
		ll cnt = 0, mn = inf;
		rep(i,n){
			chmin(mn,a[i]);
			if(a[i] & 1) cnt++;
		}
		if(mn & 1) puts("First");
		else{
			if(cnt & 1) puts("First");
			else puts("Second");
		}
	}
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define MAXN 200005
#define INF 999999999999999LL
using namespace std;
ll n,a[MAXN],bl,br,bm,bo,cls,ans;
bool ab[MAXN];
int main(){
    cin>>n; n=2*n-1;
    for (int i=0; i<n; i++) scanf("%lld",&a[i]);

    bl=1; br=n;
    while(bl<=br){
        bm=(bl+br)/2;

        for (int i=0; i<n; i++)
            if (a[i]>=bm) ab[i]=1; else ab[i]=0;
        
        cls=INF; bo=ab[0];
        for (int i=0; i<n; i++){
            if (i<n-1 && ab[i]==ab[i+1]){
                if (abs(n/2-i)<cls) { cls=abs(n/2-i); bo=ab[i]; }
                
                while(i<n-1 && ab[i]==ab[i+1]) i++;

                if (abs(n/2-i)<cls) { cls=abs(n/2-i); bo=ab[i]; }
            }
        }

        if (bo) { ans=bm; bl=bm+1; }
        else br=bm-1;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<string>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a%3==0||b%3==0||(a+b)%3==0)
cout<<"Possible"<<endl;
else
cout<<"Impossible"<<endl;
}

Measured memory_bytes: 256
using System;
public class Hello{
    public static void Main(){
        int[] n = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
        int a = n[0];
        int b = n[1];
        int k = n[2];
        
        if(b - a + 1 < k * 2){
            for(int i = a;i <= b;i++){
                Console.WriteLine(i);
            }
        }else{
            for(int i = 0;i < k;i++){
                Console.WriteLine(a + i);
            }
            for(int j = 0;j < k;j++){
                Console.WriteLine(b - k + 1 + j);
            }
        }
     }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    char n;
    cin>>n;
    if(n=='a' || n=='e' || n=='i' || n=='o'||n=='u'){
        cout<<"vowel"<<endl;
    }
    else{
        cout<<"consonant"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define LL long long
#define MOD 1000000007
#define MX 80
char s1[MX];
char s2[MX];

int main()
{
    int n;
    scanf("%d",&n);
    scanf("%s",s1);
    scanf("%s",s2);
    int p=0;
    LL ans = 1;
    while(p<n)
    {
        if (s1[p]==s2[p])
        {
            if (p==0)
                ans*=3;
            else
            {
                if (s1[p-1]==s2[p-1])
                    ans = (ans*2)%MOD;
            }
            p++;
        }
        else// =
        {
            if (p==0)
            {
                ans = (ans*6)%MOD;
            }
            else
            {
                if (s1[p-1]!=s2[p-1])
                    ans = (ans*3)%MOD;
                else
                    ans = (ans*2)%MOD;
            }
            p+=2;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
    ll n;
    cin >> n;
    ll nnn;
    nnn=n;
    queue <ll> a35,a37,a57,b,aa,bb,kara;
    int k=0;
    while(n!=0){
        n/=10;
        k+=1;
    }
    ll ans=0;
    ll e=0;
    int l=0,l2=0;
    if(k<=2){
        cout << 0 << endl;
    }
    else{
        a35.push(35);
        a37.push(37);
        a35.push(53);
        a57.push(57);
        a37.push(73);
        a57.push(75);
        rep(i,k-2){
            bb=kara;
            aa=kara;
            l=a35.size();
            l2=b.size();
            ans+=l2;
            ll x;
            rep(j,l2){
                x=b.front();
                b.pop();
                bb.push(x*10+3);
                bb.push(x*10+5);
                bb.push(x*10+7);
            }
            rep(j,l){
                x=a35.front();
                a35.pop();
                bb.push(x*10+7);
                aa.push(x*10+3);
                aa.push(x*10+5);
            }
                e=0;
                rep(jj,i+2){
                    e+=pow(10,jj)*3;
                }
                aa.push(e*10+5);
                e=0;
                rep(jj,i+2){
                    e+=pow(10,jj)*5;
                }
                aa.push(e*10+3);
            
            a35=aa;
            aa=kara;
            rep(j,l){
                x=a37.front();
                a37.pop();
                bb.push(x*10+5);
                aa.push(x*10+3);
                aa.push(x*10+7);
                
                
            }
            e=0;
            rep(jj,i+2){
                    e+=pow(10,jj)*3;
                }
                aa.push(e*10+7);
                e=0;
                rep(jj,i+2){
                    e+=pow(10,jj)*7;
                }
                aa.push(e*10+3);
            a37=aa;
            aa=kara;
            rep(j,l){
                x=a57.front();
                a57.pop();
                bb.push(x*10+3);
                aa.push(x*10+5);
                aa.push(x*10+7);
            }
                e=0;
                rep(jj,i+2){
                    e+=pow(10,jj)*5;
                }
                aa.push(e*10+7);
                e=0;
                rep(jj,i+2){
                    e+=pow(10,jj)*7;
                }
                aa.push(e*10+5);
            
            a57=aa;
            aa=kara;
            b=bb;
        }
    
    //cout << ans << endl;

    ll nn=b.size();
    ll p;
    rep(i,nn){
        p=b.front();
        b.pop();
        
        if(p<=nnn){
            ++ans;
            //cout << p << endl;
        }
    }

    cout << ans << endl;

    
    }
    return 0;
}

Measured memory_bytes: 4404
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int R[] = new int[N];
		int i, j;
		int min=Integer.MAX_VALUE;
		int max=Integer.MIN_VALUE;
		for(i=0; i<N; i++){
			R[i] = sc.nextInt();
		}
		for(i=0; i<N-1; i++){
			if(min<=R[i]) continue;
			min=R[i];
			for(j=i+1; j<N; j++){
				if(max<R[j]-R[i]) max=R[j]-R[i];
			}
		}
		System.out.println(max);
	}
}

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

vector<int>adjList[100005];

int nodeWeight[100005];
int distances[100005];
int backNode[100005];
int n,a,b,pathLength=0;
int dfs(int node,int dist, int bk){
    distances[node]=dist;
    if(node==n-1)pathLength=dist+1;//including root
    backNode[node]=bk;
    if(adjList[node].size()==1 && node!=0){
        return nodeWeight[node]=1;
    }
    int ans=1;
    for(int i=0;i<adjList[node].size();i++){
        if(adjList[node][i]!=bk){
            ans+=dfs(adjList[node][i],dist+1,node);
        }
    }
    return nodeWeight[node]=ans;
}

int main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        adjList[a-1].push_back(b-1);
        adjList[b-1].push_back(a-1);
    }

    dfs(0,0,-1);

//    for(int i=0;i<n;i++){
//        cout<<i<<" <- "<<nodeWeight[i]<<" - "<<distances[i]<<" - "<<backNode[i]<<endl;
//    }

    int l=n-1;
    int fennec=0, snuke=0;
    int m=pathLength/2;
    int b=l;
    while(m--){
        snuke+=(nodeWeight[b]-snuke);
        b=backNode[l];
        l=b;
    }
    fennec=n-snuke;

    if(fennec>snuke)cout<<"Fennec\n";
    else cout<<"Snuke\n";
//    cout<<fennec<<" - "<<snuke<<endl;

}


Measured memory_bytes: 14720
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
using namespace std;
using lint = long long;
using ld = long double;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
#pragma endregion

const lint INF = 1ll << 60;
const int mod = 1000000007;



int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n; cin >> n;
	vector<lint> data(n, INF);
	lint ans = 0;
	for (int i = 0; i < n; i++) {
		int s; cin >> s;
		int p = upper_bound(data.begin(), data.end(), -s) - data.begin();
		if (data[p] == INF) ans++;
		data[p] = -s;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
int main() {
  int abc[3];
  cin >> abc[0] >> abc[1] >> abc[2];
  sort(abc,abc+3);
  if (abc[0]+abc[1] == abc[2]) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
N = input()
L = list(map(int, input().split()))

ans = 0
for i in range(len(L)-2):
    for j in range(i+1, len(L)-1):
        for k in range(j+1, len(L)):
            if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                continue
            elif L[i] + L[j] <= L[k] or L[j] + L[k] <= L[i] or L[k] + L[i] <= L[j]:
                continue
            else:
                ans += 1
print(ans)


Measured memory_bytes: 73688
import Control.Applicative
import Data.List

readInts :: IO [Int]
readInts = map read . words <$> getLine

getLines :: IO [[Int]]
getLines = do
  [m, f, r] <- readInts
  if m == -1 && f == -1 && r == -1
     then return []
     else do
       rest <- getLines
       return ([m, f, r] : rest)

calc :: Int -> Int -> Int -> String
calc m f r
  | m == -1 || f == -1 = "F"
  | m + f >= 80 = "A"
  | m + f >= 65 = "B"
  | m + f >= 50 = "C"
  | m + f >= 30 = if r >= 50 then "C" else "D"
  | otherwise = "F"

main :: IO ()
main = do
  xs <- getLines
  putStrLn $ intercalate "\n" [calc m f r | [m, f, r] <- xs]

Measured memory_bytes: 4028
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val H, W, K = in.nextInt

  val fibList: Stream[Int] = 1 #:: 1 #:: fibList.zip(fibList.tail).map(t => t._1 + t._2)
  def fib(i: Int): Int = if (i < 0 || W - 1 < i) 1 else fibList(i)
  val Mod = 1000000007

  def next(step: Int, counts: Array[Long]): Array[Long] = {
    if (step == H) counts
    else {
      val nextCounts = Array.fill(W)(0L)
      (0 until W).foreach {i =>
        if (i > 0)     nextCounts(i - 1) += counts(i) * fib(i - 1) * fib(W - i - 1)
                       nextCounts(i    ) += counts(i) * fib(i - 0) * fib(W - i - 1)
        if (i < W - 1) nextCounts(i + 1) += counts(i) * fib(i - 0) * fib(W - i - 2)
      }
      next(step + 1, nextCounts.map(_ % Mod))
    }
  }

  println(next(0, Array.tabulate(W)(i => if (i == 0) 1L else 0L))(K - 1))
}

Measured memory_bytes: 27468
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main() {
  int h,w; 
  cin >> h >> w;
  vector<vector<int>> a(510, vector<int>(510,0));
  vector<P> c;
  vector<pair<P,P>> ans;
  vector<int> used(h,0);
  rep(i,h){ rep(j,w){
    int tmp;
    cin >> tmp; 
    a[i][j] += tmp;
    if(a[i][j]%2==1 && j!=w-1){
      ans.push_back({{i,j},{i,j+1}});
      a[i][j+1]++;
    }
  }}
  rep(i,h){
    if(a[i][w-1]%2==1 && i!=h-1){
      ans.push_back({{i,w-1},{i+1,w-1}});
      a[i+1][w-1]++;
    }
  }
  
  cout << ans.size() << endl;
  for(auto d:ans){
    cout << d.F.F+1 << " " << d.F.S+1 << " " << d.S.F+1 << " " << d.S.S+1 << endl;    
  }
  return 0;
}


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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    ll h;
    cin >> h >> n;
    ll ret = 0;
    for(i=0;i<n;i++){
        cin >> m;
        ret+=m;
    }
    if(ret>=h){
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int max(int a, int b);
void findLCS(char *X, char *Y, int XLen, int YLen);

int max(int a, int b) {
	return (a > b)? a : b;
}

void findLCS(char *X, char *Y, int XLen, int YLen) {
	int L[XLen + 1][YLen + 1];
	int r, c, i;

	/*
	 * find the length of the LCS
	 */
	for(r = 0; r <= XLen; r++) {

		for(c = 0; c <= YLen; c++) {

			if(r == 0 || c == 0) {

				L[r][c] = 0;

			} else if(X[r - 1] == Y[c - 1]) {

				L[r][c] = L[r - 1][c - 1] + 1;

			} else {

				L[r][c] = max(L[r - 1][c], L[r][c - 1]);
			}
		}
	}

	/*
	 * Print LCS
	 */
	r = XLen;
	c = YLen;
	i = L[r][c];

	char LCS[i+1];

	/*
	 * setting the NULL character at the end of LCS character array.
	 * as we know in C programming language, NULL character is used
	 * to denote the end of a string
	 */
	LCS[i] = '\0';

	while(r > 0 && c > 0) {

		if(X[r - 1] == Y[c - 1]) {

			LCS[i - 1] = X[r - 1];

			i--;
			r--;
			c--;

		} else if(L[r - 1][c] > L[r][c - 1]) {

			r--;

		} else {

			c--;

		}

	}

	//print result
	printf("%s\n", LCS);
}

int main(void) {
	//the two sequences
	char X[3005];
	char Y[3005];
	scanf("%s %s",X,Y);
	//length of the sequences
	int XLen = strlen(X);
	int YLen = strlen(Y);

	findLCS(X, Y, XLen, YLen);

	return 0;
}

Measured memory_bytes: 35328
#include <stdio.h>
#include <string.h>

int main(){
    int i;
    char a[5];
    
    scanf("%s",a);
    
    for(i=0;a[i]!='\0';i++){
        if(a[i]=='1'){
            a[i]='9';
        }
        else if(a[i]=='9'){
            a[i]='1';
    }
    
    }
    
    printf("%s\n",a);
    
    return 0;
}

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

int main() {
  vector<int> i;
  i = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << i.at(K-1)<<endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

      int n = Integer.parseInt(br.readLine());
      int minv = Integer.parseInt(br.readLine());
      int n1   = Integer.parseInt(br.readLine());
      int maxv = n1- minv;
      if ( n1 < minv ) minv = n1;

      for( int i=2,r,mv; i<n; i++) {
        r = Integer.parseInt(br.readLine());
        if ( r < minv ) minv = r;
        else if ( (mv = r-minv) > maxv ) maxv = mv;
      }

      System.out.println(maxv);
    }
  }
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;
void Tree_insert(int);
void Tree_print(int);


int main(){
  int n,x,i;
  char c[10];

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%s",c);
    
    if(c[0] == 'i'){
      scanf("%d",&x);
      Tree_insert(x);
    }
    
    if(c[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  
  return 0;
}

void Tree_insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  
  while(x!=NIL){
    y=x;
    
    if(z->key < x->key){
      x = x->left;
    }
    
    else{
      x = x->right;
    }
  }
    z->parent = y;

    if(y==NIL){
      root=z;
    }
    
    else if(z->key < y->key){
      y->left = z;
    }
    
    else {
      y->right = z;
    }
  
}

void inorder(Node u){

  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }

}

void preorder(Node u){

  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }  
}

Measured memory_bytes: 24040
X=gets.to_i;gets;r=[l=m=k=0,0,*gets.split.map(&:to_i)];gets;h=X
p *$<.map{|e|
	t,a=e.split.map &:to_i
	(l=[X,[l+z=(-1)**k*(r[k+1]-r[k]),0].max].min;h=[X,[h+z,0].max].min;m+=z;k+=1)while k<r.size-1&&t>=r[k+1]
	[X,[(-1)**k*(t-r[k])+[h,[l,a+m].max].min,0].max].min
}

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

namespace ABC128A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, n;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            n = (a * 3 + b) / 2;

            Console.WriteLine(n);
            
            Console.ReadKey();       
        }
    }
}


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

int main() {
  int n; cin >>n;
  vector<ll> a(n),sum_a(n,0);
  rep(i,n) cin >> a[i];
  ll sum=0;
    for(int i=n-1;i>=0;i--){
       sum+=a[i];
       sum_a[i]=sum;
    }
  ll ans=10000000000000000;
  for(int i=1;i<n;i++){
    ll snuke=sum_a[0]-sum_a[i];
    ll arai=sum_a[i];
    ll d=abs(snuke-arai); ans=min(ans,d);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

int n, q;
int cnt[100009];

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

    cin >> n;
    ll sum = 0;
    rep(i, n) {
        int a;
        cin >> a;
        cnt[a]++;
        sum += a;
    }
    cin >> q;
    while(q--) {
        int b, c;
        cin >> b >> c;
        sum += 1LL * (c - b) * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << "\n";
    }

    return 0;
}

Measured memory_bytes: 4004
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F(i,a,n) for(int i=a;i<n;i++)
#define mod 1000000007 
#define pb push_back
int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int w=1;
	// cin>>w;
	while(w--){
		long long a,b,c,d;
		cin>>a>>b>>c>>d;
		cout<<max(max(a*c,b*d),max(a*d,b*c));
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  int c = a + b;
  if (c % 2 ==0){
    cout << c / 2 << endl;
  }
  else {
    cout << c / 2 + 1 << endl;
  }
}

Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
#print(n)
#print(p)
a=0
i=1

for i in range(1,n-1):

    if (p[i-1]<p[i]<p[i+1]) or (p[i+1]<p[i]<p[i-1]):
        a=1+a
print(a)
    #sumir=vie(i)+sumir
#print("")
#print(sumir)


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#define N 10005
int i,j,k,l,n;char c[N],x[N],y[N];
inline void solve()
{
	for(i=j=1;i<=n;i=j)
	{
		while(c[i]==c[j])j++;
		if(k>12||j-i<<k>=n)
		{
			memset(x,c[i],n);
			if(strcmp(x,y)<0)memcpy(y,x,n);
		}
		else if((j-i<<k)+(n<<1)-j+1>=n)
		{
			memset(x,c[i],j-i<<k),memcpy(x+(j-i<<k),c+j,n-(j-i<<k));
			if(strcmp(x,y)<0)memcpy(y,x,n);
		}
	}
}
int main()
{
	scanf("%d%d%s",&n,&k,c+1),k--;
	for(i=1,j=n<<1;i<=n;c[j--]=c[i++])y[i-1]='z';
	solve();
	if(k>1)
	{
		for(i=1,j=n<<1;i<=n;i++,j--)c[i]^=c[j]^=c[i]^=c[j];
		solve();
	}
	return 0*printf("%s\n",y);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
 
/*
int bubbleSort(int A[], int n) {
    int i, j, t, s;
    int cnt = 0; // 反転数
    for(i=0;i<n-1;i++) {
        for(j=n-1,s=i+1;j>=s;j--) {
            if(A[j] < A[j-1]) {
                t = A[j];
                A[j] = A[j-1];
                A[j-1] = A[j];
                cnt++;
            }
        }
    }
   
    return cnt;
}
*/
 
long long int A[200005];
long long int merge_count(int l, int r){
    long long int count = 0;
    int i, j, k;
    int n = r - l;
    if(n > 1){
        long long int b[n+5];
        int m = l + n/2;
        count += merge_count(l, m);
        count += merge_count(m, r);
        memcpy((void*)b, (void*)&A[l], sizeof(b));
        for(i = l, j = 0, k = n/2; i < r; ++i){
            if(j == n/2) {
                A[i] = b[k++];
            } else if(k == n) {
                A[i] = b[j++];
            } else if(b[j] <= b[k]) {
                A[i] = b[j++];
            } else {
                A[i] = b[k++];
                count += n/2 - j;
            }
        }
    }
    return count;
}
 
long long int bubble_sort(int n) {
    return merge_count(0, n);
}
 
int main(void) {
    int i, n;
    scanf("%d\n", &n);
     
    for(i=0;i<n;i++) {
        scanf("%lld", &A[i]);
    }
     
    printf("%lld\n", bubble_sort(n));
 
    return 0;
}

Measured memory_bytes: 5300
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;
const int MOD = 1000000007;
 
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll dp[100100];

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int x;
    cin >> x;
    if(x == 7 or x == 5 or x == 3) print("YES");
    if(x != 7 and x != 5 and x != 3) print("NO");
}

Measured memory_bytes: 764
#include<iostream>
using namespace std;
int main(void){
    long long n,y;
    cin>>n;
    long long a[n];
    for(int i=0;i<n;i++){cin>>a[i];a[i]*=2LL;}
    y=a[0];
    for(int i=1;i<n;i++)y+=a[i]*(i%2?-1LL:1LL);
    y=y/2LL;
    for(int i=0;i<n;i++){cout<<y<<"\n "[i!=n-1];y=a[i]-y;}
    return 0;
}

Measured memory_bytes: 2048
# Problem: https://atcoder.jp/contests/arc096/tasks/arc096_a
# Python 2nd Try

import sys
# from collections import defaultdict
# import heapq,copy
import pprint as pp
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


# Const
MAXSIZE = ( 1 << 31 ) -1
MINSIZE = -( 1 << 31) + 1
MAXSHEET = 10**5

def solver(a_price, b_price, ab_price, x_sheet , y_sheet):
    result = MAXSHEET*a_price+MAXSHEET*b_price
    for j in range(0, 2*MAXSHEET+1, 2):
        a_buy_sheet = max(x_sheet-j//2,0)
        b_buy_sheet = max(y_sheet - j//2, 0 )
        total = ( a_buy_sheet*a_price + b_buy_sheet*b_price +
                                         j*ab_price )
#       print("total={}".format(total))
        check = ( total < result )
        if check:
#           print("値は{}に".format(total))
            result = total
    return result


if __name__ == "__main__":
    a_price, b_price, ab_price, x_sheet , y_sheet = MI()
    print("{}".format(solver(a_price, b_price,
                             ab_price, x_sheet, y_sheet)))


Measured memory_bytes: 9972
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=200000000000000;
double pi=3.141592653589793;

const int MOD = 1000000007;

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

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}
long myPow(long long x, long long n, long long m=MOD){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

ll N;
vector<double>p(3002);
vector<vector<double>>memo(3002,vector<double>(3002,-1));
double f(double i,double j){
	if(memo[i][j]!=-1)return memo[i][j];
	if(i==0){
		if(j==0)return 1;
		else return 0;
	}
	return memo[i][j]=(1-p[i-1])*f(i-1,j)+p[i-1]*f(i-1,j-1);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll N;
	cin>>N;
	cout<<(N-1)/2<<endl;
}


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

using namespace std;

int main() {
	string name,last;
	
	int n = 0;

	cin >> name;
	n = name.length();
	//末尾の検索
	last = name.substr(n-1);
	

	if (last == "s") {
		name = name + "es";
	}
	else
		name = name + 's';

	cout << name;

}

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

#define PB          push_back
#define PF          push_front
#define MP          make_pair
#define FI          first
#define SE          second
#define SIZE( A )   int( ( A ).size( ) )
#define ALL( A )    ( A ).begin( ), ( A ).end( )
#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )

using namespace std;

typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         lf;
typedef pair< int, int >    pii;
typedef pair< ll, ll >      pll;
typedef vector< bool >      vb;
typedef vector< lf >        vd;
typedef vector< ll >        vll;
typedef vector< int >       vi;
typedef vector< pii >       vpii;

const int MAXN = int( 2e5 );
const int MOD  = int( 360 );
const int oo   = INT_MAX;

int n;
int arr[ MAXN ], cp[ MAXN ];
int tp[ MAXN ];

int main( ) {

  #ifdef LOCAL
    freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
  #else
    //freopen( "attack.in", "r", stdin );
    //freopen( "attack.out", "w", stdout );
    ios_base::sync_with_stdio( 0 );
    cin.tie( 0 );
  #endif

  while( cin >> n ) {
    for( int i = 0; i < n; ++i ) {
      cin >> arr[ i ];
    }
    memcpy( cp, arr, sizeof( int )*n );
    sort( cp, cp+n );
    int ans = 0;
    for( int i = 0; i < n; ++i ) {
      int pos = lower_bound( cp, cp+n, arr[ i ] )-cp;
      if( pos%2 != i%2 ) {
        ++ans;
      }
    }
    cout << ans/2 << '\n';
  }

  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){
  string S; cin >> S;
  ll N = S.length();

  vector <ll> A(26);
  for (int i = 0; i < N; i++){
    int a = S[i] - 'a';
    A[a]++;
  }
  
  ll cnt = 0;
  for (int i = 0; i < 26; i++){
    cnt += A[i] * (A[i] - 1) / 2;
  }
  
  cout << N * (N - 1) / 2 - cnt + 1 << endl;
  
  
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll c[20][20];
ll math[220][220];
ll number[11];
ll dp[20][20];

//long longしか使わない
//素数は1より大きい
int main() {
	ll h, w;
	cin >> h >> w;
	rep(i, 10) {
		rep(j, 10) {
			cin >> c[i][j];
		}
	}
	rep(i, 10) {
		rep(j, 10) {
			rep(k, 10) {
				c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
			}
		}
	}
	ll ans = 0;
	rep(i, h) {
		rep(j, w) {
			cin >> math[i][j];
			if (math[i][j] != 1 && math[i][j] != -1)ans += c[math[i][j]][1];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include<sstream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define  mem memset(a,0,sizeof(a))

const int mo=1000000007;
const int inf=0x3f3f3f3f;

typedef long long ll;
using namespace std;

int main()
{
    char a[2][100];
    int n,i,j;
    cin>>n;
    cin>>a[0];
    cin>>a[1];
    int x=-1;
    ll sum=1;
    for(i=0;i<n;i++)
    {
        if(a[0][i]==a[0][i+1])
        {
            if(x==-1)
            {
                sum=sum*3*2;
                sum=sum%mo;
            }
            else if(x==1)
            {
                sum=sum*2;
                sum=sum%mo;
            }
            else if(x==0)
            {
                sum=sum*3;
                sum=sum%mo;
            }
            x=0;
        }
        else if(a[0][i]==a[1][i])
        {
            if(x==-1)
            {
                sum=sum*3;
                sum=sum%mo;
            }
            else if(x==1)
            {
                sum=sum*2;
                sum=sum%mo;
            }
            else if(x==0)
            {
                sum=sum*1;
                sum=sum%mo;
            }
            x=1;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;
typedef long long int lint;

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

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

Measured memory_bytes: 1152
A=int(input())
B=int(input())
C=int(input())
X=int(input())
c=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500*i+100*j+50*k==X:
                c+=1
                
print(c)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
template<class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P){
    in >> P.first >> P.second;
    return in;
}
template<class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P){
    out << "(" << P.first << ", " << P.second << ")";
    return out;
}
template<class T>
istream &operator>>(istream &in, vector<T> &arr){
    for(auto &x: arr) in >> x;
    return in;
}
template<class T>
ostream &operator<<(ostream &out, const vector<T> &arr){
    for(auto &x: arr) out << x << ' '; cout << "\n";
    return out;
}
template<class T>
istream &operator>>(istream &in, deque<T> &arr){
    for(auto &x: arr) in >> x;
    return in;
}
template<class T>
ostream &operator<<(ostream &out, const deque<T> &arr){
    for(auto &x: arr) out << x << ' '; cout << "\n";
    return out;
}
const ll mod = 1000000007;

ll modpow(ll b, ll e) {
	ll ans = 1;
	for (; e; b = b * b % mod, e /= 2)
		if (e & 1) ans = ans * b % mod;
	return ans;
}
ll n , k;
ll fat[200006] , ifat[200006] , a[200005];
map<ll, ll> cnt;
int32_t main(){
fat[0] = 1;
	rep(i,1,200005) fat[i] = (i*fat[i-1])%mod;
	ifat[200004] = modpow(fat[200004] , mod - 2);
	for(int j = 200003 ; j >= 0 ; j --){
		ifat[j] = ((j+1)*ifat[j+1])%mod;
	}
	cin>>n>>k;
	rep(i,1,n+1){
		cin>> a[i];
	}
	sort(a+1, a+1+n);
	ll ans = 0 ;
	rep(i,1,n+1){
		if((i-1) >= (k-1)){
			ll u = (fat[i-1] * ifat[k-1])%mod;
			u = (u * ifat[(i-1) - (k-1)]) %mod;
			ans = (ans + a[i] *u)%mod;
		}
		// cout << ans << endl;
	}
	rep(i,1,n+1){
		a[i] = -a[i];
	}
	sort(a+1 ,a+1+n);
	rep(i,1,n+1){
		if((i-1) >= (k-1)){
			ll u = (fat[i-1] * ifat[k-1])%mod;
			u = (u * ifat[(i-1) - (k-1)]) %mod;
			ans = (ans + a[i] *u)%mod;
		}
	}
	if(ans < 0) ans += mod;
	cout << ans << endl;
}

Measured memory_bytes: 4096
import fractions
n = int(input())
a = list(map(int, input().split()))
l = a[0]
for i in range(1, n): l = l // fractions.gcd(l, a[i]) * a[i]
s = 0
for i in range(n): s += l // a[i]
print(s % 1000000007)

Measured memory_bytes: 6072
#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>

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 = 1e9 + 7;
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

int a, b, c;

int main() {
	cin >> a >> b >> c;
	if (b - a == c - b)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back;
#define endl "\n";
#define X first;
#define Y second;
#define pii pair<int,int>;
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
int main(){
	migmig;
	int a,b;
	cin >> a >>b;
	cout<<max(a+a-1,max(b+b-1,a+b));
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
//int m,n;
//int i,j,k,l;
//int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
//char a[101],b[101],s[101],t[101],u[101];
char a[6];
int main(void){
    scanf("%s",a);
    if (strcmp("ABC", a) == 0) {
        printf("ARC\n");
    } else if (strcmp("ARC", a) == 0) {
        printf("ABC\n");
    }
    
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;++i) {
    cin >> A[i];
  }
  int count = 0;
  int min = 1000000;
  for(int j=0;j<N;++j) {
    if(min > A[j]) {
      ++count;
      min = A[j];
    }
  }
  cout << count;
}

Measured memory_bytes: 1024
use std::io;

fn main() {
  let mut line = String::new();
  io::stdin().read_line(&mut line)
    .expect("failed to read line");
  let ss: Vec<i32> = line.trim().split_whitespace()
    .map(|e| e.parse().unwrap()).collect();

  if ss[0] > ss[1] {
    println!("a > b")
  } else if ss[0] < ss[1] {
    println!("a < b")
  } else {
    println!("a == b")
  }
}



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

using namespace std;

int main()
{
    int s,a,b;
    cin>>s;

    a=s/100;
    b=s%100;

    if((a!=0 && a<=12) && (b!=0 && b<=12)) cout << "AMBIGUOUS\n";
    else if(a!=0 && a<=12) cout << "MMYY\n";
    else if(b!=0 && b<=12) cout << "YYMM\n";
    else cout << "NA\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ulli;
typedef long long int lli;
int main()
{
   
   int a,b,c,d;

   cin>>a>>b>>c>>d;
   if(abs(c-a)<=d)
     cout<<"Yes\n";
   else if(abs(b-a)<=d&&abs(c-b)<=d)
    cout<<"Yes\n";
    else
        cout<<"No";

    return 0;
}  

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc164/tasks/abc164_e
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;

using pll = pair<long long, long long>;
using Edge = pair<int, pll>;
using Graph = vector<vector<Edge>>;

// C : money , D : time
vector<long long> C, D;
Graph G;
static const long long INF = numeric_limits<long long>::max();
static const int nmax = 50;
static const int smax = 2500;

// dp[v][s] : インデックスvの頂点にいて、所持金sという状態になるために必要な最小の所要時間 
vector<vector<long long>> dp;
// 頂点数, 辺の数, 所持金
int N, M;
long long S;

void Dijkstra()
{
    // <要素の型 : pair<T1, T2>, 内部コンテナ: std::vector<T>, 昇順>
    priority_queue<pair<long long, pll>, vector<pair<long long, pll>>, greater<pair<long long, pll>>> que;
    dp.assign(nmax, vector<long long>(smax+1, INF));
    // 頂点 0 からスタートするので、dp[0][S] を初期化
    dp[0][S] = 0;
    que.push(make_pair(0, pll(0, S)));
    while(!que.empty())
    {
        auto parent = que.top();
        que.pop();
        long long time = parent.first;
        int v = parent.second.first;
        long long s = parent.second.second;
        
        if (time > dp[v][s]) continue;

        if (s + C[v] <= smax)
        {
            long long ns = s + C[v];
            long long ntime = time + D[v];
            if (ntime < dp[v][ns])
            {
                dp[v][ns] = ntime;
                que.push(make_pair(ntime, pll(v, ns)));
            }
        }

        for (auto e : G[v])
        {
            if (s < e.second.first) continue;
            int nv = e.first;
            long long ns = s - e.second.first;
            long long ntime = time + e.second.second;
            if (ntime < dp[nv][ns])
            {
                dp[nv][ns] = ntime;
                que.push(make_pair(ntime, pll(nv, ns)));
            }
        }
    }
}

int main()
{
    cin >> N >> M >> S;
    if (S >= smax) S = smax; // 頂点は高々50個, 各頂点で支払うコストは高々50 なので、Sは2500で十分

    G.assign(N, vector<Edge>());
    for (int i = 0; i < M; ++i)
    {
        int u, v;
        long long a, b;
        cin >> u >> v >> a >> b;
        --u, --v;
        G[u].push_back(Edge(v, pll(a, b)));
        G[v].push_back(Edge(u, pll(a, b)));
    }
    C.reserve(N), D.reserve(N);
    for (int i = 0; i < N; ++i)
    {
        long long c, d;
        cin >> c >> d;
        C[i] = c, D[i] = d;
    }
    Dijkstra();
    for (int v = 1; v < N; ++v)
    {
        long long ans = numeric_limits<long long>::max();
        for (int s = 0; s <= smax; ++s) ans = (std::min)(ans, dp[v][s]);
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 7364