akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static long mod = 1000000007;
	static long INF = Long.MAX_VALUE;

	static long chmin(long a, long b) {
		return Math.min(a, b);
	}

	static long chmax(long a, long b) {
		return Math.max(a, b);
	}

	public static void main(String[] args) {
		// AtCoder_D
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int AWk[] = new int[100001];
		Arrays.fill(AWk, 0);

		for(int i=0; i<N; i++) {
			AWk[sc.nextInt()]++;
		}

		// 初期ansを求めておく
		long ans = 0;
		for(int j=0; j<100001; j++) {
			ans += j*AWk[j];
		}

		int Q = sc.nextInt();

		for(int i=0; i<Q; i++) {
			int B = sc.nextInt();
			int C = sc.nextInt();

			ans += (C-B)*AWk[B];
			System.out.println(ans);

			AWk[C] += AWk[B];
			AWk[B] = 0;
		}

	    // Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}


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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define MOD 1000000007
typedef pair<li, li> PI;

li h[100100];
li dp[100100];

inline li cost(li from, li to) {
	return abs(h[from] - h[to]);
}

int main(void)
{
	li n;
	cin >> n;
	rep(i, n) {
		cin >> h[i];
	}
	dp[0] = 0;
	dp[1] = cost(0, 1);
	for (li i = 2; i < n; ++i) {
		dp[i] = min(dp[i - 2] + cost(i - 2, i), dp[i - 1] + cost(i - 1, i));
	}
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=10;
const ll MOD=10;
ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);}
ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);}
ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;}
ll factor[MAXN];
void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}}
ll C(ll n,ll k){return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;}
void solve()
{
    int N;
    ll nv=0,ne=0;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    nv=N;
    for(int u=2;u<=N;u++){
        int s,t;
        cin>>s>>t;
        if(s>t)swap(s,t);
        nv+=(ll)u*(N-u+1);
        ne+=(ll)s*(N-t+1);
    }
    cout<<nv-ne;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

Measured memory_bytes: 3652
//  RAKSHIT KADAM

 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the Size of arrayss!!!
    
// NUMERIC DEFINITIONS :
    #define INF 1000000000000000005
    #define inf 1000000037
    #define MOD  1000000007
    #define newMOD  998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
#define ld long double
                         #define ll long long
                         #define int long long
//  #define ll int
 #define present(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
    
#define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
 
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}
const int maxn =506003;

void solve()
{
    ll n,m,k;cin>>n>>m>>k;
    ll a[n],b[m];
    ll aa[n+3],bb[m+3];set<pii>s;
    aa[0]=bb[0]=0;
    for(ll i=0;i<n;i++)cin>>a[i];
    for(ll i=0;i<m;i++)cin>>b[i];
    for(ll i=1;i<=n;i++)
    {
        aa[i] = a[i-1]+aa[i-1];
    }
    for(ll i=1;i<=m;i++)
    {
        bb[i] =b[i-1]+bb[i-1];
        
    }
    ll ans =0;ll j=m;
    for(ll i=0;i<=n;i++)
    {
       while((~j) && aa[i]+bb[j]>k)j--;
        if(j<0)break;
        ans = max(ans,i+j);
            
    }
    cout<<ans<<endl;
}
signed main()
{
   Need_for_speed(activated);
    
//satisfy
//    {
//  solve();
//   }
    solve();
    
    return 0;
}


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

int cnt[31];

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

	vector <int> a(n);

	for (int &x : a) {
		cin >> x;

		int xx = x;

		for (int i = 0; xx > 0; ++i) {
			cnt[i] += xx & 1;
			xx >>= 1;
		}
	}

	vector <int> ans(n);

	for (int i = 0; i < 31; ++i) {
		if (cnt[i] & 1) {
			for (int j = 0; j < n; ++j)
				if (!(a[j] >> i & 1))
					ans[j] += 1 << i;
		} else {
			for (int j = 0; j < n; ++j)
				if (a[j] >> i & 1)
					ans[j] += 1 << i;
		}
	}
	
	for (int x : ans)
		cout << x << " ";

	return 0;
}


Measured memory_bytes: 4780
def comb(n):
    return n * (n-1) // 2


def comb2(n):
    if n == 0:
        return 1
    else:
        return (n-1)*(n-2) // 2


N = int(input())
A = [int(i) for i in input().split()]

count = [0] * N
Comb = 0
for a in A:
    count[a-1] += 1
for i,c in enumerate(count):
    Comb += comb(c)

for a in A:
    c = count[a-1]
    ans = Comb - comb(c) + comb2(c)
    print(ans)

Measured memory_bytes: 86476
#include <bits/stdc++.h>
#define endl "\n"
#define int long long
  
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;


