akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 200010;
 
// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}
 
ll inverse(ll a) {
    return modpow(a, mod-2);
}
 
ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];
 
void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i*fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}
 
//--- main関数でinit()を呼び出すのを忘れるな ---//
 
// 素因数分解。計算量はO(√n)
map<ll, ll> primefactor(ll n) {  // (nのi番目の素因数, その素因数の個数)のmapを返す(n = 720 = (2^4)*(3^2)*(5^1)なら{(2, 4), (3, 2), (5, 1)}のように)
    map<ll, ll> res;
    for(ll i = 2; i*i <= n; i++) {
        while(n%i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) {
        res[n] = 1;
    }
    return res;
}
 
int main() {
    ll n, m;
    cin >> n >> m;
 
    init();
 
    map<ll, ll> mp = primefactor(m);
    ll ans = 1;
    for(auto p : mp) {
        ll k = p.second;
        ans *= Comb((n-1)+k, k);
        ans %= mod;
    }
 
    out(ans);
    re0;
}

Measured memory_bytes: 4992
from collections import Counter
N = int(input())
a = list(map(int, input().split()))
Q = int(input())
bc = [list(map(int, input().split())) for _ in range(Q)]
tmp_counter = Counter(a)
tmp_sum = sum(a)
for b, c in bc:
    if b in tmp_counter.keys():
        tmp_sum += (c - b) * tmp_counter[b]
        tmp_counter[c] += tmp_counter[b]
        tmp_counter[b] = 0
    print(tmp_sum)


Measured memory_bytes: 36488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
int main() {
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i+=2) {
        if (i + 1 >= s.size()) {
            cout << "No" << endl;
            return 0;
        }
        if (s[i] != 'h' || s[i+1] != 'i') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n, i, a, amin = 1e5, amax = 0;
  cin >> n;
  for ( i = 0; i < n; i++ ){
    cin >> a;
    amax = max(amax, a);
    amin = min(amin, a);
  }
  cout << amax - amin << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String str = sc.next();

		if(n>=str.length()) {
			System.out.println(str);
		}else {
			System.out.println(str.substring(0,n)+"...");
		}

	}

}



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

typedef long long int ll;

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    while(a > 0 && c > 0){
        a -= d;
        c -= b;
    }

    if(a < 0 && c < 0){
        cout << "Yes";
    }
    else if(c > 0){
        cout << "No";
    }
    else{
        cout << "Yes";
    }

    return 0;
}

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

