akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define x first
#define y second
#define y1 Y1
#define y2 Y2
#define mp make_pair
#define pb push_back

using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

template <typename T> inline int Chkmax (int &a, int b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline int Chkmin (int &a, int b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline T read ()
{
	T sum = 0, fl = 1; char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
	return sum * fl;
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string(istreambuf_iterator <char> (t), istreambuf_iterator <char> ())<< endl;
}

const int Maxn = 50 + 10, Mod = 1e9 + 7;

int N, A[Maxn][Maxn];
LL K;

inline void Add (int &a, int b) { a += b; if (a >= Mod) a -= Mod; }

struct Matrix
{
	int A[Maxn][Maxn];

	inline void init ()
	{
		memset(A, 0, sizeof A);
		for (int i = 1; i <= N; ++i) A[i][i] = 1;
	}

	inline Matrix operator * (const Matrix &rhs) const
	{
		Matrix c;
		for (int i = 1; i <= N; ++i)
			for (int j = 1; j <= N; ++j)
			{
				c.A[i][j] = 0;
				for (int k = 1; k <= N; ++k)
					Add (c.A[i][j], 1ll * A[i][k] * rhs.A[k][j] % Mod);
			}
		return c;
	}
};

Matrix ans, sum;

inline void Solve ()
{
	ans.init();
	for (LL i = K; i; i >>= 1, sum = sum * sum) if (i & 1) ans = ans * sum;

	int Ans = 0;
	for (int i = 1; i <= N; ++i)
		for (int j = 1; j <= N; ++j)
			Add (Ans, ans.A[i][j]);

	cout<<Ans<<endl;
}

inline void Input ()
{
	N = read<int>(), K = read<LL>();
	for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) sum.A[i][j] = read<int>();
}

int main()
{
#ifdef hk_cnyali
	freopen("R.in", "r", stdin);
	freopen("R.out", "w", stdout);
#endif
	Input();
	Solve();
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;



int main(int argc, char *argv[])
{
	int n;

	//input
	cin >> n;



	//calc
	int ans = 0;
	int prev2, prev1;
	cin >> prev2 >> prev1;
	for (int i = 2; i < n; i++){
		int current;
		cin >> current;

		vector<int> range;
		range.push_back(prev2);
		range.push_back(prev1);
		range.push_back(current);
		sort(range.begin(), range.end());

		if (range[1] == prev1){
			ans++;
		}

		prev2 = prev1;
		prev1 = current;
	}




	//ans
	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int x,k,d;
	cin >> x>>k>>d;
	if(x<0)x=-1*x;
	long long int a = x/d;
	if(-1*a<k && a<k  ){
	k = k-a;

	x = x - a*d;
	}
	else{
		if(x<=0)cout << x+k*d <<endl; 
		else cout << x-k*d<< endl;
		return 0;
	}
	if(k%2==0)cout << x<<endl;
	else cout << abs(x-d)<<endl;
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n);
    vector<ll> y;
    REP(i,n) cin >> x[i];
    REP(i,n-1) y.push_back(x[i+1]-x[i]);
    ll ans = 0ll;
    sort(y.begin(), y.end());
    REP(i,y.size()) ans += min((a*y[i]), b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

vector<int> topological(vector<vector<int>> g){
    const int v = (int)g.size();
    vector<int> indeg(v,0);
    stack<int> s;
    for(auto u:g){
        for(auto x:u){
            indeg[x]++;
        }
    }
    rep(i,v){
        if(indeg[i]==0) s.push(i);
    }
    vector<int> ret;
    while(!s.empty()){
        int u=s.top(); s.pop();
        ret.emplace_back(u);
        for(auto x:g[u]){
            indeg[x]--;
            if(indeg[x]==0) s.push(x);
        }
    }
    return ret;
}

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<vector<int>> v(n);
    vector<vector<int>> from(n);
    vector<long double> in(n,0.0),out(n,0.0);
    vector<int> s(m),t(m);
    vector<bool> ok(m,1);
    rep(i,m){
        cin >> s[i] >> t[i];
        s[i]--; t[i]--;
        v[s[i]].pb(t[i]);
        from[t[i]].pb(s[i]);
        in[t[i]]+=1.0; out[s[i]]+=1.0;
    }
    long double ans=1001001.0;
    vector<long double> num(n,0.0);
    rrep(i,n){
        for(auto u:v[i]){
            num[i]+=(num[u]+1.0)/out[i];
        }
    }
    //fout(num[0]);
    chmin(ans,num[0]);
    rep(i,n){
        vector<long double> dp(n,0.0);
        long double res=0.0;
        int idx=-1;
        for(auto u:v[i]){
            if(res<num[u]){
                res=num[u]; idx=u;
            }
        }
        if(idx==-1) continue;
        out[i]-=1.0;
        rrep(j,n){
            for(auto u:v[j]){
                if(j==i&&u==idx) continue;
                dp[j]+=(dp[u]+1.0)/out[j];
            }
        }
        out[i]+=1.0;
        bool ok=1;
        rep(j,n-1){
            if(dp[j]==0.0) ok=0;
        }
        if(ok) chmin(ans,dp[0]);
    }
    fout(ans);
}




Measured memory_bytes: 7164
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    if(s.equals("5 5 7") || s.equals("5 7 5") || s.equals("7 5 5")) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
    
  }
}

