akhauriyash/Code-Regression huggingface dataset:
h,w = map(int,input().split())
s = [ input() for _ in range(h) ]

l = [ [0]*w for _ in range(h) ] 
r = [ [0]*w for _ in range(h) ] 
u = [ [0]*w for _ in range(h) ] 
d = [ [0]*w for _ in range(h) ] 

for i in range(h):
    for j in range(w):
        # l
        if s[i][j]=="#":
            l[i][j] = 0
        elif j==0:
            l[i][j] = 1
        else:
            l[i][j] = l[i][j-1] + 1
        # u
        if s[i][j]=="#":
            u[i][j] = 0
        elif i==0:
            u[i][j] = 1
        else:
            u[i][j] = u[i-1][j] + 1

for i in reversed(range(h)):
    for j in reversed(range(w)):
        # r
        if s[i][j]=="#":
            r[i][j] = 0
        elif j==(w-1):
            r[i][j] = 1
        else:
            r[i][j] = r[i][j+1] + 1
        # d
        if s[i][j]=="#":
            d[i][j] = 0
        elif i==(h-1):
            d[i][j] = 1
        else:
            d[i][j] = d[i+1][j] + 1

# print(l)
# print(r)
# print(u)
# print(d)

M = 0
for i in range(h):
    for j in range(w):
        lamp = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
        M = max(M,lamp)

print(M)

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

typedef long long ll;
typedef long double ld;

int res[200005];
int a[200005];
int b[200005];

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
    }
    for(int j=29; j>=0; j--){
        int ima = 0;
        for(int i=1; i<=n; i++) if(a[i] & (1<<j)) ima++;
        if(!ima) continue;
        for(int i=1; i<=n; i++) b[i] = 1;
        for(int i=1; i<=n; i++){
            if(a[i] & (1<<j)) b[i] = 0;
            res[i] |= (b[i]^(ima%2 == 0))*(1<<j);
        }
    }
    for(int i=1; i<=n; i++) cout << res[i] << " ";
    return 0;
}


Measured memory_bytes: 5996
#include<stdio.h>
int main()
{
    int r,c,a;
    scanf("%d%d",&r,&c);
    if(r>=2 && r<=100 && c>=2 && c<=100)
    {


    a=(r-1)*(c-1);
    printf("%d\n",a);
    }
     return 0;
}


Measured memory_bytes: 128
N = int(input())
S = input()
lcnt=[]

def div(x):
    s1,s2="",""
    for i in range(x):
        s1+=S[i]
    for i in range(N-x):
        s2+=S[x+i]
    return s1,s2

def count(s1,s2):
    cnt=0
    s1=list(set(s1))
    for i in range(len(s1)):
        if s1[i] in s2:
            cnt+=1
    return cnt

for i in range(1,N):
    s1,s2=div(i)
    cnt=count(s1,s2)
    lcnt.append(cnt)
    
print(max(lcnt))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int x,y;
    cin >> x >> y;
    ll sm = 0;
    switch(x){
        case 1:
            sm += 300000;
            break;
        case 2:
            sm += 200000;
            break;
        case 3:
            sm += 100000;
            break;
    }
    switch(y){
        case 1:
            sm += 300000;
            break;
        case 2:
            sm += 200000;
            break;
        case 3:
            sm += 100000;
            break;
    }
    if (x == 1 && y == 1){
        sm += 400000;
    }
    cout << sm << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
x = [0] * n

for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] > h[b - 1]:
        if x[a - 1] != -1:
            x[a - 1] = 1
        x[b - 1] = -1
    elif h[a - 1] < h[b - 1]:
        x[a - 1] = -1
        if x[b - 1] != -1:
            x[b - 1] = 1
    else:
        x[a - 1] = -1
        x[b - 1] = -1

print(n - x.count(-1))

Measured memory_bytes: 20020
import java.io.PrintWriter;
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int x = sc.nextInt();
        System.out.println(x == 0 ? 1 : 0);

        // out.println("Hello World");
        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 35716
n,m,k = map(int,input().split())

base = 998244353


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353 #出力の制限
N = n
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )



ans = 0
rbase = 1
for i in range(n-1-k):
    rbase *= (m-1)
    rbase %= mod

temp = m*rbase
temp %= mod
for i in range(k+1):
    hoge = temp*cmb(n-1,k-i,mod)
    hoge %= mod
    ans += hoge
    temp *= (m-1)
    temp %= mod

print(ans%mod)

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

a_max = 0
sum = 0
for i in range(n):
  sum += A[i]
  if sum > k:
    sum -= A[i]
    break
  a_max += 1
  
ans = a_max
kotae =ans
j = 0