signed main() {
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  #endif
  ios_base::sync_with_stdio(false); 
  cin.tie(nullptr); 

  int n;
  cin >> n;
  int a,b,c,d;
  a=b=c=d=0;
  string s;

  for (int i=0; i<n; i++) {
    cin >> s;
    if (s == "AC") a++;
    if (s == "WA") b++;
    if (s == "TLE") c++;
    if (s == "RE") d++;
  }

  cout << "AC x " << a << endl;
  cout << "WA x " << b << endl;
  cout << "TLE x " << c << endl;
  cout << "RE x " << d << endl;
 
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,n;
    int res=0;
    cin >> n >> a >> b;
    
    for (int i = 1; i < n+1; i++){
        int x = i/10000;
        x+=(i%10000)/1000;
        x+=(i%1000)/100;
        x+=(i%100)/10;
        x+=i%10;
        if(x>=a&&x<=b) res+=i;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i, 0, N) { cin >> v[i]; }
    bool j = true;
    rep(i, 0, N) {
        if(v[i] % 2 == 0) {
            if(v[i] % 3 != 0 && v[i] % 5 != 0) {
                j = false;
            }
        }
    }
    if(j) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  cout << (a + b) * h / 2 << endl;


  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inc(l,i,r) for (int i=l;i<=r;i++)
#define dec(r,i,l) for (int i=r;i>=l;i--)
#define SIZE(V) ((int) V.size())
#define forE(p,u) for (edge *p=head[u];p;p=p->nxt)
#define forV(i,V) for (int i=0;i<SIZE(V);i++)
#define pb push_back
#define In inline
#define fi first
#define se second
#define mp make_pair
#define It iterator
#define ___ putchar(10);
#define cnt(x) __builtin_popcount(x)
#define show(x) cout << #x << " = " << x << endl;
#define mid ((l+r) >> 1)
#define N 200100
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

template<typename T>
inline void read(T &x) {
	static char c;
	for (c=getchar();!isdigit(c);c=getchar());
	for (x=0;isdigit(c);c=getchar()) x = (x<<1) + (x<<3) + c - '0';
}

struct edge {int to;  edge *nxt;} *head[N], e[N*2];

int edge_tot = 0;
inline void AE(int u,int v) {
	head[u] = &(e[edge_tot++] = (edge) {v,head[u]});
	head[v] = &(e[edge_tot++] = (edge) {u,head[v]});
}

int n, m, A[N], B[N], fa[N];
pii a[N];
ll sumB[N], dp[N];
vector<int> T[N];

int getfa(int x) {return fa[x] == x ? x : fa[x] = getfa(fa[x]);}
inline void merge(int x,int y) {fa[getfa(x)] = getfa(y);}

void dfs(int u,int from) {
	sumB[u] = B[u];
	dp[u] = A[u];
	forE(p,u) if (p->to != from) {
		dfs(p->to,u);
		sumB[u] += sumB[p->to];
		dp[u] = min(dp[u], max(dp[p->to], A[u] - sumB[p->to]));
	}
}

int main() {
//	freopen("rescue.in","r",stdin);
//	freopen("rescue.out","w",stdout);
	read(n);   read(m);
	inc(1,i,n) read(A[i]), read(B[i]), a[i] = mp(A[i]-B[i],i), A[i] = max(A[i]-B[i], 0);
	while (m--) {
		int u, v;  read(u);  read(v);
		AE(u,v);
	}
	sort(a+1,a+n+1);
	
	inc(1,i,n) {
		fa[a[i].se] = a[i].se;
		forE(p,a[i].se)	if (fa[p->to] && getfa(p->to) != getfa(a[i].se)) {
			T[a[i].se].pb(getfa(p->to));
			merge(p->to, a[i].se);
		}
	}
	edge_tot = 0;
	memset(head,0,sizeof(edge*) * (n+1));
	inc(1,i,n) forV(j,T[i]) AE(i,T[i][j]);
	
	dfs(a[n].se, 0);
	
	printf("%lld\n",dp[a[n].se] + sumB[a[n].se]);
}

Measured memory_bytes: 24704
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	string s;
	cin >> s;
	if (s[0] != s[1] and s[1] != s[2] and s[2] != s[3]) cout << "Good" << endl;
	else cout << "Bad" << endl;
}


Measured memory_bytes: 256
import kotlin.math.*
import java.util.*

fun main(args: Array<String>) {
  val (n, k) = readLine()!!.split(' ').map(String::toInt)
  val snk = (1..n).toMutableSet()
  repeat(k) {
    readLine()
    readLine()!!.split(' ').map(String::toInt).forEach { snk.remove(it) }
  }
  println(snk.size)
}


Measured memory_bytes: 39332
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,m=1000000,k,ans=0;
    scanf("%d%d",&n,&x);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&k);
        ans+=k;
        if(k<m) m=k;
    }
    ans=x-ans;
    int t=ans/m+n;
    printf("%d\n",t);
    return 0;
}


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