Measured memory_bytes: 35652
#include <stdio.h>
int main(){
     int a,b;
     scanf("%d %d",&a,&b);
     int c[50]={0};
     for(int i=0;i<b;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        c[x-1]++;
        c[y-1]++;
     }
     for(int i=0;i<a;i++){
        printf("%d\n",c[i]);
     }
    return 0;
}


Measured memory_bytes: 128
N, K = map(int,input().split())
A = [int(i) for i in input().split()]
cnt = 0
B = A*2
cnt1 = 0
for i in range(N-1):
  for j in range(i+1,N):
    if A[i] > A[j]:
      cnt += 1
for i in range(N):
  for j in range(N, 2*N):
    if B[i] > B[j]:
      cnt1 += 1
print((cnt*K+cnt1*K*(K-1)//2)%(10**9+7))

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

using namespace std;

using ll = long long;
using ld = long double;

const ll INF = 1e15;

ld calc(ll vmax, ll vmin, ll vmax_r, ll vmin_r, ll vmax_l, ll vmin_l, ld t) {
    return max({(ld)vmax, vmax_r + t, vmax_l - t}) - min({(ld)vmin, vmin_r + t, vmin_l - t});
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> x(n), y(n);
    vector<char> d(n);

    ll xmax = -INF, xmin = INF, ymax = -INF, ymin = INF;
    ll ymax_u = -INF, ymin_u = INF, ymax_d = -INF, ymin_d = INF;
    ll xmax_l = -INF, xmin_l = INF, xmax_r = -INF, xmin_r = INF;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> d[i];
        if (d[i] == 'U') {
            xmax = max(xmax, x[i]);
            xmin = min(xmin, x[i]);
            ymax_u = max(ymax_u, y[i]);
            ymin_u = min(ymin_u, y[i]);
        } else if (d[i] == 'D') {
            xmax = max(xmax, x[i]);
            xmin = min(xmin, x[i]);
            ymax_d = max(ymax_d, y[i]);
            ymin_d = min(ymin_d, y[i]);
        } else if (d[i] == 'L') {
            ymax = max(ymax, y[i]);
            ymin = min(ymin, y[i]);
            xmax_l = max(xmax_l, x[i]);
            xmin_l = min(xmin_l, x[i]);
        } else {
            ymax = max(ymax, y[i]);
            ymin = min(ymin, y[i]);
            xmax_r = max(xmax_r, x[i]);
            xmin_r = min(xmin_r, x[i]);
        }
    }

    ld ans = 1e50;
    for (int i = 0; i <= 200000000; i++) {
        ld t = (ld)i / 2;
        ld ansx = calc(xmax, xmin, xmax_r, xmin_r, xmax_l, xmin_l, t);
        ld ansy = calc(ymax, ymin, ymax_u, ymin_u, ymax_d, ymin_d, t);
        ans = min(ans, ansx * ansy);
    }

    cout << fixed << setprecision(15) << ans << endl;
    return 0;
}

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

int partition(int *a, int p, int r){
    int x = a[r];
    int i = p-1;
    for(int j=p;j<r;j++){
        if(a[j] <= x){
            swap(a[++i],a[j]);
        }
    }
    swap(a[++i], a[r]);
    return i;
}

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

    int a[n];
    rep(i, n){
        cin >> a[i];
    }

    int base = partition(a, 0, n-1);

    rep(i, n){
        if(i==base) cout << "[";
        cout << a[i];
        if(i==base) cout << "]";
        i!=n-1 ? cout << " " : cout << "\n";
    }

    return 0;
}


Measured memory_bytes: 3372
#include <stdio.h>
#define MAX 100000

int parent (int);
int left(int);
int right(int);
int main(){
    int H,i,A[MAX+1];
    scanf("%d",&H);
    for(i=1;i<=H;i++){
        scanf("%d",&A[i]);
    }
    for(i=1;i<=H;i++){
        printf("node %d: key = %d, ",i,A[i]);
        if(parent(i)>=1)
            printf("parent key = %d, ",A[parent(i)]);
        if(left(i)<=H)
            printf("left key = %d, ",A[left(i)]);
        if(right(i)<=H)
            printf("right key = %d, ",A[right(i)]);
        printf("\n");
    }
    return 0;
}
int parent (int i){
    return i/2;
}
int left(int i){
    return 2*i;
}
int right(int i){
    return 2*i+1;
}



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

typedef long long int ll;
#define deb(x) cout << #x << " " << x << endl;
#define debtwo(x,y) cout << #x << " " << x << ", " << #y << " " << y << endl;
#define mod 100000007

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

    ll d, t, s;

    cin >> d >> t >> s;

    if (d <= t * s) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 3648
import java.util.*;
import java.math.*;
public class Main{