for i in range(m):
  sum += B[i]
  ans += 1
  while sum > k and j < a_max:
    sum -= A[a_max-1-j]
    ans -= 1
    j += 1
  if sum > k:
    print(kotae)
    exit()
  kotae = max(kotae, ans)

  
print(kotae)
  
    
    
  

Measured memory_bytes: 40624
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

ll dp[200005], ma[200005], x[100005], v[100005];
int n;
ll c;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> c;
	FOR(i, n) {
		cin >> x[i] >> v[i];
		dp[i] = (i == 0 ? v[i] - x[i] : dp[i-1] + v[i] - (x[i] - x[i-1]));
		ma[i] = (i == 0 ? max(dp[i], 0LL) : max(dp[i], ma[i-1]));
	}
	FOR(i, n) {
		dp[n+i] = (i == 0 ? v[n-1-i] - (c-x[n-1-i]) : dp[n+i-1] + v[n-1-i] - (x[n-i] - x[n-1-i]));
		ma[n+i] = (i == 0 ? max(dp[n+i], 0LL) : max(dp[n+i], ma[n+i-1]));
	}
	ll ans = 0LL;
	FOR(i, n) {
		ans = (i==n-1 ? max(ans, dp[i]) : max({ans, dp[i], dp[i]+ma[n-1+(n-i-1)]-x[i]}));
		// cout << ans << endl;
	}
	// cout << ans << endl;
	FOR(i, n) {
		ans = (i==n-1 ? max(ans, dp[n+i]) : max({ans, dp[n+i], dp[n+i]+ma[n-1-i-1]-(c-x[n-i-1])}));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
import java.util.*;

public class Main{
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m) == 0) break;
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i = 1; i <= n; i++){
				list.add(i);
			}
			
			int ind = -1;
			while(true){
				ind = (ind + m) % list.size();
				list.remove(ind);
				ind--;
				if(list.size() == 1){
					System.out.println(list.get(0));
					break;
				}
			}
		}
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 12000
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
void solve(){
	ll h1 , m1 , h2 , m2 , k;
	cin>> h1 >> m1 >> h2 >> m2 >> k ;
	ll time ;
	if(m1>m2){
		h2--;m2+=60;
		time=(h2-h1)*60 + (m2 -m1);
	}
	else{
		time=(h2-h1)*60+(m2-m1);
	}
	cout<<max(time-k,0LL)<<endl;
}
int main(){
	//mahakal(),fast;
	ll t=1 ;
	// cin>> t;
	while(t--)solve();

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
#define all(a)  (a).begin(), (a).end()
#define rall(a) (a).rbegin(),(a).rend()
#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 PB push_back
#define MP make_pair
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main(){
    int n,sum = 0; cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(rall(p));
    rep(i,n){
        if(i) sum += p[i];
        else sum += p[i]/2;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
ss = list(map(int, list(input())))

#先頭1からか0からのパターンで考える
next=1
count1=0
for s in ss:
    if s != next:
        count1+=1
    next = (next+1)%2

next=0
count2=0
for s in ss:
    if s != next:
        count2+=1
    next = (next+1)%2

print(min(count1,count2))

Measured memory_bytes: 4652
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
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;
}
int main(){
    ll n;cin >> n;
    vector<double> x(n),y(n);
    rep(i,n){
        cin >> x[i] >>y[i];
    }
    double sum=0;
    rep(i,n){
        repl(j,i+1,n){
            sum+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        }
    }
    CST(7);
    sum*=2;
    sum/=n;
    cout << sum <<endl;
}


Measured memory_bytes: 256
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O2")
#pragma GCC optimization ("unroll-loops")

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> v;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = i; j < n; j++) {
      sum += a[j]; 
      v.push_back(sum);
    }
  }
  sort(v.rbegin(), v.rend());
  int ans = 0;
  for (int b = 61; b >= 0; b--) {
    if ((v[0] & (int)pow(2, b)) == 0) {
      continue;
    }
    if ((v[k - 1] & (int)pow(2, b)) == 0) {
      int nt = (int) pow(2, 62) - 1 - (int) pow(2, b);
      for (int i = 0; i < sz(v); i++) {
        v[i] &= nt;
      }
      sort(v.rbegin(), v.rend());
    } else {
      ans += (int) pow(2, b);
    }
  }
  cout << ans << "\n";
}



Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
int gcds(int a,int b){
	int tmp;
	while(b!=0){
		tmp = a%b;
		a = b;
		b = tmp;
	}
	return a;
}
int main(void){
	int x;
	scanf("%d",&x);
	int xx = gcds(x,360);
	printf("%d",360/xx);
	return 0;
}


