akhauriyash/Code-Regression huggingface dataset:
n, m, l = map(int, raw_input().split(" "))
a = [[0 for i in range(m)] for j in range(n)]
b = [[0 for k in range(l)] for i in range(m)]
for j in range(n):
    a[j] = map(int, raw_input().split(" "))
for i in range(m):
    b[i] = map(int, raw_input().split(" "))

c = [[0 for k in range(l)] for j in range(n)]
for j in range(n):
    for k in range(l):
        for i in range(m):
            c[j][k] += a[j][i] * b[i][k]
for j in range(n):
    print " ".join(map(str, (c[j])))

Measured memory_bytes: 7196
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>


#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b), i++)
#define NL << endl

using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {

	ull n, m, d;

	cin >> n >> m >> d;

	if (d == 0) {
		cout << (m - 1) / (double)n NL;
	} else {
		printf("%f\n", (n - d) * (m - 1) * 2 / (double)(n * n));
		//cout << (n - d) / (double)n * (m - 1) * 2.0 / n NL;
	}

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().split()]

fn = 0
for a in A :
    if a < 0 :
        fn += 1

B = [abs(a) for a in A]
B.sort()
if fn%2 == 0 :
    print(sum(B))
else :
    print(sum(B) - B[0]*2)


Measured memory_bytes: 60960
#include <bits/stdc++.h>
using i64 = long long;

auto calc(const std::string &s) {
    std::vector<int> a(s.size() + 1);
    a[0] = -1;
    for (int i = 0, j = -1; i < s.size(); i++) {
        while (j >= 0 && s[i] != s[j]) j = a[j];
        j++;
        a[i + 1] = s[i + 1] == s[j] ? a[j] : j;
    }
    return a;
}

auto find_all(const std::string &s, const std::string &t, const std::vector<int> &a, int ss = 0, int ts = 0) {
    std::deque<int> ret;
    for (int i = ss, j = ts; i < s.size(); i++) {
        while (j >= 0 && s[i] != t[j]) j = a[j];
        if (++j == t.size()) {
            ret.push_back(i - t.size() + 1);
            j = a[j];
        }
    }

    return ret;
}

int main() {
    std::string s, t;
    std::cin >> s >> t;
    int n = s.size(), m = t.size();
    std::vector<int> e(s.size());
    auto ss = s;
    while (ss.size() < s.size() + t.size()) ss += s;
    auto a = calc(t);

    auto qq = find_all(ss, t, a);
    for (auto el : qq) e[el % n] = 1;

    int ret = 0;
    std::vector<int> p(n);
    for (int i = 0; i < n; i++) {
        if (e[i] < 0 || p[i]) continue;
        int j = i, tmp = 0;
        while (!p[j] && e[j]) {
            p[j] = 1;
            j = (j + m) % n;
            if (j == i) {
                std::cout << -1 << std::endl;
                return 0;
            }
            tmp++;
        }
        p[i] = tmp + p[j];
        ret = std::max(ret, p[i]);
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 12724
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, f;
bitset<5005> water;
bitset<5005> suger;
signed main() {
	cin >> a >> b >> c >> d >> e >> f;
	water.set(0);
	suger.set(0);
	for (int i = 0; i < f; ++i) {
		if (water[i]) {
			water.set(i + a);
			water.set(i + b);
		}
		if (suger[i]) {
			suger.set(i + c);
			suger.set(i + d);
		}
	}
	int mw = a * 100;
	int ms = 0;
	double ans = 0;
	for (int i = 1; i * 100 <= f; ++i) 
		if (water[i]) {
			int lim = min(i * e, f - i * 100);
			int tmp = 0;
			for (int j = lim; j; --j)
				if (suger[j]) {
					tmp = j;
					break;
				}
			double now = 1.0 * tmp / (tmp + i * 100);
			if (ans < now) {
				ans = now;
				mw = i * 100;
				ms = tmp;
			}
		}
	int tot = mw + ms;
	cout << tot << " " << ms << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,p,m=0,ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p;
        ans+=p;
        m=max(m,p);
    }
    ans-=m/2;
    cout<<ans;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<ll, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

int main(){
    fastIO;
    string t;
    cin >> t;
    int c0=0,c1=0;
    int w0=0,w1=0;
    for(char p : t){
        if(p == 'N') c0 ++ ;
        else if(p == 'S') c1 ++ ;
        else if(p == 'W') w0 ++ ;
        else w1 ++ ;
    }
    bool ok1,ok2;
    if((c0 == 0 && c1 == 0) || (c0 > 0 && c1 > 0)){
        ok1 = true;
    }
    else{
        ok1 = false;
    }
    if((w0 == 0 && w1 == 0) || (w0 > 0 && w1 > 0)){
        ok2 = true;
    }
    else{
        ok2 = false;
    }
    if(ok1 && ok2){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
using System;
 
namespace StandardInput
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string [] a=Console.ReadLine().Split(" ");
            string [] b=a[1].Split(".");
            Console.Write(long.Parse(a[0])*int.Parse(b[0])+long.Parse(a[0])*int.Parse(b[1])/100);
        }
    }
}

Measured memory_bytes: 27540
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    bool check = (x - r >= 0) && (y - r >= 0) && (W >= x + r) && (H >= y + r);
    cout << (check ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;
  int N=S.length();
  while(N!=0){
    if(N>=5 && S.substr(N-5,5)=="dream")N-=5;
    else if(N>=7 && S.substr(N-7,7)=="dreamer")N-=7;
    else if(N>=5 && S.substr(N-5,5)=="erase")N-=5;
    else if(N>=6 && S.substr(N-6,6)=="eraser")N-=6;
    else {cout<<"NO";return 0;}
  }
  cout<<"YES";
}

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

int a[12][12];
int p[12];
int skill[12];

int main() {
	int n,m,x;
	scanf("%d%d%d",&n,&m,&x);
	for (int i = 0; i < n; i++) { // books
		scanf("%d",&p[i]);
		for (int j = 0; j < m; j++) { // skills
			scanf("%d",&a[i][j]);
		}
	}
	
	// printf("input done\n");
	
	int lim = 1<<n;
	
  int ans = 1999999999, sum;
	bool e;
	
  for (int i = 0; i < lim; i++) { // case
		sum = 0;
		e = 1;
    for (int j = 0; j < m; j++) { // skill reset
			skill[j] = 0;
		}
		for (int j = 0; j < n; j++) { // book
			sum+=((i>>j)&1)*p[j];
			for (int k = 0; k < m; k++) { // skill
				skill[k]+=((i>>j)&1)*a[j][k];
			}
		}
		for (int j = 0; j < m; j++) {
			if (skill[j]<x) {
				e = 0;
				break;
			}
		}
		if (e) {
      ans = min(ans,sum);
      // /*if (sum==ans)*/ printf("%d %d\n",i,ans);
    }
	}
	
  if (ans==1999999999) {
    printf("-1\n");
    return 0;
  }

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

}

Measured memory_bytes: 3828
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        string[] Words = new string[N];
        char tail = ' ';
        for(int i = 0; i < N; i++)
        {
            Words[i] = Console.ReadLine();
            if (tail == ' ' || tail == Words[i].First())
                tail = Words[i].Last();
            else
            {
                tail = '0';
            }
        }
        if (N == Words.Distinct().Count() && tail != '0')
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}