	static int INF = 2 << 27;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int c[] = new int[n];
		int r[] = new int[n];
		int a[] = new int[k];
		int b[] = new int[k];
		for(int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
			r[i] = sc.nextInt();
		}
		for(int i = 0; i < k; i++) {
			a[i] = sc.nextInt()-1;
			b[i] = sc.nextInt()-1;
		}
		int[][] dis = new int[n][n];
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(i == j) continue;
				dis[i][j] = INF;
			}
		}
		Node[] node = new Node[n];
		for(int i = 0; i < n; i++) {
			node[i] = new Node();
			node[i].cost = INF;
		}
		for(int i = 0; i < k; i++) {
			node[a[i]].edge_to.add(b[i]);
			node[b[i]].edge_to.add(a[i]);
		}
		for(int i = 0; i < n; i++) {
			ArrayDeque<Data> queue = new ArrayDeque<Data>();
			queue.add(new Data(i,0));
			while(!queue.isEmpty()) {
				Data tmp = queue.poll();
				if(tmp.cost > r[i]) break;
				ArrayList<Integer> edge_to = node[tmp.now].edge_to;
				for(int j = 0; j < edge_to.size(); j++) {
					int T = edge_to.get(j);
					int M = tmp.cost+1;
					if(dis[i][T] <= M) continue;
					dis[i][T] = M;
					queue.add(new Data(T,M));
				}
 			}
		}
		PriorityQueue<Data> queue = new PriorityQueue<Data>();
		queue.add(new Data(0,0));
		while(!queue.isEmpty()) {
			Data tmp = queue.poll();
			if(node[tmp.now].cost <= tmp.cost) continue;
			node[tmp.now].cost = tmp.cost;
			node[tmp.now].check = true;
			if(tmp.now == n-1) break;
			for(int i = 0; i < n; i++) {
				if(node[i].check) continue;
				if(dis[tmp.now][i] > r[tmp.now]) continue;
				if(node[i].cost <= tmp.cost + c[tmp.now]) continue;
				queue.add(new Data(i,tmp.cost + c[tmp.now]));
			}
		}
		System.out.println(node[n-1].cost);	
	}
	static class Data implements Comparable<Data>{
		int now;
		int cost;
		Data(int a, int b) {
			now  = a;
			cost = b;
		}
		@Override
		public int compareTo(Data o) {
			return this.cost - o.cost;
		}
	}
	static class Node {
		int cost;
		boolean check;
		ArrayList<Integer> edge_to = new ArrayList<Integer>();
	}
}

Measured memory_bytes: 488712
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]
x, y = list(map(int, input().split()))
if(x in a and y in a or x in b and y in b or x in c and y in c):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
using namespace std;
#define int long long int
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k;
	cin>>n>>k;
	int j,arr[n];
	for(j=0;j<n;j++)
	  cin>>arr[j];
	sort(arr,arr+n);
	int sum=0;
	for(j=0;j<k;j++)
	  sum+=arr[j];
	cout<<sum<<endl;
}


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

using namespace std;