Measured memory_bytes: 3760
n, k = map(int, raw_input().split())
a = [0] + map(int, raw_input().split())
for i in xrange(1, len(a)):
    a[i] += a[i - 1]
print (k + max(a[i] - a[i - k] for i in xrange(k, len(a)))) / 2.0


Measured memory_bytes: 49968
#include<iostream>
    #include<string>
    using namespace std;
     
    int main() {
    	char A, B, C;
    	char D;
    	while (1) {
    		cin >> A >>D>> B;
    		if (A == 'A') {
    			C = B;
    		}
    		else if (B == 'A') {
    			C = A;
    		}
    		if (C == 'B' || C == 'C') {
    			break;
    		}
    	}
    	while (cin>>A>>D>>B) {
    		if (A == C) {
    			C = B;
    		}
    		else if (B == C) {
    			C = A;
    		}
    	}
    	cout << C << endl;
    	return 0;
    }

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int a[9],ans,used[10];

void dfs(int p){
  if(p==9){
    if(a[0]+a[2]+a[5]-a[8]+10*(a[1]+a[4]-a[7])+100*(a[3]-a[6])==0)ans++;
    return;
  }
  if(a[p]!=-1){dfs(p+1);return;}
  for(int i=1;i<=9;i++){
    if(used[i])continue;
    used[i]=1,a[p]=i;
    dfs(p+1);
    used[i]=0,a[p]=-1;
  }
}

int main(){
  for(int i=0;i<9;i++){
    cin>>a[i];
    if(a[i]!=-1)used[a[i]]=1;
  }
  dfs(0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3104
from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n, p = map(int, input().split())
p = Counter(prime_factorize(p))
ans = 1
for key, val in p.items():
    if val >= n:
        ans *= pow(key, int(val//n))
print(ans)

Measured memory_bytes: 9360
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M,K;

ll dp[4040][4040];
ll mo=1000000007;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>K;
	int L=(N+M-1)/(K-1);
	
	dp[0][0]=1;
	FOR(i,L) {
		FOR(j,M+1) {
			for(x=0; x<K && j+x<=M; x++) (dp[i+1][j+x] += dp[i][j])%=mo;
		}
	}
	
	ll ret=0;
	while(M>0) ret+=dp[(N+M-1)/(K-1)][M], M-=K-1;
	cout<<ret%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

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

    string test[] = {"AC", "WA", "TLE", "RE"};

    int ans[4] = {0};

    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < 4; j++)
        {
            if(test[j] == s)
            {
                ans[j]++;
                break;
            }
        }
    }
    
    for (int i = 0; i < 4; i++)
    {
        cout << test[i] << " x " << ans[i] << endl;
    }
    
}


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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353
#define inf LLONG_MAX

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

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

    ll test=1;
    //cin>>test;
    while(test--)
    {
        ld a,b;
        
        cin>>a>>b;
        
        ld ans=a*b;

        cout<<setprecision(18);
        
        cout<<floor(ans);
    }
}













Measured memory_bytes: 3812
n =int(input())
w = list(map(int,input().split()))
a='APPROVED'
for i in range(n):
  if w[i]%2!=0:
    continue
  else:
    if w[i]%3==0 or w[i]%5==0:
      continue
    else:
      a='DENIED'
      break