void test_case(){

}

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

	vector<int> v(n);
	unordered_set<int> s;
	
	for(int i=0;i<n;i++){
		cin >> v[i];
		s.insert(v[i]);
	}

	if(n==0){
		cout << X << endl;
		return 0;
	}

	int mini = *min_element(v.begin(), v.end());
	int maxi = *max_element(v.begin(), v.end());

	int mindif = 99999999;
	int num;

	if(X < mini || X > maxi){
		cout << X << endl;
		return 0;
	}
 
	for(int i = maxi+1 ; i>=mini-1 ; i--){
		if(s.count(i)>0) continue;
		
		if(abs(i-X) <= mindif){
			mindif = abs(i-X);
			num = i;
		}
	}
	
	cout << num << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>

using namespace std;

int N;
int a[100005], b[100005], c[100005];
int dp[100005][3];

int solve() {
    int pa = 0, pb = 0, pc = 0, na, nb, nc;
    for (int i = 1; i <= N; ++i) {
        na = max(pb, pc) + a[i];
        nb = max(pa, pc) + b[i];
        nc = max(pa, pb) + c[i];
        pa = na, pb = nb, pc = nc;
    }
    return max({pa, pb, pc});
}

int main() {
    cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }
    int res = solve();
    cout << res;
    return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);
    
        int n = scan.nextInt();
        int d = scan.nextInt();
        int x = scan.nextInt();

        int sum = 0;
        for(int i=0; i<n; i++){
            int a = scan.nextInt();
            for(int j=1; j<=d; j+=a){
                sum++;
            }
        }

        System.out.println(sum + x);
        
        
        scan.close();
    
    }

}

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

#define fi first
#define se second

const int N = 303;

using namespace std;

int n;
long double D[N][N][N];

int main()
{
        ios_base::sync_with_stdio(false);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n;
        int A = 0, B = 0, C = 0;
        for(int i = 1; i <= n; i++){
                int x;
                cin >> x;
                A += (x == 1);
                B += (x == 2);
                C += (x == 3);
        }
        for(int c = 0; c <= n; c++){
                for(int b = 0; b <= n; b++){
                        for(int a = 0; a <= n; a++){
                                int d = n - a - b - c;
                                if(d < 0 || a + b + c == 0){
                                        continue;
                                }
                                long double d1 = (long double)a / n;
                                long double d2 = (long double)b / n;
                                long double d3 = (long double)c / n;
                                if(a > 0){
                                        d1 *= D[a - 1][b][c];
                                }
                                if(b > 0){
                                        d2 *= D[a + 1][b - 1][c];
                                }
                                if(c > 0){
                                        d3 *= D[a][b + 1][c - 1];
                                }
                                D[a][b][c] = (1 + d1 + d2 + d3) / (1 - (long double)d / n);
                        }
                }
        }
        cout << fixed << setprecision(9) << D[A][B][C] << "\n";
}


Measured memory_bytes: 432384
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
using LL = long long;
using ULL = unsigned long long;
#define NUM 1000000007

using namespace std;

int main()
{
    vector<char> v(9);
    for (auto& i : v)
    {
        cin >> i;
    }
    cout << v[0] << v[4] << v[8] << endl;
}

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

int N, K;
vector<int> ng(10);

bool dcheck(int n)
{
    while (n > 0)
    {
        if (ng[n % 10]) return false;
        n /= 10;
    }
    return true;
}