Measured memory_bytes: 13280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i< (n); i++)
int main(){
int a,b;
cin >> a >> b;
vector<int> vec(2000, 2000);
rep(i, 2000){
    int c=0, d=0;
    c=i*0.08;
    d=i*0.1;
    if(c==a && d==b){
        vec.at(i)=i;
    }
}
sort(vec.begin(), vec.end());

if(vec.at(0)!=2000) cout << vec.at(0) << endl;
else cout << -1 << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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 main() {
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  if (n > 2 && m > 2) {
    ans += (n - 2) * (m - 2);
  } else {
    if (n == 1 && m == 1) ans = 1;
    else if (n == 1 || m == 1) ans = n * m - 2;
    else if (n == 2 || m == 2) ans = 0;
  }
  if (ans < 0) ans = 0;
  P(ans);
  return 0;
}



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

int main(){
  ll n;cin >> n;
  vector<ll> a(n+1);
  rep(i,n) cin >> a.at(i+1);
  ll ans = 0;
  for(ll i=1;i<=n;++i){
    if( i%2 == 1 && a.at(i)%2 == 1 ) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    char a[100][100],b[100][100];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < m; j++){
            cin >> b[i][j];
        }
    }

    bool seg = false;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n;j++){
            if(i+m-1 >= n || j+m-1 >= n){
                continue;
            }

            bool ans = true;
            for(int k = 0; k < m; k++){
                for(int l = 0; l < m; l++){
                    if(a[i+k][j+l] != b[k][l]){//ここが肝
                        ans = false;
                    }
                }
            }
            if(ans){
                    seg = true;
                }
        }
    }
    if(seg){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}



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