int main()
{
  string s;
  cin>>s;
  int n = s.length();
  int i;
  for( i = 0 ; i < n ; i++)
  {
    if(s[i] == 'L' && i%2 == 0)
    {
      cout<<"No";
      return 0;
    }
    if(s[i] == 'R' && i%2 == 1)
    {
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
#include<vector>

using namespace std;
typedef long long ll;

ll ans,mx,sum,mn=1e8;


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

ll lcm(ll a,ll b){  
    return (a*b)/gcd(a, b);  
} 
 
int main(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll oneto = (a/c)+(a/d)-(a/lcm(c,d));
	ll whole = (b/c)+(b/d)-(b/lcm(c,d));
	
	ans =(b-whole)-(a-oneto);
	if(a%c!=0) ans++;
	cout<<ans;
}


Measured memory_bytes: 256
s, t = [], []
n = int(input())
for i in range(n):
    s.append(input())
m = int(input())
for i in range(m):
    t.append(input())
st = set(s + t)
ans = 0
for i in st:
    ans = max(s.count(i) - t.count(i), ans)
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<pair<int,int>>>;
#define MOD 1000000007
#define INF 1000000000

int main(){
  int N;
  ll D;
  cin>>N>>D;
  vector<ll> x(N),y(N);
  for(int i=0;i<N;i++){
    cin>>x[i]>>y[i];
  }

  int ans=0;
  for(int i=0;i<N;i++){
    if(x[i]*x[i]+y[i]*y[i]<=D*D){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 6428
#include <iostream>
#include <string>
int main(){
std::string a , b;
std::cin >> a >> b ;
//pot top
//a[3]  a[0]=p
if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0]){
std::cout << "YES" <<std::endl;
}
else{std::cout << "NO" << std::endl;}
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

struct semanticInfo{
    ll val;
    ll treeIdx;
    
    semanticInfo(){
        val = 0;
        treeIdx = 0;
    }

    semanticInfo(ll initV,ll initI){
        val = initV;
        treeIdx = initI;
    }
};

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

semanticInfo semantic(const vector<string> &statement,int idx,int depth){
    if('0' <= statement[idx][depth] && statement[idx][depth] <= '9'){
        return semanticInfo(statement[idx][depth] - '0',idx);
    }
    semanticInfo ret;
    bool times = false;
    if(statement[idx][depth] == '*'){
        ret = semanticInfo(1,idx);
        times = true;
    }else{
        ret = semanticInfo(0,idx);
    }
    while(ret.treeIdx + 1 < statement.size()){
        ll nextdepth = 0;
        while(statement[ret.treeIdx+1][nextdepth] == '.'){
            nextdepth++;
        }
        if(depth >= nextdepth){
            return ret;
        }else{
            auto tmp = semantic(statement,ret.treeIdx+1,depth+1);
            if(times){
                ret.val *= tmp.val;
            }else{
                ret.val += tmp.val;
            }
            ret.treeIdx = tmp.treeIdx;
        }
    }
    return ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    vector<ll> ans;

    while(true){
        ll n;
        cin >> n;
        if(n == 0){
            break;
        }
        vector<string> state;
        for(int i = 0; i < n; i++){
            string str;
            cin >> str;
            state.push_back(str);
        }
        ans.push_back(semantic(state,0,0).val);
    }

    for(auto x: ans){
        cout << x << endl;
    }

    return 0;
}


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

using namespace std;

int main(void) {
  
 int N;
 cin >> N;
 int ac = 0;
   int wa = 0;
   int tle = 0;
   int re = 0;
 for (int i = 0; i< N; i++) {
   string S;
   cin >> S;
   
   if (S == "AC") {
     ac++;
   } else if (S == "WA") {
     wa++;
   } else if (S == "TLE") {
     tle++;
   } else if (S == "RE") {
     re++;
   }
 }
 cout << "AC x " << ac << endl;
 cout << "WA x " << wa << endl;
 cout << "TLE x " << tle << endl;
 cout << "RE x " << re << endl;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace mondai0033
{
	class Program
	{
		static void Main(string[] args)
		{
			var	n	= int.Parse( Console.ReadLine() );
			for( int nn = 0; nn < n; nn++ ) {
				var	ball	= Array.ConvertAll( Console.ReadLine().Split(), b => int.Parse( b ) );
				int	pipe_a	= 0;
				int	pipe_b	= 0;
				int i;
				for( i = 0; i < ball.Length; i++ ) {
					if( (ball[ i ] < pipe_a) && (ball[ i ] < pipe_b) ) {
						break;
					} else if( (ball[ i ] > pipe_a) && (ball[ i ] > pipe_b) ) {
						int	a_d	= ball[ i ] - pipe_a;
						int	b_d	= ball[ i ] - pipe_b;
						if( a_d < b_d ) {
							pipe_a	= ball[ i ];
						} else {
							pipe_b	= ball[ i ];
						}
					} else if( ball[ i ] > pipe_a ) {
						pipe_a	= ball[ i ];
					} else {
						pipe_b	= ball[ i ];
					}
				}
				if( i >= ball.Length ) {
					Console.WriteLine( "YES" );
				} else {
					Console.WriteLine( "NO" );
				}
			}
		}
	}
}

Measured memory_bytes: 5292
/*|In The Name Of Allah|*/
//This Month Will Be Expert ISA
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+7;

const int mod = 1e9+7;

long long inv[N];
long long fac[N];
long long finv[N];

void cominit(){
    fac[0] = fac[1] =1;
    finv[0] = finv[1] =1;
    inv[1] = 1;
    for(int i = 2; i < N; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i]= mod - inv[mod%i] * (mod / i) %mod;
        finv[i]= finv[i-1] * inv[i] % mod;
    }
}

long long nCr(long long n , long long r){
    if(n < r)
        return 0;
    if(n < 0 || r < 0)
        return 0;
    return fac[n] * (finv[r] * finv[n-r] % mod) %mod;
}

int n;
int k;
int ar[N];

void add_self(int & sum , long long add){
    sum += add;
    sum %= mod;
}

int main(){
    cominit();
    scanf("%d%d" , &n , &k);
    for(int i = 1; i <= n; i++){
        scanf("%d" , &ar[i]);
    }
    int ans = 0;
    sort(ar + 1 , ar + n + 1);
    //select the minimum number
    for(int i = 1; i <= n; i++){
        if(n - i < k - 1)
            break;
        long long nve = ((1ll * -ar[i] * nCr(n - i , k - 1) % mod) + mod) % mod;
        add_self(ans , nve);
    }
    //select the maximum number
    for(int i = n; i >= 1; i--){
        int r = n - i + 1;
        if(n - r < k - 1)
            break;
        long long pos = ((1ll * ar[i] * nCr(n - r , k - 1) % mod) + mod) % mod;
        add_self(ans , pos);
    }
    printf("%d\n" , ans);
}

Measured memory_bytes: 5376
#include <iostream>
#include <cstring>
using namespace std;
int n, i;
char s[1001];
int main()
{
    cin.getline (s, 1001);
    n=strlen(s);
    for(i=0; i<n; i++)
        cout<<s[i];
    if(s[i-1]=='s') cout<<"es";
    else cout<<'s';
    return 0;
}


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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
const ll P =  1000000007;
ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= P;
   }
   return ans;
}
using Graph = vector<vector<int>>;

ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}

int main(){
  string S;
  cin >> S;
  int k = S.size();
  rep(i,k){
    cout << "x";
  }
  cout << endl;
 }


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int paper[14][14] = {}, x, y, size, c = 0, max = 0, i, j;
  while(scanf("%d,%d,%d", &x, &y, &size) != EOF){
    x += 2;
    y += 2;
    switch(size){
    case 3:
      paper[y - 2][x]++;
      paper[y][x - 2]++;
      paper[y][x + 2]++;
      paper[y + 2][x]++;
    case 2:
      paper[y - 1][x - 1]++;
      paper[y + 1][x - 1]++;
      paper[y - 1][x + 1]++;
      paper[y + 1][x + 1]++;
    case 1:
      paper[y - 1][x]++;
      paper[y + 1][x]++;
      paper[y][x - 1]++;
      paper[y][x + 1]++;
      paper[y][x]++;
      break;
    }
  }

  for(i = 2;i < 12;i++){
    for(j = 2;j < 12;j++){
      if(paper[i][j] != 0) c++;
      if(paper[i][j] > max) max = paper[i][j];
    }
  }

  printf("%d\n%d\n",100 - c, max);
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

char a[1003][1004];
int dis[1004][1004];
int x,y;
int n,m;
int fx,fy;



int32_t main(){
	fastio();
	cin >> n >> m;
	cin >> x >> y;
	cin >> fx >> fy;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cin >> a[i][j];
			dis[i][j] = mod;
		}
	}
	dis[x][y] = 0;
	set<array<int,3>>s;
	s.insert({dis[x][y],x,y});
	while(!s.empty()){
		array<int,3>p = *s.begin();
		s.erase(p);
		for(int i = 0; i < 4; i++){
			int xx = p[1] + dx[i];
			int yy = p[2] + dy[i];
			if(xx >= 1 and xx <= n and yy >= 1 and yy <= m  and a[xx][yy] == '.'){
				if(dis[xx][yy] > p[0]){
					s.erase({dis[xx][yy],xx,yy});
					dis[xx][yy] = p[0];
					s.insert({dis[xx][yy],xx,yy});
				}
			}
		}
		for(int i = p[1] - 2; i <= p[1] + 2; i++ ){
			for(int j = p[2] - 2; j <= p[2] + 2; j++){
				if(i >= 1 and i <= n and j >= 1 and j <= m and a[i][j] == '.'){
					if(dis[i][j] > p[0] + 1){
						s.erase({dis[i][j],i,j});
						dis[i][j] = 1 + p[0];
						s.insert({dis[i][j],i,j});
					}
				}
			}
		} 
	}
	if(dis[fx][fy] == mod) cout << "-1";
	else cout << dis[fx][fy];
}

