akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,p;
  cin >> n >> p;
  string s;
  cin >> s;
  reverse(s.begin(),s.end());
  if(p==2||p==5){
    ll ans = 0;
    rep(i,n){
      if((s[i]-'0')%p==0)ans += (n-i);
    }
    cout << ans << endl;
    return 0;
  }
  map<int,int> mp;
  int remain = 0;
  mp[remain]++;
  int mod = 1;
  rep(i,n){
    remain += (s[i]-'0')*mod;
    remain %= p;
    mp[remain]++;
    mod *= 10;
    mod %= p;
  }
  ll ans = 0;
  for(auto p:mp){
    //cout << p.first << " " << p.second << endl;
    ans += (ll)p.second*(p.second-1)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 892
use std::io::*;
use std::str::FromStr;
use std::collections::VecDeque;

fn main() {
    let n: usize = read();
    let q: usize = read();
    
    let mut vec: Vec<Vec<usize>> = vec![vec![]; n];
    for _ in 0..n-1 {
        let a: usize = read();
        let b: usize = read();
        vec[a-1].push(b-1);
        vec[b-1].push(a-1);
    }

    let mut count: Vec<usize> = vec![0; n];
    for _ in 0..q {
        let p: usize = read();
        let x: usize = read();
        count[p-1] += x;
    }
    
    let mut que = VecDeque::new();
    que.push_back(0);
    let mut used: Vec<bool> = vec![false; n];
    used[0] = true;
    while let Some(q) = que.pop_front() {
        for v in &vec[q] {
            if !used[*v] {
                used[*v] = true;
                count[*v] += count[q];
                que.push_back(*v);
            }
        }
    }

    for i in 0..n {
        if i > 0 {
            print!(" ");
        }
        print!("{}", count[i]);
    }
    println!();
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 24700
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, M;
  cin>>N>>M;

  vector<Int> ac(N), wa(N);

  Int num = 0, pen = 0;
  for(Int i=0;i<M;i++){
    Int p;
    string s;
    cin>>p>>s; p--;
    if(ac[p]) continue;
    if(s == "AC") ac[p] = 1, num++, pen += wa[p];
    else wa[p]++;
  }

  cout<<num<<" "<<pen<<endl;
  return 0;
}


Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main() {
	var S string
	fmt.Scan(&S)

	if S[0] != 'A' {
		fmt.Println("WA")
		return
	}

	num := 0
	pos := 0
	for i := 2; i < len(S)-1; i++ {
		if S[i] == 'C' {
			num++
			pos = i
		}
	}
	if num != 1 {
		fmt.Println("WA")
		return
	}

	for i := 1; i < len(S); i++ {
		if pos == i {
			continue
		}
		if S[i] < 'a' || 'z' < S[i] {
			fmt.Println("WA")
			return
		}
	}

	fmt.Println("AC")
}


Measured memory_bytes: 512
from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
n,m = map(int, stdin.readline().rstrip().split())
#S = [list(map(int, stdin.readline().rstrip().split())) for _ in range(h)]#hの定義を忘れずに

print(int(n*(n-1)/2 + m*(m-1)/2))


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc172_b
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] nmk = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var n = nmk[0];
            var m = nmk[1];
            var k = nmk[2];
            long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long[] b = Console.ReadLine().Split().Select(long.Parse).ToArray();


            long[] sum_a = new long[a.Length + 1];
            sum_a[0] = 0;
            for (int i = 1; i < a.Length + 1; i++)
            {
                sum_a[i] = sum_a[i - 1] + a[i - 1];
            }


            long[] sum_b = new long[b.Length + 1];
            sum_b[0] = 0;
            for (int i = 1; i < b.Length + 1; i++)
            {
                sum_b[i] = sum_b[i - 1] + b[i - 1];
            }


            long ans = 0;
            long j = m;
            for (int i = 0; i < a.Length + 1; i++)
            {
                if (sum_a[i] > k) break;
                while (sum_b[j] > k - sum_a[i])
                {
                    j -= 1;
                }
                ans = Math.Max(ans, i + j);
            }

            // 出力
            Console.WriteLine(ans);

            Console.Read();
        }
    }
}