print(a)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define FI first
#define SE second
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define PQ priority_queue<int>
#define PGQ priority_queue<int,vector<int>,greater<int> >
#define VE vector<int>
#define VP vector<PA>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int MOD=1e9+7;
const int INF=1e9+7;
const double PI=3.141592653589793238462643383279;
//
struct edge {int to,cap,rev;};
vector<edge> G[100000];
int level[100000];
int iter[100000];
//
int s,t;
//
void add_edge(int from,int to,int cap){
  G[from].PB((edge){to,cap,(int)G[to].size()});
  G[to].PB((edge){from,0,(int)G[from].size()-1});
}
//
void BFS(int S){
  memset(level,-1,sizeof(level));
  queue<int> que;
  level[S]=0;
  que.push(S);
  while(!que.empty()){
    int v=que.front();
    que.pop();
    FOR(i,0,(int)G[v].size()){
      edge &E=G[v][i];
      if(E.cap>0&&level[E.to]<0){
        level[E.to]=level[v]+1;
        que.push(E.to);
      }
    }
  }
}
//
int DFS(int V,int T,int F){
  if(V==T){
    return F;
  }
  for(int &i=iter[V];i<(int)G[V].size();i++){
    edge &E=G[V][i];
    if(E.cap>0&&level[V]<level[E.to]){
      int D=DFS(E.to,T,min(F,E.cap));
      if(D>0){
        E.cap-=D;
        G[E.to][E.rev].cap+=D;
        return D;
      }
    }
  }
  return 0;
}
int MAX_FLOW(int SS,int TT){
  int flow=0;
  while(1){
    BFS(SS);
    if(level[TT]<0){
      return flow;
    }
    memset(iter,0,sizeof(iter));
    int F;
    while((F=DFS(SS,TT,INF))>0){
      flow+=F;
    }
  }
}
int main(){
  int H,W;
  char M[100][100];
  cin>>H>>W;
  FOR(i,0,H){
    FOR(j,0,W){
      cin>>M[i][j];
    }
  }
  FOR(i,0,H){
    FOR(j,0,W){
      int ID=i*W+j;
      if(M[i][j]=='o'){
        add_edge(ID*2,ID*2+1,1);
      }
      add_edge(ID*2+1,H*W*2+i,INF);
      add_edge(H*W*2+i,ID*2,INF);
      add_edge(ID*2+1,H*W*2+H+j,INF);
      add_edge(H*W*2+H+j,ID*2,INF);
      if(M[i][j]=='S'){
        s=ID*2+1;
      }else if(M[i][j]=='T'){
        t=ID*2;
      }
    }
  }
  int ans=MAX_FLOW(s,t);
  if(ans>=1e5){
    cout<<-1<<endl;
  }else{
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 5248
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

int main(void) {
	ll W, H, x, y;
	int flag = 0;
	long double area1,w1,h1, tmp;
	scanf("%lld %lld %lld %lld", &W, &H, &x, &y);
	area1 = (long double)(W * H) / 2.0;
	if (x + x == W && y+y == H) {
		flag = 1;
	}
	printf("%Lf %d", area1, flag);



	return 0;
}

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

int main()
{
    string s;
    int k;
    cin >> k >> s;
    if(s.length() <= k){cout << s;}
    else
    {
        string ans = s.substr(0,k) + "...";
        cout << ans;
    }

    return 0;
}

Measured memory_bytes: 3636
n = int(input())
A = [int(i) for i in input().split()]

q = int(input())
m = [int(i) for i in input().split()]

def dfs(idx, s, target):
    if s == target:
        return 1
        
    if s > target or idx == n:
        return 0
    if s + sum(A[idx:]) < target:
        return 0
    
    return dfs(idx+1, s, target) or dfs(idx+1, s+A[idx], target)
    
for target in m:
    ans = "yes" if dfs(0, 0, target) else "no"
    print(ans)


Measured memory_bytes: 5628
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int r, g;
  cin >> r >> g;
  cout << 2 * g - r << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void) {
  char input[100001];
  scanf("%s", input);
  /*printf("%s\n", input );*/
  int length = strlen(input);
  /*printf("%d\n", length );*/
  int i; /*index*/
  int ans[length];
  int count = 0;
  if (input[0] == '0') {
    for (i = 1;i < length;++i) {
      if (i % 2 == 0 && input[i] == '1') {
          ++count;
      } else if (i % 2 == 1 && input[i] == '0'){
          ++count;
      }
    }
  }

  if (input[0] == '1') {
    for (i = 1;i < length;++i) {
      if (i % 2 == 0 && input[i] == '0') {
          ++count;
      } else if (i % 2 == 1 && input[i] == '1') {
          ++count;
      }
    }
  }
  printf("%d\n",count );
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// using Graph = vector<vector<int>>;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int N;
  cin >> N;
  vector<vector<int>> G(N);
  REP(i, N - 1) {
    int a, b;
    cin >> a >> b;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
  }
  vector<int> c(N);
  REP(i, N) {
    cin >> c[i];
  }
  sort(c.begin(), c.end(),greater<int>());

  vector<int> seen(N, false);
  queue<int> todo;
  vector<int> ans(N);
  
  int cursol = 0;
  seen[0] = true;
  todo.push(0);
  while (!todo.empty()) {
    int here = todo.front();
    todo.pop();
    // cout << here << ' ' << c[cursol] << endl;
    ans[here] = c[cursol];
    cursol++;

    for (int node: G[here]) {
      if (seen[node] == false) {
        todo.push(node);
        seen[node] = true;
      }
    }
  }

  int sum = 0;
  for (int i = 1; i < N; i++) sum += c[i];
  cout << sum << endl;
  REP(i, N) {
    if (i != N - 1) cout << ans[i] << ' ';
    else cout << ans[i] << endl; 
  }
  return 0;
}

Measured memory_bytes: 1024
#!/anaconda3/bin/python
n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
money=0
ab.sort(key=lambda tup:tup[0])
for a,b in ab:
    if m-b>0:
        money+=a*b
        m-=b        
    else:
        money+=a*m
        break
print(money)



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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int bio[1000005];

int main() {
	int k;
	scanf("%d", &k);
	int pos = 0;
	int cnt = 0;
	while (1) {
		cnt++;
		pos = (pos*10+7) % k;
		if (bio[pos]) {
			printf("-1\n");
			return 0;
		}
		if (pos == 0) {
			printf("%d\n", cnt);
			return 0;
		}
		bio[pos] = 1;
	}
	return 0;
}

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

int main() {

	int n; cin >> n;
	const int p = 26;
	vector<vector<int>> num(n, vector<int>(p, 0));
	for (int i = 0; i < n; i++) {
		string s; cin >> s;
		for (int j = 0; j < s.size(); j++) {
			num[i][s[j] - 'a']++;
		}
	}
	vector<int> minCnt(p, 0);
	for (int j = 0; j < p; j++) {
		int tmp = 2147483647;
		for (int i = 0; i < n; i++) {
			tmp = min(tmp, num[i][j]);
		}
		minCnt[j] = tmp;
	}
	string ans = "";
	for (int i = 0; i < p; i++) {
		int cnt = minCnt[i];
		while (cnt--) {
			ans += 'a' + i;
		}
	}	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3584
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

vector<vector<pair<int,int> > > g;    // to, pt

void dfs0( int curr, const vector<vector<int> >& gg, vector<int>& vis )
{
    if(vis[curr]) return;
    vis[curr]=1;

    int siz=gg[curr].size();
    int i;
    for(i=0; i<siz; i++) {
        int next=gg[curr][i];
        if( vis[next] ) continue;
        dfs0( next, gg, vis );
    }

    return;
}

int main()
{
    int n,m,p;
    scanf("%d%d%d", &n, &m, &p);

    g.resize(n);

    vector<vector<int> > g0(n);   // to
    vector<vector<int> > g1(n);   // from
    int i;
    for(i=0; i<m; i++) {
        int a,b,c;
        scanf("%d%d%d", &a, &b, &c);
        a--; b--; c-=p;
        g[a].push_back(make_pair(b,c));
        g0[a].push_back(b);
        g1[b].push_back(a);
    }

    vector<int> vis0(n), vis1(n);
    dfs0( 0, g0, vis0 );
    dfs0( n-1, g1, vis1 );

    vector<ll> pt(n, -INF);
    pt[0]=0;
    int j;
    int numloop=0;
    while(1) {
        int cnt=0;
        for(i=0; i<n; i++) {
            if(vis0[i] && vis1[i] && pt[i]>-INF) {
                for(j=0; j<(int)g[i].size(); j++) {
                    int next=g[i][j].first;
                    int add=g[i][j].second;
                    if(pt[next]>=pt[i]+add) {
                        continue;
                    }
                    else {
                        pt[next]=pt[i]+add;
                        cnt++;
                    }
                }
            }
        }
        if(cnt==0) break;
        else numloop++;

        if(numloop>n) {
            printf("-1\n");
            return 0;
        }
    }
    printf("%lld\n", MAX(0,pt[n-1]));

    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if(a <= b)
    cout << a << endl;
  else
    cout << a - 1 << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

//PrimeFactorize .
func PrimeFactorize(n int) (ans []int) {
	for n%2 == 0 {
		ans = append(ans, 2)
		n /= 2
	}

	for i := 3; i*i <= n; i += 2 {
		for n%i == 0 {
			ans = append(ans, i)
			n /= i
		}
	}

	if n > 2 {
		ans = append(ans, n)
	}

	return ans
}

func main() {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	ans := PrimeFactorize(n)
	//fmt.Println(ans)
	fmt.Printf("%d:", n)
	for _, s := range ans {
		fmt.Printf(" %d", s)
	}
	fmt.Println()
}



Measured memory_bytes: 1100
import java.util.Scanner;

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

		int N = sc.nextInt();
		int H = sc.nextInt();
		int W = sc.nextInt();

		int result = ((N-H)+1)*((N-W)+1);

		System.out.println(result);
	}
}

Measured memory_bytes: 21716
from collections import deque
import sys


def read_int():
    line = sys.stdin.readline().rstrip('\n')
    return int(line)

def read_int_list():
    line = sys.stdin.readline().rstrip('\n')
    return [int(e) for e in line.split(' ')]

N = read_int()
A = read_int_list()

A.sort(key=lambda i:-i) # descending                                                                                                                          

q = deque()

ans = 0
for i in A:
    if q:
        ans += q.popleft()
        q.append(i)
    q.append(i)
print(ans)



Measured memory_bytes: 34420
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	np := 0
	for i := n - 1; i > 0; i-- {
		for j := 0; j < i; j++ {
			np++
		}
	}
	mp := 0
	for i := m - 1; i > 0; i-- {
		for j := 0; j < i; j++ {
			mp++
		}
	}
	fmt.Println(np + mp)
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;

int main(){
  ll H,W,h,w;
  cin >> H >> W;
  cin >> h >> w;
  cout << (H-h)*(W-w);
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define EPS 1e-10
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


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

    vector<ll> a;
    rep(i, 3){
        ll inp; cin >> inp;
        a.pb(inp);
    }
    
    rmsame(a);
    if(a.size() == 2) cout << "Yes" << endl;
    else cout << "No" << endl;

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


Measured memory_bytes: 888
#include <iostream>
#include <cmath>
#include <deque>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)

struct cur{
	ll val;
	int index;
	cur(){
		this->val = 0;
		this->index = 0;
	}
	cur(ll va,int inde){
		this->val = va;
		this->index = inde;
	}
};

typedef struct p{
	ll prime;
	int count;
    p(ll prim,int coun){
		this->prime = prim;
		this->count = coun;
    }
	p(){
		this->prime = 0;
		this->count = 0;
	}
   
}p_t;

int main(){
	ll x,n,m;
	cin >> x;
	ll i = 2;int count1=0;
  	p_t a[100000],b[100000];
	n=x;
	while(i<=sqrt(n) && n!=1){
		int number=0;
		if(n%i==0){
			while(n%i==0){
				n /= i;
				number++;
			}
			a[count1] = p(i,number);
			count1++;
            //cout << i << " " << number << endl;
          	//cout << endl;
		}
		i++;
	}
	if(n!=1){
      a[count1] = p(n,1);
      count1++;
      //cout << n << " " << 1 << endl;
      //cout << endl;
    }
	i=2;int count2=0;m=x-1;
	while(i<=sqrt(m)&&m!=1){
		int number=0;
		if(m%i==0){
			while(m%i==0){
				m /= i;
				number++;
			}
			b[count2] = p(i,number);
			count2++;
            //cout << i << " " << number << endl;
          	//cout << endl;
		}
		i++;
	}
	if(m!=1){
      b[count2] = p(m,1);
      count2++;
      //cout << m << " " << 1 << endl;
      //cout << endl;
    }
    ll ans=0;
	deque<cur> dfs;
	dfs.push_back(cur(1,0));
  	//return 0;
    //cout << count1 << endl;
	while(!dfs.empty()){
		if(dfs.back().index < count1){
			ll cur_val = dfs.back().val;
			int cur_index = dfs.back().index;
			dfs.pop_back();
			ll r = 1;
			dfs.push_back(cur(cur_val,cur_index+1));
			for(int j = 0;j<a[cur_index].count;j++){
				cur_val*=a[cur_index].prime;
				dfs.push_back(cur(cur_val,cur_index+1));
			}
		}else{
          	//cout << 1 << endl;
			ll value = dfs.back().val;
          	if(value == 1){
				dfs.pop_back();
                continue;
            }
			ll o = x;
			while(o%value==0)o/=value;
			if(o%value==1)ans++;
			dfs.pop_back();
		}
      	/*for(int k=0;k<dfs.size();k++){
        	cout << dfs[k].val << " " << dfs[k].index << endl;
        }
      	cout << endl;*/
	}
  	
  //return 0;
	dfs.push_back(cur(1,0));
	while(!dfs.empty()){
		if(dfs.back().index < count2){
			ll cur_val = dfs.back().val;
			int cur_index = dfs.back().index;
			dfs.pop_back();
			ll r = 1;
			dfs.push_back(cur(cur_val,cur_index+1));
			for(int j = 0;j<b[cur_index].count;j++){
				cur_val*=b[cur_index].prime;
				dfs.push_back(cur(cur_val,cur_index+1));
			}
		}else{
			ll value = dfs.back().val;
            if(value == 1){
              	dfs.pop_back();
              	continue;
            }
			ll o = x;
			if(o%value==1)ans++;
			dfs.pop_back();
		}
      /*for(int k=0;k<dfs.size();k++){
        	cout << dfs[k].val << " " << dfs[k].index << endl;
        }
      	cout << endl;*/
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    const int m = 1000000007;
    int n;
    cin>>n;
    vector<int> nu(n);
    int ct=0;
    for(int i=0;i<n;i++){ 
        cin>>nu[i];
    }
    
    
    int ans=0;
    int x=0;
    for(int i=0;i<n;i++){
        ans = (ans+(long long)nu[i]*x)%m;
        x = (x+nu[i])%m;
    }
    
    cout<<ans<<endl;
    
}


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

int main()
{
    ll a;
    double b;
    cin >> a >> b;
    ll b100 = b * 100 + 0.001;
    cout << a * b100 / 100 << endl;
}

Measured memory_bytes: 3672
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.meta;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(string S, string T) {
    int ans;
    foreach (s, t; zip(S, T))
        if (s == t)
            ans++;
    return ans;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    string S;
    S = input.front.to!string;
    input.popFront;

    string T;
    T = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(S, T);
    else
        solve(S, T).writeln;
}


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

int main()
{
  int N;
  long long int t, a;
  cin >> N;
  t = 1;
  a = 1;
  for(int i = 0; i < N; i++){
    long long int T, A;
    cin >> T >> A;
    long long int x, y;
    if(a % A == 0) x = a/A;
    else x = a/A+1;
    if(t % T == 0) y = t/T;
    else y = t/T+1;
    long long int n = max(x,y);
    t = T*n;
    a = A*n;
  }
  cout << t+a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

   if(d == 25){cout << "Christmas" << endl;}
   else if(d == 24){cout << "Christmas Eve" << endl;}
   else if(d == 23){cout << "Christmas Eve Eve" << endl;}
   else if(d == 22){cout << "Christmas Eve Eve Eve" << endl;}

   return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,j,count=0,k;
    scanf("%d",&k);
    for(i=1;i<=k;i++)
    {
        for(j=1;j<=k;j++)
        {
            if(j%2==0 && i%2!=0)
            {
                count++;
            }
        }
    }
    printf("%d\n",count);
    
    return 0;
}

Measured memory_bytes: 128
def q2():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]

    ans = 0
    pre_i = N
    for i in range(N):
        ans += B[A[i]-1]
        if A[i] == pre_i + 1:
            ans += C[A[i]-2]
        pre_i = A[i]
    print(ans)


if __name__ == '__main__':
    q2()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
	long long int a,b;
	cin>>a>>b;
	long long int ans=0;
	for (long long int i=b;i<=a+1;i++)
		{
			ans+=(a*i-(i*(i-1))+1)%1000000007;
			ans%=1000000007;
		}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace io{
	const int l=1<<20;
	char buf[l],*s,*t;
	inline char gc(){
		if(s==t){
			t=(s=buf)+fread(buf,1,l,stdin);
			return s==t?EOF:*s++;
		}
		return *s++;
	}
	char c;
	template<class IT>inline void gi(IT &x){
		x=0;c=gc();while(c<'0'||c>'9')c=gc();
		while('0'<=c&&c<='9'){x=(x<<1)+(x<<3)+(c^'0');c=gc();}
	}
};
using io::gi;
struct qwq{
	int a,b;
	inline bool operator<(const qwq &x)const{
		return a<x.a;
	}
};
template<class IT>inline void cmin(IT &a,IT b){if(b<a)a=b;}
template<class IT>inline void cmax(IT &a,IT b){if(a<b)a=b;}
const ll p=1000000007ll,inf=1000000000000000000ll;
const int N=2005;
int a[N];
int main(){
	int n,k,i,j;ll kk,ans=0ll;
	scanf("%d%d",&n,&k);kk=((k*((ll)(k-1)))%p)*500000004ll%p;
	for(i=1;i<=n;++i)scanf("%d",&a[i]);
//	printf("k=%d kk=%lld\n",k,kk);
	for(i=1;i<=n;++i)for(j=n;j>i;--j)if(a[i]>a[j])ans+=k ;
	for(i=1;i<=n;++i)for(j=n;j  ;--j)if(a[i]>a[j])ans+=kk;
	printf("%lld",ans%p);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
long long num;
int main(){
    cin >> num;
    long long t = 1;
    for(long long i = 1; i * i <= num; i ++){
        if(num % i == 0) t = max(t, i);
    }
    cout << t + num / t -2 << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N = int(input())
S = input()
list = []

for i in S : 
    if ord(i)+N > 90 : 
        list.append(chr(ord(i)+N-26))
    else : 
        list.append(chr(ord(i)+N))

string = ''.join(list)

print(string)

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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

int H[100005];
vector<int> elist[100005];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N, M; gi(N), gi(M);
	int a = 0;
	rep1(i, N) gi(H[i]);
	while(M--) {
		int u, v; gi(u), gi(v);
		elist[u].pb(v); elist[v].pb(u);
	}
	rep1(i, N) {
		bool g = 1;
		for(int& k:elist[i]) if(H[k] >= H[i]) { g = 0; break; }
		a += g;
	}
	print(a);
}


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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N;
    double A[110];
    cin >> N;
    REP(i,N){
        cin >> A[i];
    }
    double ans;
    REP(i,N) ans += 1 / A[i];
    ans = 1 / ans;
    
    cout << fixed << setprecision(6);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main() 
{
	ll N;
	cin >> N;
	cout << N * (N - 1) / 2 << endl;
}

Measured memory_bytes: 256
n=int(input())
a=[int(_) for _ in input().split()]
b=[int(_) for _ in input().split()]
c=0
for i in range(n):
    if a[i] <= b[i]:
        c += a[i]
        if a[i+1] <= b[i]-a[i]:
            c += a[i+1]
            a[i+1] = 0
        else:
            c += b[i]-a[i]
            a[i+1] -= b[i]-a[i]
    else:
        c += b[i]
print(c)


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vdbl;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int> > vvint;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
typedef priority_queue<int, vector<int>, greater<int> > spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll> > spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int> > bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll> > bpqll;        //大きい順に取り出し

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, b) for (int(i) = a; (i) < (int)b; i++)
#define IREP(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const double PI = M_PI;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes()
{
    cout << "Yes" << endl;
}
void no()
{
    cout << "No" << endl;
}
//-----------------------------------------
int n ;
vll a ;

bool is_good(int idx){
    ll m = a[idx] ;
    bool res = true ;
    REP(i,n){
        if(i==idx){
            continue ;
        }

        if(a[i]<=2*m){
            m += a[i] ; 
        }
        else{
            res = false ;
        }
    }
    return res ;
}

int binary_search(){
    int left = -1 ;
    int right = a.size() ;

    while(right-left>1){
        int mid = (left + right) / 2 ;
        if(is_good(mid)){
            right = mid ;
        }
        else{
            left = mid ;
        }
    }
    // left は条件を満たさない最大の値、right は条件を満たす最小の値になっている 
    return right;
}

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n ;
    REP(i,n){
        int m ;
        cin >> m ;
        a.PB(m) ;
    }
    sort(ALL(a)) ;

    int k = BS() ;

    cout << n - k <<endl ;  

    

    return 0;
}


Measured memory_bytes: 1400
n = gets.chomp.to_i
a = Array.new(101)
a[0] = false
a[1] = false
a[2] = false
a[3] = false
a[4] = true
a[5] = false
a[6] = false
a[7] = true
(8 .. 100).each do |i|
  a[i] = a[i - 4] || a[i - 7]
end
puts(a[n] ? "Yes" : "No")

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

bool test = true;
int tt = 1;
#define ll long long
#define all(x) x.begin(), x.end()
#define sz(s) (int)(s.size())

struct fio
{
    fio()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(10);
    }
} fio;