Measured memory_bytes: 12484
from collections import deque

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

ans=float("inf")
count=0
def dfs(num,ro,re,bo,be):
    global ans,count
    count+=1
    if num==N:
        que=[]
        ro.sort(reverse=True)
        re.sort(reverse=True)
        bo.sort(reverse=True)
        be.sort(reverse=True)
        ropos=-1
        repos=-1
        bopos=-1
        bepos=-1
        for i in range(N):
            if i%2==0:
                if repos>=-len(re) and bopos>=-len(bo):
                    val1,num1=re[repos]
                    val2,num2=bo[bopos]
                    if val1>val2:
                        que.append([val2,num2])
                        bopos-=1
                    elif val2>val1:
                        que.append([val1,num1])
                        repos-=1
                    elif num1>num2:
                        que.append([val2,num2])
                        bopos-=1
                    else:
                        que.append([val1,num1])
                        repos-=1
                elif repos>=-len(re):
                    val,num=re[repos]
                    que.append([val,num])
                    repos-=1
                elif bopos>=-len(bo):
                    val,num=bo[bopos]
                    que.append([val,num])
                    bopos-=1
                else:
                    return 0
            else:
                if ropos>=-len(ro) and bepos>=-len(be):
                    val1,num1=ro[ropos]
                    val2,num2=be[bepos]
                    if val1>val2:
                        que.append([val2,num2])
                        bepos-=1
                    elif val2>val1:
                        que.append([val1,num1])
                        ropos-=1
                    elif num1>num2:
                        que.append([val2,num2])
                        bepos-=1
                    else:
                        que.append([val1,num1])
                        ropos-=1
                elif ropos>=-len(ro):
                    val,num=ro[ropos]
                    que.append([val,num])
                    ropos-=1
                elif bepos>=-len(be):
                    val,num=be[bepos]
                    que.append([val,num])
                    bepos-=1
                else:
                    return 0


        for i in range(1,N):
            if que[i][0]<que[i-1][0]:
                return 0

        temp=0
        for i in range(1,N):
            for j in range(0,i):
                if que[i][1]<que[j][1]:
                    temp+=1
        ans=min(ans,temp)
        return 0

    if num%2==0:
        dfs(num+1,ro,re+[[A[num],num]],bo,be)
        dfs(num+1,ro,re,bo,be+[[B[num],num]])
    else:
        dfs(num+1,ro+[[A[num],num]],re,bo,be)
        dfs(num+1,ro,re,bo+[[B[num],num]],be)