int main(){
	int a, b, n, c;
	while (cin >> a >> b)
	{
		n = a + b;
		c = 1;
		while( (n = n / 10) != 0 )
			++c;

		cout << c << "\n";
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int INF = 10000000;


int n;
int p[100];


int main(){

    int c = 0;
    P f, s;

    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> p[i];

        if(i != p[i]){
            c++;
        }
    }

    if(c == 2 || c == 0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
S = input()
T = input()
ans = -1
for i in range(0,len(S)-len(T)+1):
    count = 0
    for j in range(len(T)):
        if S[i+j] == T[j]:
            count += 1
    if count > ans:
        ans = count

print(len(T) - ans)

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

typedef long long ll;
ll N, M;
priority_queue<ll> A;
ll R;

int main() {
  cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    A.push(a);
  }
  for (int i = 0; i < M; ++i) {
    ll a = A.top();
    A.pop();
    a /= 2;
    A.push(a);
  }
  while (!A.empty()) {
    ll a = A.top();
    A.pop();
    R += a;
  }
  cout << R << endl;
}


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

template <int MOD>
class Modular {
public:
    Modular(long long v=0) {
        value = v % MOD;
        if (value < 0)
            value += MOD;
    }

    Modular(long long a, long long b) : value(0) {
        *this += a;
        *this /= b;
    }

    Modular& operator+=(Modular const& b) {
        value += b.value;
        if (value >= MOD)
            value -= MOD;
        return *this;
    }

    Modular& operator-=(Modular const& b) {
        value -= b.value;
        if (value < 0)
            value += MOD;
        return *this;
    }

    Modular& operator*=(Modular const& b) {
        value = (long long)value * b.value % MOD;
        return *this;
    }

    friend Modular power(Modular a, long long e) {
        Modular res = 1;
        while (e) {
            if (e & 1)
                res *= a;
            a *= a;
            e >>= 1;
        }
        return res;
    }

    friend Modular inverse(Modular a) {
        return power(a, MOD - 2);
    }

    Modular& operator/=(Modular const& b) {
        return *this *= inverse(b);
    }

    friend Modular operator+(Modular a, Modular const b) {
        return a += b;
    }

    friend Modular operator-(Modular a, Modular const b) {
        return a -= b;
    }

    friend Modular operator-(Modular const a) {
        return 0 - a;
    }

    friend Modular operator*(Modular a, Modular const b) {
        return a *= b;
    }

    friend Modular operator/(Modular a, Modular const b) {
        return a /= b;
    }

    friend std::ostream& operator<<(std::ostream &os, Modular const& a) {
        return os << a.value;
    }

    friend bool operator==(Modular const& a, Modular const& b) {
        return a.value == b.value;
    }

    friend bool operator!=(Modular const& a, Modular const& b) {
        return a.value != b.value;
    }

    int value;
    static const int MOD_value = MOD;
};

using ModInt = Modular<1'000'000'007>;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    
    map<char, int> cnt;
    for (char c : s) {
        cnt[c]++;
    }

    ModInt res(1);
    for (auto it : cnt) {
        res *= it.second + 1;
    }
    cout << (res - 1) << '\n';
}


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

using namespace std;
int main(void)
{
	int k;
	string s;
	cin>>k;
	cin>>s;
	if(s.size() <= k)
		cout<<s<<endl;
	else
		{
			for(int i=0;i<k;i++)
			{
				cout<<s[i];
			}
			cout<<"..."<<endl;
		}
	return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
int main(){
    int n,a,b,c,d;
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);

    if((n+a-1)/a*b < (n+c-1)/c*d)
        printf("%d\n",(n+a-1)/a*b);
    else printf("%d\n",(n+c-1)/c*d);

    return 0;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
const int N=200007;
std::vector<int>e1[N],e2[N];
int n,p1,p2,dep[N],fa[N],un[N],ans=0;
void f1(int w,int pa){
	for(int i=0;i<e2[w].size();++i){
		int u=e2[w][i];
		if(u!=pa){
			dep[u]=dep[w]+2;
			fa[u]=w;
			f1(u,w);
		}
	}
}
void f2(int w,int pa,int d){
	if(d>dep[w])return;
	if(un[w])ans=-1;
	if(ans!=-1&&ans<dep[w])ans=dep[w];
	for(int i=0;i<e1[w].size();++i){
		int u=e1[w][i];
		if(u!=pa)f2(u,w,d+2);
	}
}
int main(){
	scanf("%d%d%d",&n,&p1,&p2);
	for(int i=1,a,b;i<n;++i){
		scanf("%d%d",&a,&b);
		e1[a].push_back(b);
		e1[b].push_back(a);
	}
	for(int i=1,a,b;i<n;++i){
		scanf("%d%d",&a,&b);
		e2[a].push_back(b);
		e2[b].push_back(a);
	}
	f1(p2,0);
	for(int w=1;w<=n;++w){
		for(int i=0;i<e1[w].size();++i){
			int a=w,b=e1[w][i],c=0;
			for(;a!=b&&c<3;++c){
				if(dep[a]>dep[b])a=fa[a];
				else b=fa[b];
			}
			if(c==3)un[w]=1;
		}
	}
	f2(p1,0,1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 35836
import collections
N = int(input())

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

c = collections.Counter(prime_factorize(N))
kiso = [1]
for i in range(2, 10):
    kiso.append(kiso[i-2]+i)
d = dict()
k = 1
for i in range(1, 46):
    if i in kiso and i != 1:
        k += 1
    d[i] = k

ans = 0
for n in c:
    ans += d[c[n]]

print(ans)

Measured memory_bytes: 9468
#include<bits/stdc++.h>
using namespace std;
int A,B,K,i,cnt;
int main(){
  cin>>A>>B>>K;
  for(i=min(A,B);i;i--){
    if(A%i==0&&B%i==0){
      cnt++;
      if(cnt==K){
        cout<<i<<endl;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define ll long long int
ll GCD(ll x,ll y){return y==0? x:GCD(y,x%y);}
int compare_longlong(const void *a, const void *b) {long long *A = (long long *)a;long long *B = (long long *)b;if (*A > *B) return 1;if (*A < *B) return -1;return 0;}
int MAX(int x, int y){return x<y?y:x;}
int main(void){
	int n;
	scanf("%d",&n);
	ll a[n+1];
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	ll L[n+2],R[n+2],M,N;
	L[0] = R[n+1] = 0;
	for(int i=1;i<=n;i++)L[i] = GCD(L[i-1],a[i]);
	for(int i=n;i>=0;i--)R[i] = GCD(R[i+1],a[i]);
	for(int i=1;i<=n;i++){
		N = GCD(L[i-1],R[i+1]);
		M = MAX(M,N);
	}
	printf("%lld",M);
	
	return 0;
}

Measured memory_bytes: 2560
import java.util.*;
import java.io.*;
import java.util.function.*;

class Main {
    static Scanner scanner = new Scanner();
    static int mod = 1000000007;
    static int inf = 0x7ffffff;

    void solve() {
        int n = scanner.nextInt();
        System.out.println(n * n);
    }

    public static void main(String[]$) throws Exception {
        new Main().solve();
        System.out.flush();
    }
}

class System {
    static PrintWriter out = new PrintWriter(java.lang.System.out);

    static void exit() {
        java.lang.System.exit(0);
    }
}

class Scanner {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(java.lang.System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

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

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

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}


Measured memory_bytes: 23252
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramB a = new ProgramB();
            a.main();//実行する

        }

    }
    //ABC170
    class ProgramB
    {
        public void main()
        {
            //入力
            int D = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            int n = 26;

            long[] c = new long[n];
            long[] count = new long[n];

            long[,] score = new long[n,D];

            for (int i = 0; i < D; i++)
            {
                string[] t = Console.ReadLine().Split(' ');
                for (int j = 0; j < n; j++)
                    score[j, i] = long.Parse(t[j]);
            }

            for (int i = 0; i < n; i++)
                c[i] = long.Parse(s[i]);

            long ans = 0;
            
            for (int i = 0;i < D;i++)
            {
                int v = int.Parse(Console.ReadLine());

                count[v-1] = i+1;
                long sum = score[v - 1, i];
                for(int j = 0;j < n;j++)
                {
                    if(j != v -1)
                        sum -= c[j] * (i + 1 - count[j]);
                }
                ans += sum;

                Console.WriteLine(ans);
            }

        }
    }

    class ProgramA
    {
        public void main()
        {
            //入力
            int D = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            int n = 26;

            long[] c = new long[n];
            long[] count = new long[n];

            for (int i = 0; i < n; i++)
                c[i] = long.Parse(s[i]);

            for (int i = 0; i < D; i++)
            {
                long[] score = new long[n];
                string[] t = Console.ReadLine().Split(' ');

                for (int j = 0; j < n; j++)
                    score[j] = long.Parse(t[j]);

                count[0] = D + 1;
                long sum = score[0];
                for (int j = 1; j < n; j++)
                {
                    sum -= c[j] * (i + 1 - count[j]);
                }

                Console.WriteLine(sum);
            }

        }
    }

    class ProgramC
    {
        public void main()
        {

            

        }
    }

    

}






Measured memory_bytes: 27964
#include <iostream>
#include <limits.h>
#include <algorithm>

int main()
{
	int n, m, r;
	std::cin >> n >> m >> r;
	
	int rs[100];
	for (int i = 0; i < r; ++i)
	{
		std::cin >> rs[i];
		--rs[i];
	}
	
	long long int dist[310][310] = { 0 };
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			if (i != j)
				dist[i][j] = INT_MAX;
		}
	}
	
	for (int i = 0; i < m; ++i)
	{
		int a, b;
		long long int c;
		std::cin >> a >> b >> c;
		--a;
		--b;
		
		dist[a][b] = std::min(dist[a][b], c);
		dist[b][a] = std::min(dist[b][a], c);
	}
	
	for (int k = 0; k < n; ++k)
	{
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j < n; ++j)
			{
				if (dist[i][j] > dist[i][k] + dist[k][j])
				{
					dist[i][j] = dist[i][k] + dist[k][j];
				}
			}
		}
	}
	
	std::sort(rs, rs + r);
	
	long long int ans = LONG_MAX;
	do
	{
		long long int count = 0;
		
		for (int i = 1; i < r; ++i)
			count += dist[rs[i - 1]][rs[i]];
		
		ans = std::min(ans, count);
	} while (std::next_permutation(rs, rs + r));
	
	std::cout << ans;
}

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

int main(){
    int N,R;
    cin >> N >> R;
    int res = 0;
    if(N >= 10){
        res = R;
    }else{
        res = R + 100*(10-N);
    }

    cout << res << endl;

}


Measured memory_bytes: 256
N,K = map(int,input().split())
X = list(map(int,input().split()))
ans = 10**N+1
distance = 0
for i in range(N-K+1):
  distance = X[i+K-1]-X[i]
  ans = min(abs(X[i])+distance,abs(X[i+K-1])+distance,ans)
print(ans)


Measured memory_bytes: 14224
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{

	static void Main(string[] args)
	{
		var N = int.Parse(Console.ReadLine());
		var S = Console.ReadLine();
		var K = int.Parse(Console.ReadLine());

		var target = S[K - 1];
		var result = new char[N];

		for (int i = 0; i < N; i++)
		{
			if (S[i] == target)
				result[i] = target;
			else
				result[i] = '*';
		}

		Console.WriteLine(new String(result));
	}
}


Measured memory_bytes: 11092
if __name__ == '__main__':
    n, m = map(int, input().split())
    paths = [[] for i in range(n)]
    dist = [-1] * n

    for i in range(m):
        a, b = map(int, input().split())
        paths[a - 1].append(b - 1)
        paths[b - 1].append(a - 1)

    next = []
    # next is (from, to)
    for i in paths[0]:
        next.append((0, i))

    for prev, to in next:
        if dist[to] == -1:
            dist[to] = prev
            for i in paths[to]:
                next.append((to, i))

    if dist.count(-1) != 0:
        print("No")
    else:
        print("Yes")
        for i in range(1, n):
            print(dist[i] + 1)


Measured memory_bytes: 66604
<?php
// D
fscanf(STDIN, '%s', $s);
$n = strlen($s);
$mods = array_fill(0, 2019, 0);
$mods[0]++;
$mod = 0;
$t = 1;
for ($i = $n - 1; $i >= 0; $i--) {
    $mod = ($mod + (int) $s[$i] * $t) % 2019;
    $t = $t * 10 % 2019;
    $mods[$mod]++;
}
$ans = 0;
for ($i = 0; $i < 2019; $i++) {
    $ans += intdiv($mods[$i] * ($mods[$i] - 1), 2);
}
echo $ans;

Measured memory_bytes: 16336
import java.util.*;

import static java.lang.System.*;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();

	class Era{
		int len;
		int y;
		String name;
		Era(int len,int y,String name){
			this.len=len;
			this.y=y;
			this.name=name;
		}
	}

	public void run() {
		TCase:while(true){
			int n=sc.nextInt(),q=sc.nextInt();
			if(n==0)return;
			Era[] eras=new Era[n];
			for(int i=0;i<n;i++){
				String name=sc.next();
				int d=sc.nextInt();
				int y=sc.nextInt();
				eras[i]=new Era(d,y,name);
			}
			Arrays.sort(eras,new Comparator<Era>(){
				@Override
				public int compare(Era o1, Era o2) {
					return o1.y-o2.y;
				}
			});
			int[] ys=new int[n];

			for(int i=0;i<n;i++){
				ys[i]=eras[i].y;
			}
			for(int i=0;i<q;i++){
				int y=sc.nextInt();
				int ind=Arrays.binarySearch(ys,y);
				if(ind<0)ind=~ind;
				if(0<=ind && ind<ys.length){
					Era era=eras[ind];
					if(0<era.len+y-era.y)
						ln(era.name+" "+(era.len+y-era.y));
					else
						ln("Unknown");
				}else
					ln("Unknown");
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

Measured memory_bytes: 72484
#include <bits/stdc++.h>
 
#define pf printf
#define sc scanf
#define endl "\n"
#define dbug(x) cout << #x << ": " << x << endl
#define gi(k) scanf("%d",&k)
#define gl(k) scanf("%lld",&k) 
#define pb push_back
#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define rep(i,n) for(int i = 1; i <= n; i++)
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod) x-=mod;if(x<0) x+=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))
#define Set(N,cur) N=(N|(1LL<<cur))
#define Reset(N,cur) N=(N&(~(1LL<<cur)))
#define Check(N,cur) (!((N&(1LL<<cur))==0))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)
#define NMAX 2147483647
#define LMAX 9223372036854775807LL
#define mem CLR
 
using namespace std;
 
 
#define LL long long
#define LLU long long unsigned int
typedef long long vlong;
typedef unsigned long long uvlong;
typedef pair < int, int > pii;
typedef pair < vlong, vlong > pll;
typedef vector<int> vi;
typedef vector<vlong> vl;
typedef vector<pll> vll;
 
inline vlong gcd ( vlong a, vlong b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

 
const vlong inf = 2147383647;
const vlong mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-9;
 
 
int t,n,x,y; 
 
int main () {
 	
 	#ifdef forthright48
    freopen ( "00_input.txt", "r", stdin ); //freopen ( "00_output.txt", "w", stdout );
 	#endif

 	cin >> n >> x >> y;

 	if((x-y) & 1) pf("Borys");
 	else pf("Alice");

 	nl;
 
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
N, W = [int(i) for i in input().split()]
Things = [[int(i) for i in input().split()] for j in range(N)]

dp = defaultdict(lambda: float('inf'))
dp[0] = 0
for w, v in Things:
    for nv, nw in list(dp.items()):
        if nw + w <= W:
            dp[nv + v] = min(dp[nv + v], nw + w)
ans = 0
for v, w in dp.items():
    if w <= W and v >= ans:
        ans = v
print(ans)

Measured memory_bytes: 76764
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  vi w(10);
  vi k(10);
  rep(i,10)
    cin>>w[i];
  rep(i,10)
    cin>>k[i];
  sort(all(w));
  sort(all(k));
  cout<<w[7]+w[8]+w[9]<<" "<<k[7]+k[8]+k[9]<<endl;
}

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

int main() {
long M,N,sum=0;
  
  cin>>N>>M;
for(int i=0;i<M;i++){
  int a;
  cin>>a;
  sum+=a;
}
  if(N-sum>=0){
  cout<<N-sum;
  }
  else{
    cout<<-1;
  }
    
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){

	long long int N,x=2;
	
	cin>>N;
	cout<<N<<":";
	while(1){//cout<<"#"<<x<<endl;
	
		if(x*x>N)break;
		if(N%x==0){
			cout<<" "<<x;
			N=N/x;
			x=0;

		}
		
		
		x+=2;
		if(x!=2&&x%2==0)x--;
		
	}
	
	if(N!=1)cout<<" "<<N;
	cout<<endl;

		return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int main(){
    int n;cin>>n;
    string s;cin>>s;
    int q;cin>>q;
    while(q--){
        int k;cin>>k;k--;
        if(k<2){
            cout<<0<<endl;
            continue;
        }
        ll ans=0;
        ll co=0;
        ll mc=0,dc=0;
        for(int j=n-1;j>=n-1-k;j--){
            if(s[j]=='D'){
                co+=mc;
                dc++;
            }else if(s[j]=='M'){
                mc++;
            }
        }
        for(int c=n-1;c>=2;c--){
            if(s[c]=='C'){
                ans+=co;
            }else if(s[c]=='M'){
                mc--;
                co-=dc;
            }else if(s[c]=='D'){
                dc--;
            }
            if(c<=k)continue;
                if(s[c-k-1]=='M'){
                    mc++;
                }else if(s[c-k-1]=='D'){
                    co+=mc;
                    dc++;
                }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 1412
def main():
    MOD = 10 ** 9 + 7

    S = input()

    N = len(S)
    dp = [[0] * 4 for _ in range(N + 1)]

    for i in reversed(range(N + 1)):
        for j in reversed(range(4)):
            if i == N:
                dp[i][j] = int(j == 3)
            else:
                dp[i][j] = dp[i + 1][j] * (3 if S[i] == "?" else 1)
                if j < 3 and (S[i] == "?" or S[i] == "ABC"[j]):
                    dp[i][j] += dp[i + 1][j + 1]
                dp[i][j] %= MOD

    print(dp[0][0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 27596
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで


using namespace std;
lint h,w,k;
lint ban[10][105];
lint kazu[8] = {1,1,2,3,5,8,13,21};

int main(){
  cin >> h >> w >> k;
  ban[1][0] = 1;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      ban[j][i] += ban[j][i-1] * kazu[j-1] * kazu[w-j];
      ban[j][i] %= MOD;
      if(j>=2){
        ban[j][i] += ban[j-1][i-1] * kazu[j-2] * kazu[w-j];
        ban[j][i] %= MOD;
      }
      if(j<=w-1){
        ban[j][i] += ban[j+1][i-1] * kazu[j-1] * kazu[w-j-1];
        ban[j][i] %= MOD;
      }
      //cout << i << " " << j << " " << ban[j][i] << endl;
    }
  }
  cout << ban[k][h] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>           // printf(), scanf()
#include <vector>
#include <algorithm>        // swap()

using namespace std;
static const int MAX_V = 100000;
static const int MAX_LOG_V = 17; // ceil(log(MAX_V))

vector<int> G[MAX_V];
int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];

void
dfs(int v, int p, int d)
{
	parent[0][v] = p;
	depth[v] = d;
	for (unsigned int i = 0; i < G[v].size(); ++i)
	{
		if (G[v][i] != p)
			dfs(G[v][i], v, d + 1);
	}
}

void
init_lca(int V)
{
	dfs(0, -1, 0);
	for (int k = 0; k + 1 < MAX_LOG_V; ++k)
	{
		for (int v = 0; v < V; ++v)
		{
			if (parent[k][v] < 0)
				parent[k + 1][v] = -1;
			else
				parent[k + 1][v] = parent[k][parent[k][v]];
		}
	}
}

int
lca(int u, int v)
{
	if (depth[u] > depth[v])
		swap(u, v);

	for (int k = 0; k < MAX_LOG_V; ++k)
	{
		if (((depth[v] - depth[u]) >> k) & 1)
			v = parent[k][v];
	}

	if (u == v)
		return u;

	for (int k = MAX_LOG_V - 1; k >= 0; --k)
	{
		if (parent[k][u] != parent[k][v])
		{
			u = parent[k][u];
			v = parent[k][v];
		}
	}

	return parent[0][u];
}

int
main(int argc, char** argv)
{
	int V;
	int q;

	scanf("%d", &V);
	for (int i = 0; i < V; ++i)
	{
		int k;
		int c;

		scanf("%d", &k);
		for (int j = 0; j < k; ++j)
		{
			scanf("%d", &c);
			G[i].push_back(c);
		}
	}

	init_lca(V);
	scanf("%d", &q);
	while (q--)
	{
		int u, v;

		scanf("%d %d", &u, &v);
		printf("%d\n", lca(u, v));
	}

	return 0;
}

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

long long k, n = 50;
long long ans[50] = {0};

void solve();

int main() {
  cin >> k;
  for(int i = 0; i < n; ++i) ans[i] = 49 - k;
  solve();
  cout << n << endl;
  for(int i = 0; i < n; ++i) {
    if(i != 0) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

void solve() {
  for(int i = 0; i < n; ++i) ans[i] += 51 * (k / 50);
  for(int i = 0; i < k % 50; ++i) ans[i] += 51;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vi x(n), y(n), h(n);
    rep(i, n) cin >> x[i] >> y[i] >> h[i];

    rep(cx, 101){
        rep(cy, 101){
            int H = 0;
            int Hu = inf;

            bool ok = [&](){
                rep(i, n){
                    int cur = abs(x[i] - cx) + abs(y[i] - cy);

                    if(h[i] > 0){
                        int curH = h[i] + cur;

                        if(H > 0 and H != curH){
                            return false;
                        }
                        H = curH;
                    }
                    else {
                        int curHu = cur;
                        chmin(Hu, curHu);
                    }
                }
                if(H == 0 or Hu < H){
                    return false;
                }

                return true;
            }();

            if(ok){
                cout << cx << " " << cy << " " << H << endl;
                return 0;
            }
        }
    }

    assert(false);

    return 0;
}


Measured memory_bytes: 256
def rec i, j
  if j - i == 1
    [i]
  else
    rs = []
    for k in i + 1 ... j
      ts = rec k, j
      rec(i, k).each do |t|
        ts.each do |s|
          [:+, :-, :*].each do |op|
            rs << [op, t, s]
          end
        end
      end
    end
    rs
  end
end

def ev xs, t
  return xs[t] if t.is_a? Integer
  op, a, b = t
  case op
  when :+
    ev(xs, a) + ev(xs, b)
  when :-
    ev(xs, a) - ev(xs, b)
  when :*
    ev(xs, a) * ev(xs, b)
  end
end

def pp xs, t
  return xs[t].to_s if t.is_a? Integer
  op, a, b = t
  case op
  when :+
    "(#{pp xs, a} + #{pp xs, b})"
  when :-
    "(#{pp xs, a} - #{pp xs, b})"
  when :*
    "(#{pp xs, a} * #{pp xs, b})"
  end
end

trees = rec 0, 4

loop do
  xs = gets.split.map(&:to_i)
  break if xs.all?(&:zero?)
  tree, xs = xs.permutation do |xs|
    tree = trees.find {|t| ev(xs, t) == 10 }
    break [tree, xs] if tree
  end
  puts tree ? pp(xs, tree) : 0
end

Measured memory_bytes: 8688
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

// array pointer = *a, num of element = n, key key
int lower_bound(int *a, int n, int key){
    int ng, mid, ok;
    ng = -1, ok = n-1;
    while (abs(ok - ng) > 1){
        mid = (ok + ng) / 2;
        if (key <= a[mid]){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    if (a[ok] >= key)return ok;
    return n;
}

//greatest common divisor
unsigned long gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}

unsigned long lcm(unsigned long x, unsigned long y){
    unsigned long g = gcd(x, y);
    return x*y/g;

}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

/*
int struct_ascending_compare(const void *p, const void *q) {
return ((struct_name*)p)->member_name - ((struct_name*)q)->member_name;
}*/

/*unsigned long long pascal[100][100] = {0};
void make_pascal(void){
    for (int i = 0; i < 100; i++){
        pascal[i][0] = 1;
    }
    pascal[1][1] = 1;
    for (int i = 2; i < 100; i++){
        for (int j = 1; j < 100; j++){
           pascal[i][j] = (pascal[i-1][j-1]+pascal[i-1][j]) % mod;
        }
    }
}*/
long long mod = 1000000007;

//x ^ n
long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % mod;
        x = x * x % mod;
    }
    return res;
}


double speed[100000];
int t[105];
int v[105];


int main(void){
    int n;
    int total = 0;
    scanf("%d", &n);

    for (int i = 0; i < n; i++){
        scanf("%d", &t[i]);
        total += t[i];
    }
    for (int i = 0; i < n; i++){
        scanf("%d", &v[i]);
    }
    int crt = 0;
    speed[crt] = 0;

    for (int i = 0; i < n; i++){
        for (int j = 1; j <= t[i]*2; j++){
            if (!(crt+j))continue;
            if (speed[crt+j-1] + 0.5 <= v[i]) speed[crt+j] = speed[crt+j-1] + 0.5;
            else speed[crt+j] = v[i];
        }
        crt += t[i]*2;
    }
    total *= 2;
    crt = total;
    speed[crt] = 0;
    for (int i = n-1; i >= 0; i--){
        for (int j = 1; j <= t[i]*2; j++){
            if (speed[crt-j+1] + 0.5 <= v[i] && speed[crt-j+1] + 0.5 <= speed[crt-j]) speed[crt-j] = speed[crt-j+1] + 0.5;
            else speed[crt-j] = speed[crt-j]>v[i]?v[i]:speed[crt-j];
        }
        crt -= t[i]*2;
    }
    double ans = 0;

    for (int i = 0; i <= total; i++){
        ans += speed[i];
    }
    printf("%f\n", ans/2);
    
    return 0;
}


Measured memory_bytes: 512
n=int(input())
p=list(map(int,input().split()))
sort_p=sorted(p)
if p==sort_p:
  print('YES')
  exit()
for i in range(n-1):
  for j in range(i+1,n):
    k=p[i]
    l=p[j]
    p[i]=l
    p[j]=k
    if p==sort_p:
      print('YES')
      exit()
    p[i]=k
    p[j]=l
print('NO')

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

lli data[10][10];
lli flag[10][10];

signed main(){

	lli h,w;
	cin>>h>>w;

	REP(i,0,h)REP(j,0,w){
		char tmp;
		cin>>tmp;
		if(tmp=='#')data[i][j]=1;
	}

	queue<pair<lli,lli>> q;
	q.push(mp(0,0));
	flag[0][0]=1;

	while(q.size()){
		pair<lli,lli> p = q.front();
		q.pop();

		lli dx[2]={0,1};
		lli dy[2]={1,0};

		bool move = false;
		if(p.first == (h-1) && p.second == (w-1))move = true;
		REP(i,0,2){
			lli nextX = p.second+dx[i];
			lli nextY = p.first +dy[i];
			if(data[nextY][nextX]==0)continue;
			if(flag[nextY][nextX]==1){
				cout<<"Impossible"<<endl;
				return 0;
			}
			flag[nextY][nextX]=1;
			q.push(mp(nextY,nextX));
			move = true;
		}
		if(!move){
							cout<<"Impossible"<<endl;
				return 0;
		}
	}
	REP(i,0,h)REP(j,0,w){
		if(data[i][j]==1 && flag[i][j]==0){
			cout<<"Impossible"<<endl;
			return 0;
		}
	}
	cout<<"Possible"<<endl;



	return 0;
}

Measured memory_bytes: 256
import math
def nCr(n, r): 
  
    return (math.factorial(n) // (math.factorial(r)  
                * math.factorial(n - r))) 
n,m=list(map(int,input().split()))
total=0
if n>1:
  total+=nCr(n,2)
if m>1:
  total+=nCr(m,2)
print(total)

Measured memory_bytes: 38256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s,t;
    cin>>s>>t;
    s=s+s;
    for(int i=0;i<t.size();i++){
        if(s.substr(i,t.size())==t){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}


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

#define LEN 1000000
using namespace std;

int search(int A[], int n, int key){
  int i = 0;
  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(int argc, const char * argv[]) {
  int i, n, A[LEN], q, key, sum = 0;
  
  cin >> n;
  for(i=0; i < n; i++) cin >> A[i];
  
  cin >> q;
  
  for(i=0; i< q; i++){
    cin >> key;
    if(search(A, n, key)) sum++;
  }
  
  cout << sum << endl;
  
  return 0;
}



Measured memory_bytes: 3152
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	s := getNextInt(scanner)
	w := getNextInt(scanner)
	if s > w {
		fmt.Fprintln(writer, "safe")
		return
	}
	fmt.Fprintln(writer, "unsafe")
}


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

using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<unsigned> in(N);
  for(int i = 0; i < N; i++) cin >> in[i];
  
  int cnt = 0;
  while(true){
    for(int i = 0; i < N; i++){
      if(in[i] % 2 == 1) goto end;
      in[i] /= 2;
    }
    cnt++;
  }
  end:

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
ll gcd(ll x,ll y){
  if(!y)return x;
  else return gcd(y,x%y);
}

int main()
{
  int N;
  ll T[101],res=0;
  cin >> N;
  REP(i,N)cin >> T[i];
  res = T[0];
  for(int i=1;i<N;i++){
    res = (T[i])/gcd(res,T[i])*(res);
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 256