int main()
{
    cin >> N >> K;
    int tmp;
    for (int i=0; i<K; i++)
    {
        cin >> tmp;
        ng[tmp] = 1;
    }
    for (int i=N; ; i++)
    {
        if (dcheck(i))
        {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int a,b; cin>>a>>b;
    if(a+b>=10)cout<<"error"<<endl;
    else cout<<a+b<<endl;
}

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

int main(){
  int a,b,x;
  cin >> a >> b >> x;
  if( x >= a && x <= a+b ){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less   
using namespace __gnu_pbds;  
using namespace std;  
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> set1;
int main()
{  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   string s;
   cin>>s;
   ll s1=s.size();
   for(ll i=0;i<s1;i++)
   {
       if(s.at(i)=='?')
       s.at(i)='D';
   }
   cout<<s<<endl;
   return 0;
}
   

Measured memory_bytes: 3748
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n,k;cin>>n>>k;
  vector<ll> A(n);
  rep(i,n){
    cin>>A[i];
  }
  rep(_t,k){
    bool ok = true;
    vector<ll> imos(n+1,0);
    rep(i,n){
      imos[max(0ll, i - A[i])] += 1;
      imos[min(n, i + A[i] + 1)] -= 1;
    }
    rep(i,n){
      imos[i+1] += imos[i];
      A[i] = imos[i];
      if(A[i] != n){
        ok = false;
      }
    }
    if(ok) break;
  }

  rep(i,n){
    cout<<A[i];
    if(i != n){
      cout<<" ";
    }
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 6340
n,a,b = map(int,input().split())
k = min(a,b)-1
p = n - max(a,b)
if abs(a-b)==1:
  print(min(k,p)+1)
else:
  x = (abs(a-b)//2) if abs(a-b)%2==0 else min(k+1+(max(a,b)-k-2)//2,p+1+(n-min(a,b)-p-1)//2 ) 
  print(x)

Measured memory_bytes: 3064
N = int(input())
A = []
for i in range(N):
	l = list(map(int,input().split()))
	A.append([i-1 for i in l])
match_num = [0 for i in range(N)]
match_dict = {}
idx = 0
for i in range(N-1):
	for j in range(i+1, N):
		match_dict[(i,j)] = idx
		idx += 1
M = idx
edge = [[] for i in range(M)]
parent = [[] for i in range(M)]
for i in range(N):
	for j in range(N-2):
		a = A[i][j]
		a_nxt = A[i][j+1]
		x,y = min(i,a), max(i,a)
		z,w = min(i,a_nxt), max(i,a_nxt)
		m1 = match_dict[(x,y)]
		m2 = match_dict[(z,w)]
		edge[m1].append(m2)
		parent[m2].append(m1)
finish = [False for i in range(M)]
candidate = [i for i in range(M) if len(parent[i]) == 0]
depth = [-1 for i in range(M)]


day = 0
while len(candidate) > 0:
	new_candidate = []
	for c in candidate:
		finish[c] = True
		for e in edge[c]:
			parent[e].remove(c)
			if len(parent[e]) == 0:
				new_candidate.append(e)
		edge[c] = []
	candidate = new_candidate
	day += 1
print(day if all(finish) else -1)

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

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	string a, b;
	cin >> a >> b;
	for(int i = 0; i < a.size(); i ++)
	{
		string q = a.substr(i, a.size() - i) + a.substr(0, i);
		if(q == b)
			return cout << "Yes", 0;
	}
	cout << "No";





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int diff = A - B;
	C -= diff;
	C = max(C, 0);
	cout << C << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [T, X] = [long(input_raw[0]), long(input_raw[1])]
    print float(T)/float(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2932
#include <stdio.h>

int main(){
    
    int a,b,tmp;
    
    while(1){
        scanf("%d%d",&a,&b);
        if (a>b){
            tmp = a;
            a = b;
            b = tmp;
        }
        if (a==0&&b==0)break;
        printf("%-d %-d\n",a,b);
    }
    
    return 0;
}


Measured memory_bytes: 2056
w=int(raw_input())

number = range(1,w+1)
for i in xrange(input()):
    a,b=map(int,raw_input().split(","))
    tmp=number[a-1]
    number[a-1]=number[b-1]
    number[b-1]=tmp
print '\n'.join(map(str,number))

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

int main() {
    string S;
    cin >> S;
    int ans = 700;
    if (S[0] == 'o') ans += 100;
    if (S[1] == 'o') ans += 100;
    if (S[2] == 'o') ans += 100;
    cout << ans << endl;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	ll ans = 1000000000;
	//両方普通に買う
	ans = min(ans, (ll)a * x + b * y);
	//一枚あまして買う
	ll k = 2 * c * min(x, y);
	if (x >= y) k += (x - y) * a;
	else k += (y - x) * b;
	ans = min(ans, k);
	//多く買う
	ll h = 2 * c * max(x, y);
	ans = min(ans, h);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MAX_V 2000
#define INF 1000000000
using namespace std;

int N, M, L, V;

struct vertex{
	int v, time;
	bool operator < (const vertex& other){
		return time < other.time;
	}
}data[MAX_V];
int d[100][100];

vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void init(){
	memset(d, -1, sizeof(d));
	for(int i = 0; i < V; i++) G[i].clear();
}
void floyd_warshall(){
	for(int k = 0; k < N; k++){
		
		for(int i = 0; i < N; i++){
			d[i][i] = 0;
			for(int j = 0; j < N; j++){
				if(d[i][j] < 0) d[i][j] = INF;
				d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
			}
		}
	}
}

void add_edge(int u, int v){
	G[u].push_back(v);
	G[v].push_back(u);
}
bool dfs(int v){
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		int u = G[v][i], w = match[u];
		if(w < 0 || !used[w] && dfs(w)){
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int bipartite_matching(){
	int res = 0;
	memset(match, -1, sizeof(match));
	for(int v = 0; v < V; v++){
		if(match[v] < 0){
			memset(used, 0, sizeof(used));
			if(dfs(v)){
				res++;
			}
		}
	}
	return res;
}
int main(){
	int count = 0;
	while(cin>>N>>M>>L){
		if(!N && !M && !L) break;
		V = L;
		init();
		while(M--){
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			d[a][b] = c; 
			d[b][a] = c;
		}
		for(int i = 0; i < V; i++){
			scanf("%d%d", &data[i].v, &data[i].time);
		}
		floyd_warshall();
		/* 
		   ????????¨?????¨??????0~V-1
		   ????????¨?°?????????¨??????V ~ 2V-1
		*/
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				int u = data[i].v, v = data[j].v;
				if(i != j && data[i].time+d[u][v] <= data[j].time){
					add_edge(i, j+V);
				//	printf("u = %d, v = %d\n",u, v);
				}
			}
		}
		printf("%d\n", V - bipartite_matching());	
	}
	return 0;
}
			

Measured memory_bytes: 28116
#include<iostream>
using namespace std;
int main()
{
	int H;
	int W;
	while (1)
	{
		cin >> H >> W;
		if (H == 0 && W == 0){ break; }
		//上の列
		for (int i = 0; i < W; i++)
		{
			cout << '#';
		}
		cout << endl;
		//真ん中
		for (int j = 0; j < H - 2; j++)
		{
			cout << '#';
			for (int k = 0; k < W - 2; k++)
			{
				cout << '.';
			}
			cout << '#' << endl;

		}
		//下の列
		for (int i = 0; i < W; i++)
		{
			cout << '#';

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


Measured memory_bytes: 3112
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()
count = 0
for i in range(len(a)):
    if a[i] < 0:
        count += 1
        a[i] = -a[i]
ans = 0
if count % 2 == 0:
    ans = sum(a)
else:
    ans = sum(a) - 2 * min(a)
print(ans)


Measured memory_bytes: 14660
w,h,n = map(int,input().split())
para = []
for i in range(n):
    para.append([i for i in map(int,input().split())])

x_r = [w]
x_l = [0]
y_r = [h]
y_l = [0]
for i in range(n):
    if para[i][2] == 1 : x_l.append(para[i][0])
    elif para[i][2] == 2 :x_r.append(para[i][0])
    elif para[i][2] == 3 : y_l.append(para[i][1])
    else: y_r.append(para[i][1])
x = min(x_r)-max(x_l)
y = min(y_r) - max(y_l)
if x >= 0 and y >= 0 : 
    print("{}".format(x*y))
else: print(0)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        // k: コンテストの種類数
        int k = 26;
        
        // n: 1日目～n日目にコンテストが開催される
        int n = sc.nextInt();
        
        // c[i]: タイプiのコンテストのマイナス係数
        int[] c = new int[k];
        for (int i = 0; i < k; i++) {
            c[i] = sc.nextInt();
        }
        
        // s[d][i]: タイプiをd日目に開催したときに増加する満足度
        int[][] s = new int[n+1][k];
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < k; j++) {
                s[i][j] = sc.nextInt();
            }
        }
        
        // t[i]: i日目に開かれるコンテストのタイプ
        int[] t = new int[n+1];
        for (int i = 1; i <= n; i++) {
            t[i] = sc.nextInt() - 1;
            // Random random = new Random();
            // int randomValue = random.nextInt(k);
            // t[i] = randomValue;
        }
        
        // held[i]: タイプiのコンテストの開催日の集合
        TreeSet<Integer>[] held = new TreeSet[k];
        for (int i = 0; i < k; i++) {
            held[i] = new TreeSet<Integer>();
            
            held[i].add(0);
            held[i].add(n+1);
        }
        for (int i = 1; i <= n; i++) {
            int contest = t[i];
            held[contest].add(i);
        }
        
        // 先に満足度計算をする
        long score = 0;
        for (int i = 1; i <= n; i++) {
            int contest = t[i];
            
            // UP
            score += s[i][contest];
            
            // DOWN
            for (int j = 0; j < k; j++) {
                int last = held[j].floor(i);
                score -= c[j] * (i - last);
            }
        }
        
        // m: 変更クエリ数
        int m = sc.nextInt();
        long oldscore = score;
        while(m-- > 0) {
            int d = sc.nextInt();
            int q = sc.nextInt() - 1;
            
            int old = t[d];
            
            // 一旦変える
            // 消去
            score -= s[d][old];
            
            int prev = held[old].lower(d);
            int next = held[old].higher(d);
            score -= c[old] * (next - d) * (d - prev);
            
            held[old].remove(d);
            
            // 追加
            score += s[d][q];
            
            prev = held[q].lower(d);
            next = held[q].higher(d);
            score += c[q] * (next - d) * (d - prev);
            
            held[q].add(d);
            
            t[d] = q;
            
            System.out.println(score);
        }
    }
    
    static public class Test {
        Test() {
            // System.out.println(MOD);
        }
        
    }
}


Measured memory_bytes: 67920
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
ans=0
for i in range(N):
    A=list(map(int,input().split()))
    cnt=0
    for j in range(M):
        cnt+=A[j]*B[j]
    if cnt>(-C):
        ans+=1
print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
    int flag_one=0 , flag_two=0,flag_three=0,flag_four=0;
    int a,b;
    for (int i =0;i < 3;i++){
        scanf("%d %d",&a,&b);
        if(a==1 || b==1){
            flag_one++;
        }
        if(a==2 || b==2){
            flag_two++;
        }
        if(a==3 || b==3){
            flag_three++;
        }
        if(a==4 || b==4){
            flag_four++;
        }
    }
    if(flag_four > 2 || flag_three > 2 || flag_two > 2|| flag_one > 2){
        printf("NO");
    }else{
        printf("YES");
    }

    return 0 ;
}

Measured memory_bytes: 128
H,W = map(int, input().split())
A = [list(map(str, input())) for _ in range(H)]

q = [[0,0]]

while q != []:
	ans = 0
	cx,cy = q.pop()
	A[cx][cy] = "."

	if [cx,cy] == [H-1,W-1]:
		ans = 1
		for i in range(H):
			for j in range(W):
				if A[i][j] == "#":
					ans = 0
		break

	nps = [[cx+1,cy],[cx,cy+1]]
	for nx,ny in nps:
		if 0 <= nx < H and 0 <= ny < W:
			if A[nx][ny] == "#":
				q.append([nx,ny])
				break

if ans:
	print("Possible")
else:
	print("Impossible")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main() {
	int a = 1;
	int b = 1;
	cin >> a;
	cin >> b;
	for (int i = 1; i <= 3000; i++)
	{
		if (a==0&&b==0)
		{
			return 0;
		}
		else
		{
			if (a<b)
			{
				cout << a << " " << b << endl;
			}
			else
			{
				cout << b << " " << a << endl;
			}
		}
		cin >> a;
		cin >> b;
	}
	return 0;
}


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

using namespace std;
int n, k;
long long ans, kol;
int main(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        if((i % k) * 2 == k){
            kol++;
        }
        if(i % k == 0){
            ans++;
        }
    }
    cout << ans * ans * ans + kol * kol * kol;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
import java.io.IOException;
	public class Main {
		
	    public static void main(String[] args) throws IOException {
	    	Scanner teclado = new Scanner(System.in);
	    	int[][] x = new int[11][21];
	    	int a = teclado.nextInt();
	    	int b = teclado.nextInt();
	    	for(int i = 0;i<a;i++) {
	    		for(int ii = 0;ii<b;ii++) {
	    			x[i][ii] = teclado.nextInt();
	    		}
	    	}
	    	int orozco = 0;
	    	for(int i = 0;i<a-1;i++) {
	    		for(int ii = i+1;ii<a;ii++) {
	    			int orozcolord =0;
	    			for(int iii =0;iii<b;iii++) {
	    				orozcolord += (x[i][iii]-x[ii][iii])*(x[i][iii]-x[ii][iii]);
	    			}
	    			double sla = Math.sqrt(orozcolord);
	    			if(sla == (int)sla) {
	    				orozco++;
	    			}
	    		}
	    	}
	    	System.out.println(orozco);
	    }
	
	}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int A[N];
  int maxa = 0;
  int ans = 0;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    if(maxa <= A[i]) {
      ans++;
      maxa = A[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
	#ifndef ONLINE_JUDGE
	if (fopen("INPUT.txt", "r"))
	{
		freopen ("INPUT.txt" , "r" , stdin);
		//freopen ("OUTPUT.txt" , "w" , stdout);
	}
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	clock_t clk;
	clk = clock();
//-----------------------------------------------------------------------------------------------------------//

	READV(N);
	READAR(A,N);
	ll F[N+1]={0};
	FORI(i,0,N)
	{
		F[A[i]]++;
	}
	ll ans=0;
	FORI(i,1,N+1)
	{
		ans+=(F[i]*(F[i]-1))/2;
	}
	FORI(i,0,N)
	{
		ans-=(F[A[i]]*(F[A[i]]-1))/2;
		ans+=((F[A[i]]-2)*(F[A[i]]-1))/2;
		cout<<ans<<endl;
		ans+=(F[A[i]]*(F[A[i]]-1))/2;
		ans-=((F[A[i]]-2)*(F[A[i]]-1))/2;		
	}


//-----------------------------------------------------------------------------------------------------------//


	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <string>

void solve() {
    int n, m;
    std::cin >> n >> m;

    std::vector<std::string> ss(n);
    for (auto& s : ss) std::cin >> s;

    int ans = n * m;
    for (int j = 0; j < n; ++j) {
        for (int i = 1; i < j; ++i) {
            int sum = 0;

            for (int x = 0; x < n; ++x) {
                char t = (x < i ? 'W' : x < j ? 'B' : 'R');
                for (char c : ss[x]) {
                    if (c != t) ++sum;
                }
            }

            ans = std::min(ans, sum);
        }
    }
    std::cout << ans << std::endl;
}

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

    solve();

    return 0;
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define MOD 998244353

using namespace std;

typedef long long ll;

char s1[200005],s2[200005];
int f[200005];

int main() {
  int n;
  scanf("%d%s",&n,s1);
  reverse(s1,s1+n);
  for(int i=1;i<=n;i++)
    if (n%i==0&&((n/i)&1)) {
    	int s=0;
    	for(int j=n-1;j>=n-i;j--) s=(s*2LL+s1[j]-'0')%MOD;
    	f[i]=s;
    	for(int j=n-1;j>=0;j--)
    		if (j>=n-i) s2[j]=s1[j]; else s2[j]=((s2[j+i]-'0')^1)+'0';
    	bool ok=1;
    	for(int j=n-1;j>=0;j--)
    	  if (s1[j]!=s2[j]) {
    	  	if (s2[j]>s1[j]) ok=0;
    	  	break;
		  }
		f[i]=(f[i]+ok)%MOD;
	}
  int ans=0;
  for(int i=1;i<=n;i++)
    if (n%i==0) {
    	for(int j=2;i*j<=n;j++) f[i*j]=(f[i*j]-f[i]+MOD)%MOD;
    	ans=(ans+f[i]*2LL%MOD*i)%MOD;
	}
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
//#define s second
#define f first
long long const mod = 1000000007; 
#define inf 1000000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

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

ll power(ll x,ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
        
   
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=n;j++)
        {
            for(ll k=1;k<=n;k++)
            {
                ans=ans+gcd(i,gcd(j,k));
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3640
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let [a,b]=t.n(2)
  let c=b*2+1
  t.o(a%c==0?a/c:t.floor(a/c)+1)
}
main()


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

signed main(){
  int m,d,mm,dd;cin>>m>>d>>mm>>dd;
  if(m != mm){
    cout << 1 << endl;
  }else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

int n;
const int MAX = 30;
int A[MAX];

void solve()
{
	A[0] = 1;
	A[1] = 2;
	A[2] = 4;
	for(int i=3; i<30; i++)
	{
		A[i] = A[i-1] + A[i-2] + A[i-3];
	}	
}

int main(int argc, char** argv)
{
	solve();
	while(cin >> n, n)
	{
		cout << (A[n-1]/10 + 1)/365 + 1 << endl;
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

// https://atcoder.jp/contests/dp/tasks/dp_b
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] line = scanner.nextLine().split(" ");
        int n = Integer.parseInt(line[0]);
        int k = Integer.parseInt(line[1]);

        int[] nums = new int[n];
        int[] dp = new int[n];
        line = scanner.nextLine().split(" ");
        for (int i = 0; i < n; i++) {
            nums[i] = Integer.parseInt(line[i]);
            dp[i] = Integer.MAX_VALUE;
        }

        dp[0] = 0;

        for (int i = 0; i < n; i++) {
            int maxLen = Math.min(i + k, nums.length - 1);

            for (int j = i; j <= maxLen; j++) {
                dp[j] = Math.min(dp[j], dp[i] + Math.abs(nums[j] - nums[i]));
            }
        }
        System.out.println(dp[n - 1]);
    }
}

Measured memory_bytes: 63056
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

void solve(int a, int b, int c) {
    if (a == b) {
        std::cout << c << std::endl;
    } else {
        if (b == c) {
            std::cout << a << std::endl;
        } else {
            std::cout << b << std::endl;
        }
    }
}

int main() {
    struct timeval start,end;
    long long span;
    int a, b, c;

    gettimeofday(&start,NULL);

    std::cin >> a >> b >> c;
    solve(a, b, c);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 256
def solve(k, a):
    dp = [False]*(k+1)
    for i in range(1, k+1):
        for x in a:
            if i - x >= 0:
                dp[i] = dp[i] or not dp[i-x]
    return dp[-1]

n, k = map(int, input().split())
a = list(map(int, input().split()))
print('First' if solve(k, a) else 'Second')

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

int main() {
  ios::sync_with_stdio(false); 
  cin.tie(0);
  int l, r, d;
  cin >> l >> r >> d;
  if (l % d) 
    l = l + (d - l % d);
  if (l > r) {
    cout << "0\n";
    return 0;
  }
  cout << max(0, (r - l) / d) + 1 << '\n';
  return 0;
}

Measured memory_bytes: 3616
N,M=map(int,input().split())
A=[list(input()) for i in range(N)]
B=[list(input()) for i in range(M)]
def AB(h,w):
  ret=[[None]*M for i in range(M)]
  for i in range(M):
    for j in range(M):
      ret[i][j]=A[h+i][w+j]
  return ret
ans='No'
for h in range(N-M+1):
  for w in range(N-M+1):
    if AB(h,w)==B:
      ans='Yes'
      break
print(ans)


Measured memory_bytes: 3064
#include <cstdint>
#include <cstdio>

int main(void) {
    int n, k;
    std::scanf("%d %d\n", &n, &k);
    char *str = new char[static_cast<std::size_t>(n + 2)];
    std::scanf("%s", str);
    str[k - 1] = static_cast<char>(static_cast<uint8_t>(str[k - 1]) + 0x20);
    std::printf("%s", str);
}


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

using namespace std;

const int MX=100005,inf=0x3f3f3f3f;

typedef pair<int,int> pii;
#define fr first
#define se second
#define mp make_pair
#define pb push_back
typedef vector<int> vi;

int n,a,b;
map<int,set<pii> >x,y;
map<int,vi>xs,ys;
pii p[MX];
int vis[MX];
inline int dis(pii l,pii r){return max(abs(l.fr-r.fr),abs(l.se-r.se));}
inline void ins(int i){x[p[i].fr].insert(mp(p[i].se,i)),y[p[i].se].insert(mp(p[i].fr,i));}
inline void rem(int i){x[p[i].fr].erase(mp(p[i].se,i)),y[p[i].se].erase(mp(p[i].fr,i));}

int main(){
	ios::sync_with_stdio(false);
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++){
		int u,v;cin>>u>>v;
		p[i].fr=u+v,p[i].se=u-v;
		//cout<<p[i].fr<<' '<<p[i].se<<endl;
	}
	for(int i=1;i<=n;i++)ins(i);
	deque<int>q;q.clear(),q.pb(a),q.pb(b);
	vis[a]=1,vis[b]=1,rem(a),rem(b);
	int D=dis(p[a],p[b]);
	while(!q.empty()){
		pii r=p[q.front()];q.pop_front();
		map<int,set<pii> >::iterator s=x.find(r.fr-D);
		if(s!=x.end()){
			for(set<pii>::iterator i=s->se.lower_bound(mp(r.se-D,~inf));i!=s->se.end()&&i->fr<=r.se+D;i=s->se.erase(i)){
				if(!vis[i->se])q.pb(i->se);
				vis[i->se]=1;
			}
		}
		s=x.find(r.fr+D);
		if(s!=x.end()){
			for(set<pii>::iterator i=s->se.lower_bound(mp(r.se-D,~inf));i!=s->se.end()&&i->fr<=r.se+D;i=s->se.erase(i)){
				if(!vis[i->se])q.pb(i->se);
				vis[i->se]=1;
			}
		}
		s=y.find(r.se-D);
		if(s!=y.end()){
			for(set<pii>::iterator i=s->se.lower_bound(mp(r.fr-D,~inf));i!=s->se.end()&&i->fr<=r.fr+D;i=s->se.erase(i)){
				if(!vis[i->se])q.pb(i->se);
				vis[i->se]=1;
			}
		}
		s=y.find(r.se+D);
		if(s!=y.end()){
			for(set<pii>::iterator i=s->se.lower_bound(mp(r.fr-D,~inf));i!=s->se.end()&&i->fr<=r.fr+D;i=s->se.erase(i)){
				if(!vis[i->se])q.pb(i->se);
				vis[i->se]=1;
			}
		}
	}
	//for(int i=1;i<=n;i++)cout<<vis[i]<<endl;
	long long c=0;
	for(int i=1;i<=n;i++)if(vis[i]){
		xs[p[i].fr].pb(p[i].se);
		ys[p[i].se].pb(p[i].fr);
	}
	for(map<int,vi>::iterator i=xs.begin();i!=xs.end();i++)sort(i->se.begin(),i->se.end());
	for(map<int,vi>::iterator i=ys.begin();i!=ys.end();i++)sort(i->se.begin(),i->se.end());
	for(int i=1;i<=n;i++){
		map<int,vi>::iterator s=xs.find(p[i].fr-D);
		c+=upper_bound(s->se.begin(),s->se.end(),p[i].se+D)-lower_bound(s->se.begin(),s->se.end(),p[i].se-D);
		s=xs.find(p[i].fr+D);
		c+=upper_bound(s->se.begin(),s->se.end(),p[i].se+D)-lower_bound(s->se.begin(),s->se.end(),p[i].se-D);
		s=ys.find(p[i].se-D);
		c+=lower_bound(s->se.begin(),s->se.end(),p[i].fr+D)-upper_bound(s->se.begin(),s->se.end(),p[i].fr-D);
		s=ys.find(p[i].se+D);
		c+=lower_bound(s->se.begin(),s->se.end(),p[i].fr+D)-upper_bound(s->se.begin(),s->se.end(),p[i].fr-D);
	}
	cout<<(c/2)<<endl;
	return 0;
}

Measured memory_bytes: 41216