dfs(0,[],[],[],[])
print(ans if ans!=float("inf") else -1)

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

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i = 0; i < N; ++i){
    cin >> A[i];
  }
  int m = 2+N%2;
  const long long INF = 1e18;
  vector<long long> dp(m,-INF);
  dp[0] = 0;
  for(int i = 0; i < N; ++i){
    vector<long long> dp_(m,-INF);
    for(int j = 0; j < m; ++j){
      if(dp[j] == -INF) continue;
      dp_[j] = max(dp_[j],dp[j]+((i+j)%2 ? 0 : A[i]));
      if(j+1 < m)
        dp_[j+1] = max(dp_[j+1],dp[j]);
    }
    swap(dp,dp_);
  }
  cout << dp.back() << endl;
}


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

  #define ll long long
  #define int long long
  #define f(i,l,n) for(ll i=l;i<n;i++)
  #define E "\n"
  #define bp __builtin_popcount
  const int M = 1e9+7;

  
  int32_t main()
  {



   
    int n;
    cin >> n;
    vector<int> a(n+1,0);
    int sum=0;
    f(i,0,n) cin >> a[i],sum=(sum+a[i])%M;

    int ans=0;

    f(i,0,n-1)
    {
      sum=(sum-a[i]+M)%M;
      ans=(ans+(a[i]*sum)%M)%M;
    }
    cout<<ans;

    return 0;
  }

Measured memory_bytes: 4780
stir=input()
lst=stir.split(" ")
l=int(lst[0])
r=int(lst[1])
t=lst[2]
b=1
x=0
multiples=[]
while(b<101):
    multiples.append(int(t)*b)
    b+=1
for a in range(l, r+1):
    for m in multiples:
        if(m==a):
            x+=1
print(x)

Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
 
int main(){ 
    string s;
    cin>>s;
    int a=0,b=0,c=0;

    for(int i=0;i<3;i++){
        if(s[i]=='a')a++;
        else if(s[i]=='b')b++;
        else c++;
    }

    if(a==1&&b==1&&c==1)cout<<"Yes";
    else cout<<"No";

 
    return 0;
}

Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=STR()
    t=STR()
    flg=0
    for i in s:
        s=s[1:]+s[0]
        if s==t:
            flg=1
    if flg==1:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
import math
N = int(input())
checkn = N
if(N == 0):
  print("No")
  exit()

length = len(str(N))
sum = 0
for i in reversed(range(0, length)):
  num = math.floor(N/10**i)
  sum += num
  N -= num * (10**i)
  
if(checkn % sum == 0):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
// abc092_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int n,d,x,a,cnt,ans=0;
  cin>>n>>d>>x;
  rep(i,n){
    cin>>a;
    cnt=0;
    while(cnt*a+1<=d){
      cnt++;
    }
    ans+=cnt;
  }
  cout<<ans+x<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#include "bits/stdc++.h"

namespace adaptor = boost::adaptors;

const int64_t len = 100005;

struct Process {
    char name[100];
    int64_t time;
};

Process Q[len];
int64_t head, tail, n;

void enqueue(Process x) {
    Q[tail] = x;
    tail = (tail + 1) % len;
}

Process dequeue() {
    Process x = Q[head];
    head = (head + 1) % len;
    return x;
}

void solve() {
    int64_t elaps = 0, c, q;
    Process u;
    std::cin >> n >> q;
    for (int64_t i = 1; i <= n; i++) {
        std::cin >> Q[i].name >> Q[i].time;
    }
    head = 1;
    tail = n + 1;

    while (head != tail) {
        u = dequeue();
        c = std::min(q, u.time);
        u.time -= c;
        elaps += c;
        if (u.time > 0) {
            enqueue(u);
        } else {
            std::cout << u.name << " " << elaps << std::endl;
        }
    }

    return;
}

int main() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}



Measured memory_bytes: 14036
N,M=(input()).split(" ")
N=(int)(N)
M=(int)(M)
sc={}

for i in range(N):
    sc[i]=-1

check=True

for i in range(M):
    s,c=(input()).split(" ")
    s=(int)(s)
    c=(int)(c)
    if sc[s-1]!=-1 and sc[s-1]!=c:
        check = False
        break
    else:
        sc[s-1]=c

if not(check):
    print(-1)
    exit()

if N!=1:
    

    ans=""
    if sc[0]==-1:
        ans+="1"
    elif sc[0]==0:
        print(-1)
        exit()
    else:
        ans+=str(sc[0])

    for i in range(N-1):
        if sc[i+1]==-1:
            ans+="0"
        else:
            ans+=str(sc[i+1])
    print(ans)
else:
    if sc[0]==-1:
        print(0)
    else:
        print(sc[0])

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