Measured memory_bytes: 72960
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ARC63_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int count = 0;
            for (int i = 1; i < s.Length; i++)
            {
                if(s[i] != s[i-1])
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


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

int main(){
    int K, S;
    cin >> K >> S;
    int
    ans = 0;
    for(int X = 0; X <= K; X++){
        for(int Y = 0; Y <= K; Y++){
            if(X + Y <= S && S - X - Y <= K){
                ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def main():
    S = list(input())
    N = len(S)
    if N <= 2:
        print(0)
        exit()
    T = []
    flag = False
    for i in range(N-1):
        if flag:
            flag = False
            continue

        if S[i] == 'B' and S[i+1] == 'C':
            T.append('D')
            flag = True
        else:
            T.append(S[i])
        
    if not (S[i-2] == 'B' and S[i-1] == 'C'):
        T.append(S[i-1])
    
    M = len(T)
    d = [0] * T.count('D')
    ans = 0
    a = 0
    for i in range(M):
        if T[i] == 'A':
            a += 1
        elif T[i] == 'D':
            ans += a
        else:
            a = 0
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 96472
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  vector<ll> N(3);
  int K;
  for(int i = 0; i < 3; i++) cin >> N[i]; cin >> K;
  vector<vector<ll>> v(3);
  for(int iter = 0; iter < 3; iter++){
    v[iter].resize(N[iter]);
    for(int i = 0; i < N[iter]; i++) cin >> v[iter][i];
    sort(v[iter].begin(),v[iter].end(),greater<ll>());
  }
  priority_queue<pair<ll,vector<int>>> que;
  set<pair<ll,vector<int>>> se;
  que.push(make_pair(v[0][0]+v[1][0]+v[2][0],vector<int>({0,0,0})));
  
  for(int k = 0; k<K;k++){
    auto c = que.top();que.pop();
    cout << c.first << endl;
    
    for(int iter = 0; iter < 3; iter++){
      if(c.second[iter] + 1 < N[iter]){
        ll sum = c.first - v[iter][c.second[iter]] + v[iter][c.second[iter]+1];
        auto num = c.second; num[iter]++;
        auto d = make_pair(sum,num);
        
        if(!se.count(d)) se.insert(d), que.push(d);
      }
    }
  }
  
  
  return 0;
}

Measured memory_bytes: 1408
n = int(input())

t, x, y = [0], [0], [0]

for i in range(n):
    ti, xi, yi, = map(int, input().split())
    t.append(ti)
    x.append(xi)
    y.append(yi)
    
is_can = True
for i in range(len(t) - 1):
    dt = t[i + 1] - t[i]
    dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i])
    if dt < dist:
        is_can = False
        break
    if(dt % 2 != dist % 2):
        is_can = False
        break
if is_can:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 11764
#https://juppy.hatenablog.com/entry/2019/02/20/ARC64_-E_Cosmic_Rays-_Python_%E7%AB%B6%E6%8A%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0_Atcoder

def dijkstra(s):
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0

    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
            break
        used[v] = True

        for j in range(n):
            d[j] = min(d[j], d[v] + cost[v][j])
    return d


sx, sy, gx, gy = map(int,input().split())
n = int(input())
edge = [[sx, sy, 0]]

for i in range(n):
    x, y, r = map(int,input().split())
    edge.append([x,y,r])
edge.append([gx, gy, 0])

cost = [[0] * (n + 2) for _ in range(n + 2)]
for j, k in enumerate(edge):
    for l, m in enumerate(edge):
        if j == l:
            continue
        else:
            cost[j][l] = max(((k[0]-m[0])**2+(k[1]-m[1])**2)**0.5-k[2]-m[2], 0)
n += 2

res = dijkstra(0)
print(res[-1])


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	string s; cin >> s;
	cin >> s;
	cout << "A" << s[0] << "C" << endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
n,m = map(int,input().split())
a = np.zeros(m)
b = np.zeros(m)
for i in range(m):
    a[i] , b[i] = map(int ,input().split())

a -= 1
b -= 1 
cnt = 0

while(a.shape[0]):
    min_b = np.min(b)
    in_task = (a < min_b).astype(np.bool)
    cnt += 1
    tmp = np.logical_not(in_task)
    a = a[tmp]
    b = b[tmp]
    
print(cnt)


Measured memory_bytes: 21256
#include <iostream>

#define rep(i,n)      for(int i=0;i<n;i++)

using namespace std;

int table[36 + 1];

int main()
{
	rep(a,10)rep(b,10)rep(c,10)rep(d,10) table[a+b+c+d]++;

	int N;
	while (cin>>N)
	{
		if (N > 36)
			cout << 0 << endl;
		else
			cout << table[N] << endl;
	}
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	if(n == 3 || n == 5 || n == 7){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> h;
  int a;
  bool b = true;
  cin >> a;
  h.push_back(a);
  for(int i=1;i<n;i++){
    cin >> a;
    if(a>h[i-1]) h.push_back(a-1);
    else if(a==h[i-1]) h.push_back(a);
    else{
      b = false;
      break;
    }
  }
  if(b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main() {
  int64_t N,Z=0;
  cin>>N;
  vector<pair<int64_t,int64_t>> p(N);
for (int64_t i=0;i<N;i++) {
  int64_t a;
  cin>>a;
  p.at(i).first=a,p.at(i).second=i;
}
  vector<vector<int64_t>> d(N+1,vector<int64_t>(N+1));
  sort(p.begin(), p.end());
reverse(p.begin(), p.end());
  for(int64_t i=0;i<N;i++){
    d.at(0).at(i+1)=d.at(0).at(i)+p.at(i).first*abs(N-1-i-p.at(i).second);
    for(int64_t j=1;j<=i;j++){
      d.at(j).at(i+1-j)=max(d.at(j).at(i-j)+p.at(i).first*abs(N-1-i+j-p.at(i).second),d.at(j-1).at(i-j+1)+p.at(i).first*abs(j-1-p.at(i).second));
    }
    d.at(i+1).at(0)=d.at(i).at(0)+p.at(i).first*abs(i-p.at(i).second);
  }
  for(int64_t i=0;i<=N;i++){
    Z=max(Z,d.at(i).at(N-i));
  }
  cout<<Z<<endl;
}

Measured memory_bytes: 34664
#include <iostream>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

ll N, M;
bool a[100100] = {};
ll memo[100100];

ll f(int loc){
    if(loc == N) return memo[loc] = 1;
    if(memo[loc] > -1) return memo[loc];

    bool next = a[loc + 1];
    bool next_next = a[loc + 2];

    ll ans = 0;
    if(!next) {
        ans = (ans + f(loc + 1)) % MOD;
        if(!next_next) {
            ans = (ans + f(loc + 2)) % MOD;
        }
    } else {
        if(next_next){
            return memo[loc] = 0;
        }else {
            ans = (ans + f(loc + 2)) % MOD;
        }
    }

    return memo[loc] = ans;
}

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

    for(int i = 0; i < N; ++i){
        memo[i] = -1;
    }

    for(int i = 0; i < M; ++i)  {
        int tmp;
        cin >> tmp;
        a[tmp] = true;
    }

    f(0);

    cout << memo[0] << endl;
}



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

struct Node {
  int good, left, up, right, down;
};

vector< vector<Node> > nodes;

int ns(Node n) {
  return n.left + n.right + n.up + n.down + n.good;
}

int main() {
  int h, w;
  cin >> h >> w;
  string s;
  int lastLeft = 0;
  vector<int> lastUp = vector<int>(w, 0);

  for(int i = 0; i < h; i++) {
    cin >> s;
    nodes.push_back(vector<Node>());
    lastLeft = 0;

    for(int j = 0; j < w; j++) {
      char c = s[j];
      Node n;
      n.good = c == '.' ? 1 : 0;
      n.left = 0;
      n.up = 0;
      n.right = w - j - 1;
      n.down = h - i - 1;
      if(n.good == 1) {
        if(j > 0) {
          Node l = nodes[i][j - 1];
          n.left = l.left + l.good;
        }
        if(i > 0) {
          Node u = nodes[i-1][j];
          n.up = u.up + u.good;
        }
      }
      else {
        n.right = 0;
        n.down = 0;
        for(int k = lastLeft; k < j; k++) {
          nodes[i][k].right = j - k - 1;
        }
        for(int k = lastUp[j]; k < i; k++) {
          nodes[k][j].down = i - k - 1;
        }
        lastLeft = j + 1;
        lastUp[j] = i + 1;
      }

      nodes[i].push_back(n);
    }
  }

  int mx = -1;
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      int nss = ns(nodes[i][j]);
      // cout << i << " " << j << " " << nss << endl;
      // cout << nodes[i][j].left << " " << nodes[i][j].right << " " << nodes[i][j].up << endl;
      if(nss > mx) {
        mx = ns(nodes[i][j]);
      }
    }
  }

  cout << mx << endl;
}


Measured memory_bytes: 82944
#include<stdio.h>
#include<cmath>
int main(){
    double n;
    while(1){
        scanf("%lf",&n);
        if(n==0)    break;
        double a[int(n)];
        double s=0;
        double alpha=0;
        for(int i=0; i<n; i++){
            scanf("%lf",&a[i]);
            s+=a[i];
        }
        s/=n;
        for(int i=0; i<n; i++){
            alpha+=(a[i]-s)*(a[i]-s);
        }
        alpha=sqrt(alpha/n);
        printf("%.8lf\n",alpha);
    }
    return 0;
}


Measured memory_bytes: 2740
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] c = new int[n];
		boolean[] dp = new boolean[k+1];
//		dp[0] = false;
		for(int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
		}
		
		for(int i = 0; i <= k; i ++) {
			for(int j = 0; j < n; j++) {
				if(i-c[j] >= 0)dp[i] = (dp[i]) | !dp[i-c[j]];
			}
		}
		System.out.println(dp[k]?"First":"Second");
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
  int N, M = 256;
  while(cin >> N, N){
    int l[N], s = -1, a = -1, c = -1;
    long double H = (1e10);
    for(int i = 0; i < N; ++i)
      cin >> l[i];
    for(int S = 0; S < 16; ++S){
      for(int A = 0; A < 16; ++A){
	for(int C = 0; C < 16; ++C){
	  vector<int> V(M,0);
	  int R = S;
	  for(int i = 0; i < N; ++i){
	    R = (A*R+C)%M;
	    ++V[(l[i]+R)%M];
	  }

	  double t = 0.0;
	  for(int i = 0; i < M; ++i)
	    if(V[i]) t -= (double)V[i]/N*log((double)V[i]);

	  if(t < H){
	    s = S;
	    a = A;
	    c = C;
	    H = t;
	  }
	}
      }
    }
    printf("%d %d %d\n", s, a, c);
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vll x(m);
  for (int i = 0; i < m; i++)
    cin >> x[i];
  sort(x.begin(), x.end());
  if (m == 1) {
    cout << 0 << endl;
    return 0;
  }
  vll sub(m - 1);
  ll ans = 0;
  for (int i = 0; i < m - 1; i++)
    ans += sub[i] = x[i + 1] - x[i];
  sort(sub.begin(), sub.end());
  reverse(sub.begin(), sub.end());
  for (int i = 0; i < n - 1 && i < sub.size(); i++) {
    ans -= sub[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, k;
    cin >> n >> k;
    ll r, s, p;
    cin >> r >> s >> p;

    string t;
    cin >> t;

    vvll c(k);
    REP(i, n) {
        ll mem;
        if (t[i] == 'r') mem = 0;
        else if (t[i] == 's') mem = 1;
        else mem = 2;
        c[i % k].push_back(mem);
    }
    vll sc = {p, r, s};
    ll res = 0;
    REP(i, k) {
        ll pp = c[i].size();
        if (pp == 0) break;
        res += sc[c[i][0]];
        ll len = 0;
        REP(j, pp - 1) {
            if (c[i][j + 1] == c[i][j] && len == 0) {
                len = 1;
                continue;
            }
            len = 0;
            res += sc[c[i][j + 1]];
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5200
n = gets
hps = gets.chomp.split.map(&:to_i)

ans = hps.min
flag = true

while flag
  mods = hps.map{|e| e%ans}
  mods_wo_zero = mods.select{|e| e>0}
  if !mods_wo_zero.empty? && mods_wo_zero.min != ans
    ans = mods_wo_zero.min
    hps.map!.with_index{|e, i| (mods[i]).zero? ? e : mods[i]}
  else
    flag = false
  end
end

puts ans


Measured memory_bytes: 12292
import java.util.Scanner;

public class Main {



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

		String[] s = sc.next().split("");
		
		String ans = "Yes";
		
		if(s[0].equals(s[1]) && s[1].equals(s[2])) {
			ans = "No";
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
import Data.Char
main = do
  str <- getLine
  let x=foldl toint 0 str
  putStrLn $ (show.(`div`60).(`div`60)$x) ++":"++(show.(`mod`60).(`div`60)$x)++":"++(show.(`mod`60)$x)

toint a c = a*10+digitToInt c

Measured memory_bytes: 3420
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<long long,int> P;

int main(){
    int n;
    cin >> n;
    ll a[n+1], b[n];
    rep(i, n+1) cin >> a[i];
    rep(i, n) cin >> b[i];

    ll cnt = 0;
    rrep(i, n){
        ll tmp = b[i] - a[i+1];
        if (tmp >= 0){
            if (a[i] - tmp >= 0){
                cnt += b[i];
                a[i] -= tmp;
            }
            else {
                cnt += a[i + 1] + a[i];
                a[i] = 0;
            }
        }
        else {
            cnt += b[i];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x)  (int)x.size()
#define en     '\n'
#define sp     ' '
#define in(v)  for(auto &a: v)cin >> a;
#define out(v) for(auto &a: v)cout << a << sp;cout << en;

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

    string str;
    cin >> str;
    cout << str;
    if(str[sz(str) - 1] == 's')cout << "es\n";
    else cout << "s\n";
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint N, x;
	cin >> N >> x;

	vector<lint> a(N);
	for (int i = 0; i < N; i++) cin >> a[i];

	lint ans = 0;
	for (int i = 0; i < N - 1; i++) {
		
		if (x - a[i] < 0) {
		
			ans += a[i + 1] + a[i] - x;
			a[i + 1] = 0;
		}
		else if (a[i + 1] - (x - a[i]) > 0) {
			ans += a[i + 1] - (x - a[i]);
			a[i + 1] -= a[i + 1] - (x - a[i]);
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n;
vector<ll>a;
int main(){
	cin>>n;
	string s="";
	while(n>0){
		n--;
		char c='a'+n%26;
		s=c+s;
		n/=26;
	}
	cout<<s;
	return 0;
}


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

int main() {
  int n, u, v, a, b, o = 0;
  cin >> n >> u >> v;
  u--;
  v--;
  vector<vector<int>> r(n);
  vector<int> da(n);
  vector<pair<int, int>> dt(n);
  for(int i = 0; i < n - 1; i++) {
    cin >> a >> b;
    r.at(--a).push_back(--b);
    r.at(b).push_back(a);
  }
  queue<pair<int, int>> que;
  pair<int, int> p;
  dt.at(u).second = u;
  for(int i = 0; i < r.at(u).size(); i++) {
    que.push({r.at(u).at(i), u});
    dt.at(r.at(u).at(i)).first = 1;
    dt.at(r.at(u).at(i)).second = r.at(u).at(i);
  }
  while(que.size()) {
    p = que.front();
    que.pop();
    for(int i = 0; i < r.at(p.first).size(); i++) {
      if(r.at(p.first).at(i) != p.second) {
        que.push({r.at(p.first).at(i), p.first});
        dt.at(r.at(p.first).at(i)).first = dt.at(p.first).first + 1;
        dt.at(r.at(p.first).at(i)).second = r.at(p.first).at(i);
      }
    }
  }
  for(int i = 0; i < r.at(v).size(); i++) {
    que.push({r.at(v).at(i), v});
    da.at(r.at(v).at(i)) = 1;
  }
  while(que.size()) {
    p = que.front();
    que.pop();
    for(int i = 0; i < r.at(p.first).size(); i++) {
      if(r.at(p.first).at(i) != p.second) {
        que.push({r.at(p.first).at(i), p.first});
        da.at(r.at(p.first).at(i)) = da.at(p.first) + 1;
      }
    }
  }
  sort(dt.begin(), dt.end(), greater<pair<int, int>>());
  for(int i = 0; i < n; i++) {
    if(dt.at(i).first < da.at(dt.at(i).second)) {
      o = max(o, dt.at(i).first +
                     max(0, da.at(dt.at(i).second) - dt.at(i).first - 1));
    }
  }
  cout << o << endl;
}

Measured memory_bytes: 7168
import java.util.*;
import java.io.*;

public class Main{

  public static void main(String[] args) {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))){
      String[] NMQ = in.readLine().split(" ");
      int N = Integer.parseInt(NMQ[0]);
      int M = Integer.parseInt(NMQ[1]);
      int Q = Integer.parseInt(NMQ[2]);

      boolean[][] S = new boolean[N][M];
      for(int i = 0; i < N; i++){
        String a =  in.readLine();
        for(int j = 0; j < M; j++){
          if (a.charAt(j) == '1'){
            S[i][j] = true;
          }
        }
      }

      int[][] V = new int[N][M];
      int[][] H = new int[N][M];
      int[][] E = new int[N][M];

      for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
          V[i][j] = (i-1 < 0 ? 0 : V[i-1][j]) + (j-1 < 0 ? 0 : V[i][j-1] + (S[i][j] && S[i][j-1] ? 1 : 0)) - (i-1 < 0 || j-1 < 0 ? 0 : V[i-1][j-1]);
          H[i][j] = (i-1 < 0 ? 0 : H[i-1][j] + (S[i][j] && S[i-1][j] ? 1 : 0)) + (j-1 < 0 ? 0 : H[i][j-1]) - (i-1 < 0 || j-1 < 0 ? 0 : H[i-1][j-1]);
          E[i][j] = (i-1 < 0 ? 0 : E[i-1][j]) + (j-1 < 0 ? 0 : E[i][j-1]) - (i-1 < 0 || j-1 < 0 ? 0 : E[i-1][j-1]) + (S[i][j] ? 1 : 0);
        }
      }

      for (int q = 0; q < Q ; q++) {
        String[] a =  in.readLine().split(" ");
        int x1 = Integer.parseInt(a[0]) - 1;
        int y1 = Integer.parseInt(a[1]) - 1;
        int x2 = Integer.parseInt(a[2]) - 1;
        int y2 = Integer.parseInt(a[3]) - 1;

        int e = E[x2][y2] - (x1-1 < 0 ? 0 : E[x1-1][y2]) - (y1-1 < 0 ? 0 : E[x2][y1-1]) + (x1-1 < 0 || y1-1 < 0 ? 0 :E[x1-1][y1-1]);
        int v = V[x2][y2] + (x1-1 < 0 ? 0 : -V[x1-1][y2] + V[x1-1][y1]) - V[x2][y1];
        int h = H[x2][y2] - H[x1][y2] + (y1-1 < 0 ? 0 : -H[x2][y1-1] + H[x1][y1-1]);

        System.out.println(e-v-h);
      }

    }catch(IOException e){
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 152036
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

int N;
int parents[25];
bool visited[1<<24];
bool used[24];
int x[25], y[25], r[25], c[25];


bool overlap(int a, int b)
{
    int dist = (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]);

    return (dist < (r[a] + r[b]) * (r[a] + r[b]) );
}

bool isTop(int a)
{
    int p = parents[a];
    for(int i=0; i<N; i++) {
	if( p & (1<<i) ) {
	    if ( used[i] == false ) return false;
	}
    }

    return true;
}

void make_tree()
{
    memset(parents, 0, sizeof(parents));
    
    for(int i=0; i<N; i++) {
	for(int j=0; j<i; j++) {
	    if(overlap(i,j) == true) parents[i] |= (1<<j);
	}
    }
}

int hash()
{
    int res = 0;

    for(int i=0; i<N; i++)
	if(used[i]) res += (1<<i);

    return res;
}


int solve(int cnt)
{
    int res = cnt;
    
    for(int i=0; i<N; i++)
	for(int j=i+1; j<N; j++) {
	    if(used[i] || used[j]) continue;
	    if(c[i] != c[j]) continue;
	    if(!isTop(i) || !isTop(j)) continue;

	    used[i] = used[j] = true;

	    int h = hash();

	    if ( !visited[h] ) {
		visited[h] = true;
		res = max(res, solve(cnt + 2) );
	    }

	    used[i] = used[j] = false;
	}

    return res;
}

int main()
{
    while(cin >> N, N) {
	for(int i=0; i<N; i++) {
	    cin >> x[i] >> y[i] >> r[i] >> c[i];
	}

	memset(used, 0, sizeof(used));
	memset(visited, 0, sizeof(visited));
	
	make_tree();
	cout <<  solve(0) << endl;
    }
}

	

	    
		
		

Measured memory_bytes: 0
n=gets.to_i
a=gets.split.map(&:to_i)
index=0
v=a.inject(&:+)
result=[]
left=0
while index<=a.length-2
   
    left+=a[index]
    right=v-left
    result<<(left-right).abs
    

index+=1
end
p result.min

Measured memory_bytes: 28944
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		long sum = 0, ans = 0, ans2 = 0;
		// 偶数位置までの和：正、奇数位置までの和：負
		for(int i = 0 ; i < n ; i++) {
			if(i % 2 == 0) {
				if(sum + a[i] >= 0) {
					ans += sum + a[i] + 1;
					sum = -1;
				} else {
					sum += a[i];
				}
			} else {
				if(sum + a[i] <= 0) {
					ans += 1 - (sum + a[i]);
					sum = 1;
				} else {
					sum += a[i];
				}
			}
		}
		sum = 0;
		// 偶数位置までの和：正、奇数位置までの和：負
		for(int i = 0 ; i < n ; i++) {
			if(i % 2 == 1) {
				if(sum + a[i] >= 0) {
					ans2 += sum + a[i] + 1;
					sum = -1;
				} else {
					sum += a[i];
				}
			} else {
				if(sum + a[i] <= 0) {
					ans2 += 1 - (sum + a[i]);
					sum = 1;
				} else {
					sum += a[i];
				}
			}
		}
		System.out.println(Math.min(ans, ans2));
	}
}


Measured memory_bytes: 50564
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int L = cin.nextInt();
        int[] A = cin.ArrayInt(N);
        for (int i = 0; i < N - 1; i++)
        {
            if(A[i] + A[i+1] >= L)
            {
                Console.WriteLine("Possible");
                for (int j = 1; j <= i; j++)
                {
                    Console.WriteLine(j);
                }
                for (int j = N - 1; j > i; j--)
                {
                    Console.WriteLine(j);
                }
                return;
            }
        }
        Console.WriteLine("Impossible");
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;
typedef vector<unordered_map<lli,lli>> graph;

lli n;
vll a,b;
lli ans = 0;

int main(){
  cin >> n;
  a = vll(n+1);
  b = vll(n+1);
  for(lli i = 0;i < n;i++) cin >> a[i];
  for(lli i = 0;i < n;i++) cin >> b[i];
  for(lli i = 0;i < n;i++) a[i+1] += a[i];
  for(lli i = 0;i < n;i++) b[i+1] += b[i];
  ans = a[0] + b[n];
  for(lli i = 1;i < n;i++){
    ans = max(ans,a[i]+b[n]-b[i-1]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e3+7;
int c[N];
int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int n,a,b;
	cin>>n>>a>>b;
	for(int i = 1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int dis = 0;
			if(j<=a) dis = j-i;
			else if(i>=b) dis = j-i;
			else if(i>=a&&j<=b) dis = min(j-i,b-j+1+i-a);
			else if(i>=a&&i<=b&&j>=b) dis = min(j-i,i-a+1+j-b);
			else if(i<=a&&j>=a&&j<=b) dis = min(j-i,b-j+1+a-i);
			else if(i<=a&&j>=b) dis = j-i-(b-a)+1;
			c[dis]++; 
		}
	}
	for(int i=1;i<n;i++){
		cout<<c[i]<<endl;
	}
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const int N = 55;
int n, a;
ll dp[N][N * N];
ll ans;

int main() {
	cin >> n >> a;
	dp[0][0] = 1;
	for(int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		for(int j = i - 1; j >= 0; j--)
			for(int k = 0; k <= N * j; k++) dp[j + 1][k + x] += dp[j][k];
	}
	for(int i = 1; i <= n; i++) ans += dp[i][i * a];
	cout << ans << endl;
}

Measured memory_bytes: 1024
//Let's play :)
#include<bits/stdc++.h>
using namespace std;

#define tarzan ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long 

int rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
int cc[] = {1, 1, 0, -1, -1, -1, 0, 1};

const int mod = 1e9 + 7;
const int N = 300050;

signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    tarzan;
    int test = 1;
    //cin >> test;
    while(test--) {
        string s;
        cin >> s;
        if(s[0] == s[1] && s[1] == s[2]) {
            cout << "No";
        }
        else cout << "Yes";
    }
    return 0;
}

Measured memory_bytes: 384
n,m = map(int,input().split())
x = [int(i) for i in input().split()]
x.sort()
memo = []
for i in range(m-1):
    memo.append(x[i+1]-x[i])
memo.sort()
ans = 0
for i in range(m-n):
    ans += memo[i]
print(ans)

Measured memory_bytes: 56872
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 1000000000;
typedef pair<int, int> P;
const int MAX_N = 1000000000;
typedef int64_t ll;
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 A, B;
	cin >> A >> B;
	for (int i = 10; i <= 1009; i++)
	{
		int c = i * 0.08;
		int d = i * 0.1;
		if (c==A && d==B)
		{
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 3632
import numpy as np


def main():
	#N, D = [int(x) for x in input().split()]
	S = input()
	T = input()

	count = 0
	for s, t in zip(S, T):
		if s == t:
			count += 1
	print(count)
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 21628
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] b = Console.ReadLine().Split();
            int A = int.Parse(b[0]); int B = int.Parse(b[1]); int C = int.Parse(b[2]);
            int a;
            if (B / A > C) { a = C; }
            else { a = B / A; }
            Console.Write(a);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,N;
  string s;
  bool p = true;
  cin >> N;
  
  for(i=0;i<N;i++){
    cin >> s;
    if(s == "Y"){
      p = false;
      break;
    }
  }
  if(p == true) cout << "Three" << endl;
  else cout << "Four" << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;
string s, sr, sl;
int xcntl, mem, l, r, cnt;

int main() {
	cin >> s;
	lp(s.size()) {
		if (s[i] != 'x')sl += s[i];
	}
	for (int i = s.size() - 1; i >= 0; i--) {
		if (s[i] != 'x')sr += s[i];
	}
	if (sl != sr) {
		cout << -1 << endl;
		return 0;
	}
	xcntl = 0;
	mem = sr.size();
	sl = sr = "";
	for (int i = 0; i - xcntl != ((mem % 2) ? mem / 2 + 1 : mem / 2); i++) {
		if (s[i] == 'x')xcntl++;
		 sl += s[i];
	}
	for (int i = s.size() - 1; i != mem / 2 + xcntl-1; i--) {
		sr += s[i];
	}
	l = r = cnt = 0;
	while (l != sl.size()) {
		if (sl[l] == sr[r]) {
			l++;
			r++;
		}
		else if (sl[l] == 'x') {
			cnt++;
			l++;
		}
		else {
			cnt++;
			r++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);
#define eps 1e-9



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	int x,y;

	cin>>n>>m>>k>>x>>y;

	if(x<y){
        swap(x,y);
        swap(n,m);
	}

	int sum1=(x*n+y*m);
	int sum2=(k*2*x);
	int sum3=(k*2*y)+(x-y)*n;

	cout<<min(sum1,min(sum2,sum3))<<endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const lli inf=1e18;
const int mod=1e9+7;
int main(){
IOS;
int a,b;
cin>>a>>b;
if((a>=1&&a<=9)&&(b>=1&&b<=9))
    cout<<a*b<<endl;
else cout<<-1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e9
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
ll n, m, x, cnt_odd[100001], cnt[100001], ans;
 
int main()
{
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		cin >> x;
		cnt[x]++;
		if(cnt[x]%2){
			cnt_odd[x%m]++;
		}
		else{
			cnt_odd[x%m]--;
		}
	}
	if(m%2==0){
		x=0;
		for(int i = 0; i*m <= 100000; i++){
			x+=cnt[i*m];
		}
		ans+=x/2;
		x=0;
		for(int i = 0; i*m+m/2 <= 100000; i++){
			x+=cnt[i*m+m/2];
		}
		ans+=x/2;
		for(int i = 1; i < m/2; i++){
			x=min(cnt_odd[i],cnt_odd[m-i]);
			cnt_odd[i]-=x;
			cnt_odd[m-i]-=x;
			ans+=x;
			if(cnt_odd[i]==0 && cnt_odd[m-i]==0){
				for(int j = 0; i+j*m<=100000; j++){
					ans+=cnt[i+j*m]/2;
				}
				for(int j = 0; m-i+j*m<=100000; j++){
					ans+=cnt[m-i+j*m]/2;
				}
			}
			else if(cnt_odd[i]==0){
				for(int j = 0; i+j*m <= 100000; j++){
					if(cnt[i+j*m]%2){
						cnt[i+j*m]--;
					}
					x=min(cnt_odd[m-i],cnt[i+j*m]);
					ans+=x;
					cnt_odd[m-i]-=x;
					cnt[i+j*m]-=x;
					ans+=cnt[i+j*m]/2;
				}
				for(int j = 0; m-i+j*m <= 100000; j++){
					ans+=cnt[m-i+j*m]/2;
				}
			}
			else{
				for(int j = 0; m-i+j*m <= 100000; j++){
					if(cnt[m-i+j*m]%2){
						cnt[m-i+j*m]--;
					}
					x=min(cnt_odd[i],cnt[m-i+j*m]);
					ans+=x;
					cnt_odd[i]-=x;
					cnt[m-i+j*m]-=x;
					ans+=cnt[m-i+j*m]/2;
				}
				for(int j = 0; i+j*m <= 100000; j++){
					ans+=cnt[i+j*m]/2;
				}
			}
		}
	}
	else{
		x=0;
		for(int i = 0; i*m <= 100000; i++){
			x+=cnt[i*m];
		}
		ans+=x/2;
		for(int i = 1; i <= m/2; i++){
			x=min(cnt_odd[i],cnt_odd[m-i]);
			cnt_odd[i]-=x;
			cnt_odd[m-i]-=x;
			ans+=x;
			if(cnt_odd[i]==0 && cnt_odd[m-i]==0){
				for(int j = 0; i+j*m<=100000; j++){
					ans+=cnt[i+j*m]/2;
				}
				for(int j = 0; m-i+j*m<=100000; j++){
					ans+=cnt[m-i+j*m]/2;
				}
			}
			else if(cnt_odd[i]==0){
				for(int j = 0; i+j*m <= 100000; j++){
					if(cnt[i+j*m]%2){
						cnt[i+j*m]--;
					}
					x=min(cnt_odd[m-i],cnt[i+j*m]);
					ans+=x;
					cnt_odd[m-i]-=x;
					cnt[i+j*m]-=x;
					ans+=cnt[i+j*m]/2;
				}
				for(int j = 0; m-i+j*m <= 100000; j++){
					ans+=cnt[m-i+j*m]/2;
				}
			}
			else{
				for(int j = 0; m-i+j*m <= 100000; j++){
					if(cnt[m-i+j*m]%2){
						cnt[m-i+j*m]--;
					}
					x=min(cnt_odd[i],cnt[m-i+j*m]);
					ans+=x;
					cnt_odd[i]-=x;
					cnt[m-i+j*m]-=x;
					ans+=cnt[m-i+j*m]/2;
				}
				for(int j = 0; i+j*m <= 100000; j++){
					ans+=cnt[i+j*m]/2;
				}
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define INF 9223372036854775807
#define MOD 1000000007
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0;
string s;
bool flag;
#pragma endregion
#define MAX 111111


char c[333][333];
int main(void) {
  cin >> n;
  FOR(i, 0, n) {
	FOR(j, 0, n) {
	  cin >> c[i][j];
	}
  }

  FOR(i, 0, n) {
	flag = true;
	FOR(j, 0, n) {
	  FOR(k, 0, n) {
		if (c[j][(k + i) % n] != c[k][(j + i) % n]) flag = false;
	  }
	}
	if (flag) ans += n;
  }
  cout << ans << endl;

  return 0;
}

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define show_table(n, k, table) rep(i,n){ rep(j,k) cout << table[i][j] << " "; cout << endl;}

using namespace std;

template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 100005;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,M; cin >> N >> M;
  if(N==1LL&&M==1LL){
    cout << 1 << endl;
  }else if(N==1LL || M==1LL){
    if(M==1LL) swap(N,M);
    cout << M-2 << endl;
  }else{
    cout << (N-2)*(M-2) << endl;
  }
  return 0;
}

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

int main() {
    string s;
    cin >> s;
    int n = s.length();
    bool ans = true;

    for(int i = 0; i < n/2; i++) {
        if(s[i] != s[n/2 + i + 1]) {
            ans = false;
            break;
        }
    }

    if(ans) {
        cout << "Yes";
    }else{
        cout << "No";
    }

}

Measured memory_bytes: 256
INF = 10 ** 20

n, w = map(int, input().split())

value = []
weight = []

for _ in range(n):
  vi, wi = map(int, input().split())
  value.append(vi)
  weight.append(wi)

sum_value = sum(value)

dp = [INF for _ in range(sum_value + 1)]
dp[0] = 0

for i in range(n):
  for j in range(sum_value, value[i] - 1, -1):
    dp[j] = min(dp[j], dp[j - value[i]] + weight[i])

for j in range(sum_value, -1, -1):
  if dp[j] <= w:
    print(j)
    break


Measured memory_bytes: 5716
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N,K; cin >> N >> K;
    veci A(N);
    REP(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    int ans = 0;
    REP(i,K) ans += A[i];
    cout << ans << endl;
}

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

int main(){
    ll A, B, C;
    cin >> A >> B;
    if((A * B) % 2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    (n, m) = tuple(map(int, input().split()))
    if n == 0:
        break
    arr = [0 for i in range(m + 1)]
    for i in range(n):
        inp = list(map(int, input().split()))
        arr[inp[0]] = max(inp[1], arr[inp[0]])
    res = 0
    for e in arr:
        res += e
    print(res)



Measured memory_bytes: 5620