int main() {
	int n;
	cin>>n;
	long long b[n+1];
	long long a[n];
	for(int i=0;i<=n;i++)
	{
		cin>>b[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	long long ans=0;
	for(int i=0;i<n;i++)
	{
	   long long x = min(a[i],b[i]);
	   b[i]-=x;
	   a[i]-=x;
	   ans+=x;
	   x=min(a[i],b[i+1]);
	   b[i+1]-=x;
	   a[i]-=x;
	   ans+=x;
	}
	cout<<ans;
		
	
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if (a >= 13) cout << b << endl;
    else if (a >= 6) cout << b/2 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
int main() {
    int n,i, d, t, a, h, ans,min=1000000000;
    scanf("%d%d%d", &n, &t, &a);
    t = t * 1000;
    a = a * 1000;
    for (i = 0; i < n; i++) {
        scanf("%d", &h);
        d = a - t + (h * 6);
        if (d < 0)
            d = -d;
        if (d < min) {
            ans = i + 1;
            min = d;
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define bit(n) 1 << n
using namespace std;
using cd = complex <double>;

typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pair <int, int> > vii;
typedef map <int, int> mii;

const int Inf = 100000;
const int mod = 1000000007;
const double Pi = acos(-1);

void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int x, y, a, b, c;
long long ans = 0;
int green = 0, red = 0, color = 0;
priority_queue <pair <long long, int> > pq;

void Solve()
{
	cin >> x >> y >> a >> b >> c;
	for(int i = 1; i <= a; i++)
	{
		long long z;
		cin >> z;
		pq.push(mp(z, 1));
	}
	for(int i = 1; i <= b; i++)
	{
		long long z;
		cin >> z;
		pq.push(mp(z, 2));
	}
	for(int i = 1; i <= c; i++)
	{
		long long z;
		cin >> z;
		pq.push(mp(z, 3));
	}
	while(pq.empty() == false)
	{
		int zz = pq.top().first, id = pq.top().second;
		pq.pop();
		if(red + green + color == x + y)
		{
			break;
		}
		if(id == 1)
		{
			if(red < x)
			{
				ans += zz;
				red++;
			}
		}
		if(id == 2)
		{
			if(green < y)
			{
				ans += zz;
				green++;
			}
		}
		if(id == 3)
		{
			if(red + green + color < x + y)
			{
				ans += zz;
				color++;
			}
		}
	}
	cout << ans;
}

signed main()
{
	Solve();
}


Measured memory_bytes: 10476
a,b,c,d,e,f=map(int,input().split())
sw=set()
for i in range(30//a+1):
  for j in range(30//b+1):
    w=a*i+b*j
    if 0<w*100<=f: sw|={w}
ss=set()
for i in range(3000//c+1):
  for j in range(3000//d+1):
    s=c*i+d*j
    if s<=f: ss|={s}
ll=[]
for w in sw:
  for s in ss:
    t=w*100+s
    if t<=f and s<=w*e:
      ll.append([-s/w,t,s])
ll.sort()
print(ll[0][1],ll[0][2])

Measured memory_bytes: 4468
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(void){

	double a, l, x;
	while (cin >> a){
		cin >> l >> x;
		double s = (2 * l + a)/2;
		double A = sqrt(s*(s - a)*(s - l)*(s - l));
		s = (2 * l + x) / 2;
		double B = sqrt(s*(s - l)*(s - (l + x) / 2)*(s - (l + x) / 2));
		
		printf("%.6f\n", A + 2*B);
	}


	return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

struct dsu {
	ll n;
	vl p;

	dsu(ll n): n(n), p(n) { iota(all(p),0); }
	
	ll find(ll x) {
		if (x == p[x]) return x;
		return p[x] = find(p[x]);
	}

	bool unite(ll x, ll y) {
		x = find(x), y = find(y);
		if (x == y) return false;
		
		if (rand() & 1) swap(x,y);
		p[y] = x;
		return true;
	}
};

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

	ll n, m;
	cin >> n >> m;
	
	dsu D(n);
	while (m--) {
		ll a, b;
		cin >> a >> b;
		D.unite(a-1,b-1);
	}

	ll res = -1;
	FOR(i,0,n) res += D.find(i) == i;
	cout << res << endl;




}



Measured memory_bytes: 3992
# ABC 049 C
S = str(input())

ans = 'YES'
while len(S)>0:
  if S[-5:] == 'dream':
    S = S[:-5]
  elif S[-5:] == 'erase':
    S = S[:-5]
  elif S[-6:] == 'eraser':
    S = S[:-6]
  elif S[-7:] == 'dreamer':
    S = S[:-7]
  else:
    ans = 'NO'
    break
print(ans)


Measured memory_bytes: 3188
function Main(input){
    input = input.split("\n");
    for(var i = 0;1;i++){
        var n = parseInt(input[i],10);var ans = 0;
        if(n == 0)
            break;
        for(var j = 2;j < n;j++){
            if(n - j * (j - 1) / 2 > 0 && (n - j * (j - 1) / 2) % j == 0){
                ans++;
            }
        }
        console.log(ans);
    }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 15816
#include <bits/stdc++.h>
#define N 100
#define INF 1e9 + 5
#define LINF 1e18 + 5

using namespace std;
using ll = long long;
string a, b;
ll memo[3003][3003], gp[3003][3003];
char s[3003];
// ll solve2(int y, int x)
// {
//     if (memo[y][x] != -1)
//         return memo[y][x];
//     if (x == 0 || y == 0)
//         return memo[y][x] = 0;
//     ll best = -1;
//     best = max(best, solve(y, x - 1));
//     best = max(best, solve(y - 1, x));
//     if (a[y] == b[x])
//         best = max(best, solve(y - 1, x - 1) + 1);
//     return memo[y][x] = best;
// }

// int main()
// {
//     cin >> a >> b;
//     a = "$" + a;
//     b = "$" + b;
//     memset(memo, -1, sizeof(memo));

//     ll maxlenth = solve(a.length(), b.length());

//     for (int y = 0; y <= a.length(); y++)
//     {
//         for (int x = 0; x <= b.length(); x++)
//         {
//             cout << memo[y][x];
//         }
//         cout << endl;
//     }
//     if (maxlenth == 1)
//     {
//         cout << "";
//         return 0;
//     }
//     int x = b.length(), y = a.length();

//     string t = "";
//     while (x > 0 && y > 0)
//     {
//         if (memo[y - 1][x] == memo[y][x - 1])
//         {
//             if (memo[y][x] > memo[y - 1][x - 1])
//             {
//                 t = a[y] + t;
//             }
//             x--, y--;
//         }
//         else
//         {
//             if (memo[y - 1][x] > memo[y][x - 1])
//                 y--;
//             else
//                 x--;
//         }
//     }
//     // cout<<maxlenth<<endl;
//     cout << t;
//     return 0;
// }

int n,m,x,y;
int dp[3003][3003];
int solve(int i, int j)
{
    if(dp[i][j] != -1) return dp[i][j];
    
    if(i == 0 || j == 0) return dp[i][j] = 0;
    
    int res = solve(i - 1,j);
    gp[i][j] = 1;
    
    int g = solve(i,j - 1);
    if(res < g){
        res = g;
        gp[i][j] = 2;
    }
    if(a[i] == b[j]){
        g = solve(i - 1,j - 1) + 1;
        if(res < g){
            res = g;
            gp[i][j] = 3;
        }
    }
    return dp[i][j] = res;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    cin>>a>>b;
    n = a.length(); m = b.length();
    a = "$" + a;
    b = "$" + b;
    solve(n,m);
    b = "";
    x = n; y = m;
    while(x > 0 && y > 0){
        if(gp[x][y] == 1)
            x -= 1;
        else{
            if(gp[x][y] == 3){
                b = a[x]+b;
                x -= 1;
            }
            y -= 1;
        }
    }
    
    cout<<b;
    return 0;
}

Measured memory_bytes: 107264
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define mod MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    ll n, m; cin >> n >> m;
    ll cnt = 0;
    if(n == 1 && m == 1){
        cnt = 1;
    } else if((n!=1 && m==1) || (n==1 && m!=1)){
        cnt = n*m -2;
    } else {
        n -= 2;
        m -= 2;
        cnt = n*m;
    }
    cout << cnt << endl;
}

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

using namespace std;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    double rate = 380000.0;
    double ans=0;
    for(int i=0;i<N;i++){
        double a;
        string s;
        cin >> a >> s;
        if(s=="JPY") ans+=a;
        else ans+=a*rate;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*input
1 1
1000
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ll long long 
#define ld long double
#define pii pair<int,int>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e12;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1){
            res=(res*a)%MOD;
        }
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=1e6+5;
const ll maxlg=__lg(maxn)+2;
int arr[maxn];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,k;
    cin>>n>>k;
    REP(i,n) cin>>arr[i];
    sort(arr,arr+n); 
    ll ans=0;
    REP(i,k) ans+=arr[i];
    cout<<ans;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

    private static boolean grouped(int[] grp, int x, int y) {
        boolean bx = false;
        boolean by = false;

        for (int i = 0; i < grp.length; i++) {
            if (grp[i] == x) {
                bx = true;
            }
            if (grp[i] == y) {
                by = true;
            }
        }

        return bx && by;
    }

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

        int[] grp1 = {1, 3, 5, 7, 8, 10, 12};
        int[] grp2 = {4, 6, 9, 11};
        int[] grp3 = {2};

        System.out.println( (grouped(grp1, x, y) || grouped(grp2, x, y)) ? "Yes" : "No" );
    }

}

Measured memory_bytes: 21844
n,a,b = map(int,input().split(" "))
if n == 1:
    if a == b:
        print(1)
    else:
        print(0)
elif a > b:
    print(0)
elif n == 2:
  	print(1)
else:
    print(b * (n-2) - a * (n-2) + 1)
    

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  // nC0 is 1 
  
    for (ll i = 1; i <= n; i++) 
    { 
        // Compute next row of pascal triangle using 
        // the previous row 
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n=nxtl(),m=nxtl();
    vector <ll> x(n),y(m);
    generate(all(x),nxtl);
    generate(all(y),nxtl);
    ll test=0;
    ll mod=1e9+7;
    for(ll i=0;i<m-1;i++)
    {
        ll temp=abs(y[i+1]-y[i])*(i+1)*(m-i-1);
        (test+=temp)%=mod;
    }
    ll t=test;
    test=0;
    for(ll i=0;i<n-1;i++)
    {
        ll temp=((abs(x[i+1]-x[i])*(i+1)*(n-i-1))%mod)*t;
        temp%=mod;
        (test+=temp)%=mod;
    }
    //(test*=t)%=mod;
    cout<<test<<endl;

    
    return 0;   
}




 
 


Measured memory_bytes: 1920
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;
typedef long long ll;


typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

vector<int> G[100005];
std::vector<P> tree[100010];

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define re(i,a,b) for(i=a;i<=b;i++)

ll i,j,ii,jj;
ll n,m;
ll kaisi,k,hazime,owari;
ll a,b,c,d;
char s[100005],t[100005];
ll ss[100005],tt[100005];

int main(){
    cin>>s>>t;
    n=strlen(s);
    m=strlen(t);
    ss[0]=tt[0]=0;
    for(i=1;i<=n;i++){
        if(s[i-1]=='A'){
            ss[i]=ss[i-1]+1;
            
        }else{
            ss[i]=ss[i-1]+2;
        }

    }

    for(i=1;i<=n;i++){
        if(t[i-1]=='A'){
            tt[i]=tt[i-1]+1;
        }else{
            tt[i]=tt[i-1]+2;
        }

    }
    ll q;
    cin>>q;
    for(i=0;i<q;i++){
        cin>>a>>b>>c>>d;
        if((ss[b]-ss[a-1]-tt[d]+tt[c-1])%3==0){
            p("YES");
        }else{
            p("NO");
        }
    }
    
    return 0;
}


Measured memory_bytes: 7040
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>

#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define ALL(X)      (X).begin(),(X).end()
typedef long long LL;

using namespace std;

int n,m,q;
vector<int> G[100000+2];
vector<int> v,d,c;

int visited[100000+2];
int color[100000+2][10+1];

void bfs(int start,int dest,int co){
    queue<pair<int,int> > qu;

    if(color[start][dest] == 0){
        qu.push(mp(start,dest));
        color[start][dest]=co;
    }

    while(!qu.empty()){
        auto p = qu.front();qu.pop();
        // printf("%d %d\n",p.first,p.second);
        if(p.second == 0)continue;
        REP(i,SZ(G[p.first])){
            if(color[G[p.first][i]][p.second-1] == 0){
                qu.push(mp(G[p.first][i], p.second-1));
                color[G[p.first][i]][p.second-1]=co;
            }
        }
    }
}

int main(void){
    scanf("%d%d",&n,&m);
    FOR(i,1,n+1){G[i].pb(i);}
    REP(i,m){int a,b;scanf("%d%d",&a,&b);G[a].pb(b);G[b].pb(a);}
    scanf("%d",&q);
    REP(i,q){int x,y,z;scanf("%d%d%d",&x,&y,&z);v.pb(x);d.pb(y);c.pb(z);}
    for(int i=q-1;0<=i;i--){
        bfs(v[i],d[i],c[i]);
    }
    FOR(i,1,n+1)printf("%d\n",color[i][0]);
    return 0;
}


Measured memory_bytes: 13604
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

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

    vector<int> li(m);
    vector<int> ri(m);
    int l, r;
    for(int i=0; i<m; i++){
        cin >> l >> r;
        li[i] = l;
        ri[i] = r;
    }

    sort(li.rbegin(), li.rend());
    sort(ri.begin(), ri.end());

    // cout << li[0] << endl;
    // cout << ri[0] << endl;
    cout << max(ri[0] - li[0] + 1, 0) << endl;;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
//#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m,k;

int main(){
	cin>>n>>m>>k;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i*m+n*j-2*i*j==k){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;

int main() {
  ll sum = 0;
  int N;
  cin >> N;
  vector<long long> vec(N);
  for (int i = 0;i < N;i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  ll ans = INF;
  ll temp = vec.at(0);
  ans = min(ans,abs(sum-temp*2));
  for (int i = 1;i<N-1;i++) {
    temp += vec.at(i);
    ans = min(ans,abs(sum - temp*2));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 10500
int a[N][27];
int a2[N][27];
int e[N][365];
int v[N][365];
int sz, sz2;

int main() {
	int n;
	int x, y;
	vector<pair<int, pair<int, int> > >b;
	int c[26];
	int d[365][26];
	bool dd[365][26];
	vector<int>ds;
	int ans[365];
	scanf("%d", &n);
	f(i, 26)scanf("%d", &c[i]);
	f(i, n) {
		f(j, 26)scanf("%d", &d[i][j]);
		ds.clear();
		f(j, 26)ds.push_back(-d[i][j]);
		sort(ds.begin(), ds.end());
		f(j, 26) {
			if ((d[i][j] + ds[5]) > 0)dd[i][j] = true;
			else dd[i][j] = false;
		}
	}
	sz = 1;
	f(i, 26)a[0][i] = -1;
	a[0][26] = 0;
	f(t, n) {
		b.clear();
		f(i, sz) {
			x = a[i][26];
			f(j, 26) {
				x -= ((t - a[i][j])*c[j]);
			}
			f(j, 26) {
				if (dd[t][j]) {
					y = x + d[t][j];
					y += ((t - a[i][j])*c[j]);
					b.push_back(make_pair(y, make_pair(i, j)));
				}
			}
		}
		sort(b.begin(), b.end(), greater<pair<int, pair<int, int> > >());
		sz2 = b.size();
		if (sz2 > N)sz2 = N;
		f(i, sz2) {
			x = b[i].second.first;
			y = b[i].second.second;
			a2[i][26] = b[i].first;
			f(j, 26)a2[i][j] = a[x][j];
			a2[i][y] = t;
			e[i][t] = x;
			v[i][t] = y;
		}
		f(i, sz2) {
			f(j, 27)a[i][j] = a2[i][j];
		}
		sz = sz2;
	}
	x = 0;
	for (int i = n - 1; i >= 0; i--) {
		ans[i] = v[x][i];
		x = e[x][i];
	}
	f(i, n)printf("%d\n", ans[i] + 1);

	return 0;
}


Measured memory_bytes: 35916
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int main() {
    string s;
    cin >> s;
    ll n = s.length();
    ll ans = 0;
    reverse(ALL(s));
    ll b = 0;
    REP(i,n){
        if (s[i] == 'B'){
            ans += i - b;
            b++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1152
open System

let n, k =
    let l = Console.ReadLine().Split(' ')
    let n = l.[0] |> int
    let k = l.[1] |> Int64.Parse
    n, k

let a =
    Console.ReadLine().Split(' ')
    |> Array.map (fun x -> int(x) - 1)

let ans =
    let loopOrigin, path =
        let mutable towns = Set<int> []

        let rec search (path: int list) =
            let tail =
                match path with
                | tail :: _ -> tail
                | _ -> -1
            let next = a.[tail]

            if towns.Contains next then
                let path = path |> List.rev
                let loopOrigin =
                    path |> List.findIndex (fun t -> t = next)
                loopOrigin, path
            else
                towns <- towns.Add next
                search (next :: path)

        search [0]

    if k < int64(loopOrigin) then
        path.[int (k)] + 1
    else
        let idx =
            let loopOrigin = int64 loopOrigin
            let freq = int64 (List.length path) - loopOrigin
            loopOrigin + (k - loopOrigin) % freq |> int
        path.[idx] + 1

ans |> Console.WriteLine


Measured memory_bytes: 73596
// Sakhiya07 - Yagnik Sakhiya
 
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double

#define pll pair<ll,ll>
#define ff first
#define ss second

#define pb push_back
#define all(x) x.begin(),x.end()

#define MOD  1000000007
const int N = 100005; 

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));

void solve()
{
    ll n,x,t;
    cin >> n >> x >> t;
    ll now = 0;
    ll ans = 0;
    while(now<n)
    {
        now += x;
        ans += t;
    }
    cout<<ans;
}

int main()
{
    FAST;
    int t = 1;
 // cin >> t;
    for(int i=1;i<=t;i++)
    {
        solve();
    }
}

Measured memory_bytes: 3636
a, b, c, d = map(int, input().split())

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a % b)
def lcm(a, b):
    return a * b // gcd(a, b)
def solve(n):
    return n - n//c - n//d + n//lcm(c, d)

div_a = solve(a-1)
div_b = solve(b)
print(div_b - div_a)


Measured memory_bytes: 3060
import math
n = int(input())
nums = []
for i in range(n):
    nums.append(int(input()))

def isprime(s):
    for i in range(2, int(math.sqrt(s))+1):
        if s % i == 0:
            return 0
    return 1

count = 0
for num in nums:
    count += isprime(num)
    
print(count)


Measured memory_bytes: 6040
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  vector<pair<int,int>>ci(m);
  rep(i,m)
  {
    int a,b;
    cin>>a>>b;
    a--;b--;
    ci[i]={b,a};
  }
  sort(all(ci));
  int res=0;
  int ma=-1;
  rep(i,m)
  {
    if(ma>ci[i].second)continue;
    if(chmax(ma,ci[i].first))res++;
  }
  cout<<res<<endl;



  return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    V<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    V<int> ord(n); iota(ALL(ord), 0);
    sort(ALL(ord), [&](int i, int j) {
        if (a[i] == a[j]) return i > j;
        else return a[i] > a[j];
    });

    vll ans(n, 0);
    int mini = ord[0];
    for (ll i = 1; i < n; i++) {
        ans[mini] += i * (ll)(a[ord[i - 1]] - a[ord[i]]);
        chmin(mini, ord[i]);
    }
    ans[mini] += (ll)n * (ll)a[ord.back()];

    for (int i = 0; i < n; i++) cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 2688
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define cc 6.28318530717958623200
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int r;
    cin >> r;

    cout << fixed << setprecision(10) << (r * cc) << '\n';
    return 0;
}

Measured memory_bytes: 3796
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, C = MAP()
D = [LIST() for _ in range(C)]
c = [LIST() for _ in range(N)]

group0 = []
group1 = []
group2 = []
for i in range(N):
	for j in range(N):
		if (i+j)%3 == 0:
			group0.append(c[i][j]-1)
		elif (i+j)%3 == 1:
			group1.append(c[i][j]-1)
		elif (i+j)%3 == 2:
			group2.append(c[i][j]-1)
# print(group0)
# print(group1)
# print(group2)

color_0 = []
inv_0 = {}
for i in range(C):
	tmp = 0
	for item0 in group0:
		tmp += D[item0][i]
	color_0.append((tmp, i))
	inv_0[i] = tmp
color_0 = sorted(color_0)[0:3]
color_0_lis = [x[1] for x in color_0]

color_1 = []
inv_1 = {}
for i in range(C):
	tmp = 0
	for item1 in group1:
		tmp += D[item1][i]
	color_1.append((tmp, i))
	inv_1[i] = tmp
color_1 = sorted(color_1)[0:3]
color_1_lis = [x[1] for x in color_1]

color_2 = []
inv_2 = {}
for i in range(C):
	tmp = 0
	for item2 in group2:
		tmp += D[item2][i]
	color_2.append((tmp, i))
	inv_2[i] = tmp
color_2 = sorted(color_2)[0:3]
color_2_lis = [x[1] for x in color_2]
# print(color_0)
# print(color_0_lis)
# print(color_1)
# print(color_1_lis)
# print(color_2)
# print(color_2_lis)
ans = INF
for i in color_0_lis:
	for j in color_1_lis:
		for k in color_2_lis:
			tmp = 0
			if i == j or j == k or k == i:
				continue
			else:
				tmp += inv_0[i]
				tmp += inv_1[j]
				tmp += inv_2[k]
				ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 9872
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x,y,i,r,ans=1;
  cin>>n>>m;
  map<int,int> z;
  vector<pair<int,int>> v;
  for(i=0;i<m;i++){
    cin>>x>>y;
    if(!z.count(x)) z[x]=y;
    else if(y<z.at(x)) z.at(x)=y;
  }
  for(auto w:z) v.push_back(make_pair(w.first,w.second));
  r=v.at(0).second;
  for(i=1;i<(int)v.size();i++){
    if(r<=v.at(i).first){
      ans++;
      r=v.at(i).second;
    }
    else if(r>v.at(i).second){
      r=v.at(i).second;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 8920
#include <bits/stdc++.h>
using namespace std;
string s;
long long  k;

int main(){
    cin>>s;
    for(int i=0;i<s.size();i++){
       if(s[i]=='7')k++;

    }
if(k>0)cout<<"Yes";
else cout<<"No";

    return 0;}




Measured memory_bytes: 3592
q=int(input())
lr=[list(map(int, input().split())) for _ in range(q)]

import math
def is_prime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if n%i==0:
            return False
    return True

n=10**5+1
prime_list=[0]*n
for i in range(3,n,1):
    if is_prime(i) and is_prime((i+1)//2):
        prime_list[i]=1

from itertools import accumulate
acc=list(accumulate(prime_list))

for lr_i in lr:
    print(acc[lr_i[1]]-acc[lr_i[0]-1])



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

int main(){
  string w;
  cin >> w;
  sort(w.begin(), w.end());
  int L=w.size();
  string Ans="Yes";
  if(L%2==0){
    for(int i=0; i<L/2; i++){
      if(w.at(2*i)!=w.at(2*i+1)){
        Ans="No";
      }
    }
  }
  else{
    Ans="No";
  }
  cout << Ans << endl;
}
  

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc169/tasks/abc169_b

LIMIT = 10**18
N = gets.to_i
As = gets.split.map(&:to_i)

if As.include?(0)
  puts 0
  exit 0
end

ans = 1
N.times do |i|
  ans *= As[i]
  if ans > LIMIT
    puts -1
    exit 0
  end
end

puts ans


Measured memory_bytes: 21568
#include <stdio.h>

int n, cnt[1001001], up[1001001];

int main()
{
  scanf ("%d",&n);
  for (int i=0;i<n;i++){
int x; scanf ("%d",&x); cnt[x]++;
  }
  
  for (int i=1;i<1001001;i++){
    for (int j=i;j<1001001;j+=i) up[j] += cnt[i];
  }
  
  int r = 0;
  for (int i=1;i<1001001;i++) if (up[i] == 1) r += cnt[i];
  printf ("%d\n",r);
return 0;
}

Measured memory_bytes: 11068
import sys
#from collections import deque
input = sys.stdin.buffer.readline

x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int,input().split())),reverse=True)
q = sorted(list(map(int,input().split())),reverse=True)
r = sorted(list(map(int,input().split())),reverse=True)
ans = p[:x]
ans[x:x] = q[:y]
ans += r
ans = sorted(ans,reverse=True)
print(sum(ans[:x+y]))

Measured memory_bytes: 22340
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
int main(){
  ll n,w;cin>>n>>w;
  vector<ll> weight(n),value(n);
  rep(i,n) cin>>weight[i]>>value[i];
  ll dp[n+1][w+1];
  rep(i,w+1) dp[0][i]=0;
  rep(i,n){
    rep(j,w+1){
      if(j>=weight[i]) dp[i+1][j]=max(dp[i][j],dp[i][j-weight[i]]+value[i]);
      else dp[i+1][j]=dp[i][j];
    }
  }
  cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 79104
open System
let C() = Console.ReadLine()
let N = (C>>int)()
let A = C().Split() |> Array.map int
let t = 
    Array.fold (fun acc x -> 
        match Map.tryFind x acc with Some(v) -> Map.add x (v + 1) acc | None -> Map.add x 1 acc 
    ) Map.empty A
for i in 1..N do 
    match Map.tryFind i t with 
    | Some x -> x 
    | None -> 0 
    |> Console.WriteLine


Measured memory_bytes: 69172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str,str1;
  cin>>str;
  if(str=="Sunny"){
    str1="Cloudy";
  }
  if(str=="Cloudy"){
    str1="Rainy";
  }
   if(str=="Rainy"){
    str1= "Sunny";
   }
  cout<<str1;
}

Measured memory_bytes: 256
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e50)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    N, K = l_inpl()
    xy = []
    for _ in range(N):
        xi, yi = l_inpl()
        xy.append([xi, yi])

    ans = INF * INF
    xy.sort()

    for l, (xl, yl) in list(enumerate(xy))[:N-K+1]:
        for r, (xr, yr) in list(enumerate(xy))[l+K-1:]:
            ys = sorted([ y for _, y in xy[l:r+1]]) 
            for yd, yu in zip(ys, ys[K-1:]):
                if yd <= yl and yd <= yr and yl <= yu and yr <= yu:
                # if yd <= yl and yr <= yu:
                    ans = min(ans, (xr-xl) * (yu - yd))
    
    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 3824
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.nio.Buffer;
import java.util.*;

public class Main {
    public static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static FastReader r=new FastReader();
    public static void main(String[] args){
        int n=r.nextInt();
        int m=r.nextInt();
        long [][]a=new long[n+1][m+1];
        int k=r.nextInt();
        for(int t=0;t<k;++t){
            int i,j;
            long v;
            i=r.nextInt();
            j=r.nextInt();
            v=r.nextLong();
            a[i][j]=v;
        }
        long [][][]dp=new long[n+1][m+1][4];
        dp[1][1][1]=a[1][1];
        dp[1][1][0]=0;
        for(int i=1;i<=n;++i){
            for(int j=1;j<=m;++j){
                if(i==1&&j==1) continue;
                for(int items=0;items<=3;++items){
                    dp[i][j][items]=dp[i][j-1][items];
                }
                for(int items=0;items<=3;++items){
                    dp[i][j][0]=Math.max(dp[i][j][0],dp[i-1][j][items]);
                }
                if(a[i][j]!=0){
                    for(int items=1;items<=3;++items){
                        dp[i][j][items]=Math.max(dp[i][j][items],dp[i][j-1][items-1]+a[i][j]);
                    }
                    for(int items=0;items<=3;++items){
                        dp[i][j][1]=Math.max(dp[i][j][1],dp[i-1][j][items]+a[i][j]);
                    }
                }
            }
        }
        long ans=0;
        for(int items=0;items<=3;++items){
            ans=Math.max(ans,dp[n][m][items]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 694828
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

typedef pair<int,int> P;
typedef pair<P,P> PP;

int main(void){
	int w, h, s[30][30], c[4], f[30][30][4], i, j, nx, ny, nc, nd, dir;
	const int ctrl[4] = {0,1,2,-1}, dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
	priority_queue<PP,vector<PP>,greater<PP> > que;
	while(1){
		scanf("%d%d",&w,&h);
		if(w == 0 && h == 0) break;
		for(i = 0;i < h;i++)
			for(j = 0;j < w;j++) scanf("%d",&s[i][j]);
		for(i = 0;i < 4;i++) scanf("%d",&c[i]);
		memset(f,-1,sizeof(f));
		que.push(PP(P(0,1),P(0,0)));
		while(que.size()){
			nx = que.top().second.second, ny = que.top().second.first, nc = que.top().first.first,nd = que.top().first.second;
			if(ny == h - 1 && nx == w - 1) break;
			que.pop();
			f[ny][nx][nd] = 0;
			for(j = 0;j < 4;j++){ // 行う操作
				dir = (nd + ctrl[j] + 4) % 4;
				if(ny + dy[dir] >= 0 && ny + dy[dir] < h && nx + dx[dir] >= 0 && nx + dx[dir] < w && f[ny + dy[dir]][nx + dx[dir]][dir])
					que.push(PP(P(s[ny][nx]==j?nc:nc+c[j],dir),P(ny + dy[dir],nx + dx[dir])));
			}
		}
		while(que.size()) que.pop();
		printf("%d\n",nc);
	}
	return 0;
}

Measured memory_bytes: 1188
import java.util.Scanner;

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

    int H, W;
    int times=0;

    while(true){
      H = sc.nextInt();
      W = sc.nextInt();
      if(H==0 && W==0) break;

      for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
          System.out.printf("#");
        }
        System.out.printf("\n");
      }
      System.out.printf("\n");
      //times++;
    }

    /*for (int k=0; k<times; k++) {
      for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
          System.out.printf("#");
        }
        System.out.printf("\n");
      }
    }*/
  }
}



Measured memory_bytes: 65560
#include<iostream>
#include<cstdio>
#include<climits>
#include<algorithm>
#include<set>
#include<vector>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX_E 13

using namespace std;

int n,m;
string e[MAX_E];
string text;
bool dp[5001][(1<<12)];
bool isAble[5001][12];

int main()
{
  int tmp;
  while(tmp = scanf("%d %d",&n,&m),n|m)
    {
      rep(i,n)
	{
	  cin >> e[i];
	}
      text = "";
      rep(i,m)
	{
	  string content;
	  cin >> content;
	  text += content;
	}

      int len = text.size();
     rep(i,len+1)rep(j,(1<<n))dp[i][j] = false;
      int ans = 0;

      rep(i,len)
	{
	  rep(j,n)
	    {
	      isAble[i][j] = false;
	      int e_len = e[j].size();
	      if(i+e_len > text.size())continue;
	      if(text[i] != e[j][0])continue;
	      if(text.substr(i,e_len) == e[j])
		{
		  isAble[i][j] = true;
		  dp[i+e_len][(1<<j)] = true;
		}
	    }
	}

      rep(cur,len+1)
	{
	  rep(state,(1<<n))
	    {
	      if(dp[cur][state] == false)continue;
	      rep(k,n)
		{
		  if((state>>k) & 1)continue;
		  if(!isAble[cur][k])continue;
		  int e_len = e[k].size();
		  if(e[k][0] != text[cur])continue;
		  if(text.size() < cur+e_len)continue;
		  //if(text.substr(cur,e_len) == e[k])
		  //{
		      dp[cur+e_len][state|(1<<k)] = true;
		      //}
		}
	    }
	  if(dp[cur][(1<<n)-1])ans++;

	}
      printf("%d\n",ans);

    }
  return 0;
}

Measured memory_bytes: 21324
#include<stdio.h>
int main()
{
    int a,b,c,i,div;
    scanf("%d%d%d",&a,&b,&c);
    for(i=a;b>=i;i++)
    {
        if(c%i==0)
        {
            div++;
        }
    }
    printf("%d\n",div);
    return 0;
}

Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;
#define M 4005

int ans = 1e9;

bool _ab[M*2+10], _bc[M*2+10], _ac[M*2+10];

void solve(string a, string b, string c) {
    int an = a.size(), bn = b.size(), cn = c.size();
    int ad = max(an, cn);
    int bm = b.size();
    auto ch = [&](char p, char q) {
        if (p != '?' && q != '?' && p != q) return false;
        return true;
    };
    auto ab = _ab + M;
    auto bc = _bc + M;
    auto ac = _ac + M;
    for (int i = -M; i <= M; i++) {
        bool ok = true;
        for (int j = 0; j < an && ok; j++) {
            if (i+j >= bn) break;
            if (i+j < 0) continue;
            if (!ch(a[j], b[i+j])) ok = false;
        }
        ab[i] = ok;
    }
    for (int i = -M; i <= M; i++) {
        bool ok = true;
        for (int j = 0; j < cn && ok; j++) {
            if (i+j >= bn) break;
            if (i+j < 0) continue;
            if (!ch(c[j], b[i+j])) ok = false;
        }
        bc[i] = ok;
    }
    for (int diff = -M; diff <= M; diff++) {
        bool ok = true;
        for (int j = 0; j < an && ok; j++) {
            if (j + diff >= cn) break;
            if (j + diff < 0) continue;
            if (!ch(a[j], c[j+diff])) ok = false;
        }
        ac[diff] = ok;
    }
    for (int al = -M; al <= M; al++) {
        if (!ab[al]) continue;
        for (int cl = -M; cl <= M; cl++) {
            if (!bc[cl]) continue;
            if (abs(cl-al) > M || ac[al-cl]) {
                if (ab[al] && bc[cl]) {
                    ans = min(ans, max({al+an, cl+cn, bn}) - min({al, cl, 0}));
                }
            }
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string a, b, c; cin >> a >> b >> c;
    solve(a, b, c);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
# ruisekiwa by itertools

from itertools import accumulate

N,K = map(int,input().split())
p = list(map(int,input().split()))

b1=[0]+list(accumulate(p))

ans=[]

for i in range(N-K+1):
    ans.append(b1[K+i]-b1[i])
    
print((max(ans)+K)/2)


Measured memory_bytes: 25540
N,D=map(int,input().split())
P=[list(map(int,input().split())) for i in range(N)]

def distance(a,b):
    result=0
    for i in range(D):
        result+=(a[i]-b[i])**2
    result=result**0.5
    return result

ans=0
for i in range(N-1):
    for j in range(i+1,N):
        if distance(P[i],P[j]).is_integer():
            ans+=1

print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;


int main(){
    string N; cin >> N;
    int ans = 0;
    if(N.size() == 1){
        ans = N[0] - '0';
    }
    else{
        if(N[0] == '9'){
            rep(i,N.size()){
                if(N[i] != '9'){
                    ans -= 1;
                    repr(j,i,N.size()) ans += 9;
                    break;
                }
                ans += 9;
            }
        }
        else{
            int ok = true;
            repr(i,1,N.size()){
                if(N[i] != '9') ok = false;
            }
            if(ok){
                ans += N[0] - '0';
                repr(j,1,N.size()) ans += 9;
            }
            else{
                ans += N[0] - '0' - 1;
                repr(j,1,N.size()) ans += 9;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256