class UnionFind {
public:
  vector<i32> r; // 親なら頂点数*-1, それ以外なら自分の親
  UnionFind(i32 N) : r(N, -1) {}
  i32 root(i32 x) {
    if (r[x] < 0)
      return x;
    else {
      r[x] = root(r[x]);
      return root(r[x]);
    }
  }
  bool unite(i32 x, i32 y) {
    i32 rx = root(x);
    i32 ry = root(y);
    if (rx == ry)
      return false;

    if (r[rx] > r[ry])
      swap(rx, ry);

    r[rx] = r[rx] + r[ry];
    r[ry] = rx;

    return true;
  }
  bool same(i32 x, i32 y) {
    if (root(x) == root(y))
      return true;
    else
      return false;
  }
  i32 size(i32 x) { return -r[root(x)]; }
};

int main() {
  u32 n, m;
  cin >> n >> m;

  UnionFind UF(n);

  unordered_set<u32> p;
  rep(i, n) { p.insert(i); }

  rep(i, m) {
    u32 a, b;
    cin >> a >> b;
    UF.unite(a - 1, b - 1);
  }

  i32 ans = 0;

  rep(i, n) { ans = max({ans, UF.size(i)}); }

  cout << ans;

  return 0;
}


Measured memory_bytes: 12220
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, H, W = MAP()
AB = [LIST() for _ in range(N)]

print(sum(y>=H and x>=W for y, x in AB))


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


priority_queue<double>q;


int main()
{


     ll n,i,j;

     double x,a,b;

     cin>>n;
     while(n--)
     {
         cin>>a;
         q.push(-a);
     }

     while(q.size()>=2)
     {
         a=q.top();
         q.pop();
         b=q.top();
         q.pop();

         a=a*-1.0;
         b=b*-1.0;
         x=(a+b)/2.0;
     //    cout<<a<<" "<<b<<endl;

         //cout<<x<<endl;

         q.push(-x);
     }
     a=q.top();
     a=a*-1.0;

     printf("%0.10lf\n",a);

    return 0;
}


Measured memory_bytes: 256
<?php
list($s) = explode(" ", trim(fgets(STDIN)));
list($t) = explode(" ", trim(fgets(STDIN)));

$len = strlen($s);

for($i=0; $i<$len; $i++){
  if($s[$i] != $t[$i]){
    echo "No";
    exit;
  }
}
echo "Yes";