int main() 
{
    int x;
    cin >> x;
    cout << 1 - x << "\n";
}

Measured memory_bytes: 3620
n, m = map(int, input().split())
keys = []

for _ in range(m):
    cost, types = map(int, input().split())
    to_open = list(map(int, input().split()))
    keys.append([cost, to_open])

DP = [10**9] * (2**n)
DP[0] = 0

for cost, (to_open) in keys:
    openable = 0
    for open in to_open:
        openable |= 1 << (open-1)

    for opened in range(2 ** n):
        pattern = opened | openable
        DP[pattern] = min(DP[pattern], DP[opened] + cost)

full_open = 2**n - 1
ans = DP[full_open]

if ans == 10 ** 9:
    ans = -1

print(ans)


Measured memory_bytes: 3372
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.solve();
        m.show();
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    int M;
    int[] p;
    int[] AC;
    int[] WA;
    int countAC = 0;;
    int countWA = 0;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
        this.M = sc.nextInt();
        p = new int[M];
        AC = new int[N];
        WA = new int[N];
    }
    
    //解答処理
    private void solve() {
        
    	for (int i=0 ;i<M; i++) {
    		p[i] = sc.nextInt();
    		String S = sc.next();
    		if (S.equals("WA")) {
    			WA[p[i]-1]++;
    		} else {
    			//まだその問題でACが出てないとき、ペナルティ分を加算
    			if (AC[p[i]-1] == 0) {
    				countWA += WA[p[i]-1];
    			}
    			AC[p[i]-1] = 1;
    		}
    	}
    	
    	for (int i=0; i<N; i++) {
    		countAC += AC[i];
    	}
        
    }
    
    //出力
    public void show() {
        System.out.print(countAC);
        System.out.print(" ");
        System.out.print(countWA);
    }

}


Measured memory_bytes: 61328