Measured memory_bytes: 16120
#include<stdio.h>
int main(){
  int a[3],b[3];
  int c[3][3];
  int i,j;
  for(i=0;i<3;i++){
    scanf("%d%d%d",&c[i][0],&c[i][1],&c[i][2]);
  }
  a[0]=0;
  for(i=0;i<3;i++){
    b[i]=c[0][i];
  }
  for(i=1;i<3;i++){
    a[i]=c[i][0]-b[0];
  }
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(c[i][j]!=a[i]+b[j]){
        puts("No");
        return 0;
      }
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 128
int main(void) {
	int a,b,d,r;
	double f;

	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=(double)a/b;
	
	printf("%d %d %lf \n",d,r,f);
  
    return 0;
}


Measured memory_bytes: 2104
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

cntA = Counter(A)
B = []
for a, c in cntA.items():
    if c // 2 == 0:
        continue
    for _ in range(c // 2):
        B.append(a)

B.sort(reverse=True)
ans = B[0] * B[1] if len(B) >= 2 else 0

print(ans)

Measured memory_bytes: 18600
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define x real()
#define y imag()
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> a(n + 1), pos(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		pos[i] = i;
	}
	vector<int> ans;
	while (sz(ans) < n) {
		int found = -1;
		for (int i = n; i >= 1; i--) {
			if (pos[i] == a[i]) {
				found = i;
				break;
			}
		}
		if ( found == -1) {
			cout << "-1\n";
			return 0;
		}
		pos[found] = -1;
		for (int i = found + 1; i <= n; i++) {
			pos[i]--;
		}
		ans.push_back(a[found]);
	}
	reverse(ans.begin(), ans.end());
	for (auto &el : ans) {
		cout << el << "\n";
	}
}



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

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

	int A = N / 100;
	int B = N % 100/10;
	int C = N % 100 % 10;

	if (A == 7 || B == 7 || C == 7) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

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

int main() {
  int in, n, ans = 0;
  cin >> in;
  n = in;
  while (true) {
    if (n <= 0) {
      break;
    }
    ans += n%10;
    n /= 10;
  }
  cout << (in%ans ? "No" : "Yes") << endl;
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        String s=in.next();
        int i=0,j=s.length()-1;
        int count=0;
        while(i<j){
            if(s.charAt(i)=='W' && s.charAt(j)=='R'){
                count++;
                i++;
                j--;
            }
            else{
                if(s.charAt(i)=='R' && s.charAt(j)=='W'){
                    i++;j--;
                }else{

                    if(s.charAt(i)=='W'){
                        j--;
                    }else{
                        i++;
                    }


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


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int K = Integer.parseInt(br.readLine());
		
		long sum = 0;
		for(int i=1; i<K+1; i++) {
			for(int j=1; j<K+1; j++) {
				for(int k=1; k<K+1; k++) {
					sum += gcd(i, gcd(j, k));
				}
			}
		}
		
		System.out.println(sum);
	}
	
	public static int gcd(int a, int b) {
		while(b != 0) {
			int tmp = a % b;
			a = b;
			b = tmp;
		}
		
		return Math.abs(a);
	}

}

Measured memory_bytes: 32560
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(500005)


def solve(N: int, a: "List[int]"):
    counter = 0
    for i in range(1,N+1):
        if ((i % 2 == 1) and (a[i-1] %2 == 1)):
            counter += 1
    
    print(counter)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61864
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<int> A(N);
    int M = 1000000;
    vector<int> cnt(M, 0);
    rep(i, N) {
        cin >> A[i];
        cnt[A[i]]++;
    }
    int ans = 0;
    rep(i, M){
        if(cnt[i] > 2) {
            ans += (cnt[i] - 1) / 2;
            cnt[i] -= ((cnt[i] - 1) / 2) * 2;
        }
    }
    
    int c = 0;
    rep(i, M){
        if(cnt[i] >= 2) c++;
    }
    
    ans += (c + 1) / 2;
    
    output(N - ans * 2);
    
    
    
    return 0;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a[3][3];
	for (int i=0; i<3; i++)
		for (int j=0; j<3; j++)
			cin>>a[i][j];
	int n,b; cin>>n;
	set<int> st;
	for (int i=0; i<n; i++)
		cin>>b, st.insert(b);
	int z=0, w=0;
	for (int i=0; i<3; i++) {
		int x=0, y=0;
		if(st.count(a[i][i]))
			z++;
		if(st.count(a[i][2-i]))
			w++;
		for (int j=0; j<3; j++) {
			if(st.count(a[i][j])) x++;
			if(st.count(a[j][i])) y++;
		}
		if(x==3||y==3) {
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<((z==3||w==3)?"Yes":"No")<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i < sqrt(n); i++) {
        if (n % i == 0 && n / i > i + 1)ans += n/i - 1;
    }
    cout << ans << endl;
}

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

int main() {
  
  int N; cin >> N;
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  
  int max = 0;
  int ans = 0;
  
  for (int i = 0; i < N; i++) {
    if (max < vec.at(i)) {
      max = vec.at(i);
      ans++;
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a, b, c, answer;
    a = Integer.parseInt(sc.next());
    b = Integer.parseInt(sc.next());
    c = Integer.parseInt(sc.next());
    if(a - b >= c) answer = 0;
    else answer = c - (a - b);
    System.out.println(answer);
  }
}


Measured memory_bytes: 22740
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

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

  int D;
  cin>>D;
  
  int C[27];
  int S[366][27];
  int last[366][27];

  for(int d=1;d<=26;d++) cin>>C[d];
  for(int d=1;d<=D;d++){
    for(int i=1;i<=26;i++) cin>>S[d][i];
  }

  for(int d=1;d<=D;d++){
    int mi=1;
    int max=-1e9;
    for(int i=1;i<=26;i++){
      int tmp=S[d][i];
      for(int j=1;j<=26;j++){
        if(j!=i) tmp-=C[j]*(d-last[d-1][j]);
      }
      if(max<tmp){
        max=tmp;
        mi=i;
      }
    }
    for(int i=1;i<=26;i++) last[d][i]=last[d-1][i];
    if(d==1){
      last[1][25]=1;
      cout<<25<<endl;
    }
    else{
      last[d][mi]=d;
      cout<<mi<<endl;
    }
  }

  return 0;
}

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

int main(int argc, char const *argv[]) {
    string S, T;
    cin >> S >> T;
    int num = 0;

    for (int i = 0; i < 3; i++) {
        if (S.at(i) == T.at(i)) {
            num++;
        }
    }
    
    cout << num << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a;
    int s = 0, t = 0;

    for (int i = 0; i < 4; i++) {
        cin >> a;
        s += a;
    }

    for (int i = 0; i < 4; i++) {
        cin >> a;
        t += a;
    }

    cout << (s < t ? t : s) << endl;
}



Measured memory_bytes: 3092
#include "bits/stdc++.h"
using namespace std;

int main() {
	string N;
	cin >> N;
	int K;
	cin >> K;
	vector<vector<int>> DP0(K + 1, vector<int>(N.size())); 
	vector<vector<int>> DP1(K + 1, vector<int>(N.size()));
	DP0[0][0] = 1; 
	DP0[1][0] = (N[0] - '0') -1;
	DP1[1][0] = 1;
	
	for (int n = 0; n < N.size()-1;++n) {
		//
		for (int m = 0;m <= K;++m) {
			DP0[m][n + 1] += DP0[m][n];
			if (m + 1 <= K) {
				DP0[m + 1][n + 1] += 9 * DP0[m][n];
			}
		}
		//
		for (int m = 0; m <= K; ++m) {
			if (0 == (N[n + 1] - '0')) {
				DP1[m][n + 1] += DP1[m][n];
			}
			else {
				DP0[m][n + 1] += DP1[m][n];
				if (m + 1 <= K) {
					DP0[m + 1][n + 1] += (N[n + 1] - '0' - 1) * DP1[m][n];
					DP1[m + 1][n + 1] += DP1[m][n];
				}
			}
		}
	}
	cout << DP0[K][N.size() - 1] +DP1[K][N.size()-1]<< endl;
	return 0;
}

Measured memory_bytes: 3616