akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    int R, S, P;
    cin >> R >> S >> P;
    string T;
    cin >> T;
    int r = 0, s = 1, p = 2;
    vector<vector<int>> dp(N+1, vector<int>(3));
    char recode[N+1];
    
    for (int i=0;i<K;i++){
        int M = max({dp[i][r], dp[i][s], dp[i][p]});
        dp[i+1][r] = M;
        dp[i+1][s] = M;
        dp[i+1][p] = M;
        char t = T[i];
        if (t == 'r') {
            dp[i+1][p] += P;
            recode[i+1] = 'p';
        }else if(t == 's') {
            dp[i+1][r] += R;
            recode[i+1] = 'r';
        }else if(t == 'p'){
            dp[i+1][s] += S;
            recode[i+1] = 's';
        }
    }

    for(int i=K;i<N;i++){
        int M = max({dp[i][r], dp[i][s], dp[i][p]});
        dp[i+1][r] = M;
        dp[i+1][s] = M;
        dp[i+1][p] = M;
        char t = T[i];
        char t2 = recode[i+1-K];
        if (t == 'r' && t2 != 'p') {
            dp[i+1][p] += P;
            recode[i+1] = 'p';
        }else if(t == 's' && t2 != 'r') {
            dp[i+1][r] += R;
            recode[i+1] = 'r';
        }else if(t == 'p' && t2 != 's'){
            dp[i+1][s] += S;
            recode[i+1] = 's';
        }else{
            recode[i+1] = '.';
        }
    }

    cout << max({dp[N][r], dp[N][s], dp[N][p]}) << endl;
}

Measured memory_bytes: 5888
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var s = ReadLine();

            long ans = 0;
            for (int j = 2; j < s.Length; j += 2)
            {
                bool f = true;
                for (int i = 0; i < (s.Length - j) / 2; i++)
                {
                    if (s[i] != s[i + (s.Length - j) / 2]) f = false;
                }
                if (f)
                {
                    ans = s.Length-j;
                    break;
                }
            }

            WriteLine(ans);


            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 17544
import itertools
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n = ri()
ls1 = ril()
ls2 = ril()

patterns = list(itertools.permutations(range(1, n + 1)))
index1 = patterns.index(tuple(ls1))
index2 = patterns.index(tuple(ls2))
print(abs(index1 - index2))

Measured memory_bytes: 8052
N, K = map(int, input().split())
hlist = sorted([int(input()) for _ in range(N)], reverse=True)
ans = 10**9 + 7
for i in range(N - K + 1):
    # print(hlist[i], hlist[i + K])
    ans = min(ans, hlist[i] - hlist[i + K - 1])
print(ans)


Measured memory_bytes: 8260
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

	    int n=gi();
	    long[] s=new long[n+1];

	    long c=0;
	    for(int i=1; i<=n;i++) {
	    	s[i]=s[i-1]+gi();
	    }
	    
	    Arrays.parallelSort(s);

	    int m=1;
	    for (int i=1; i<=n;i++) {
            if(s[i]==s[i-1]) {
            	m++;
            }else{
               m=1; 
            }
            c+=m-1;
	    }

	    System.out.println(c);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pl;

ld const PI = 4*atan((ld)1);
ll const mod = 998244353;

ll add(ll x, ll y)
{
	return (x + y) % mod;
}

ll sub(ll x, ll y)
{
	return (x - y + mod) % mod;
}

ll mul(ll x, ll y)
{
	return (x * y) % mod;
}

int const N = 2e5 + 7;
ll bit[N] = {};
ll ar[N] = {};
ii range[11];

void add_bit(int x, ll val)
{
	while (x < N)
		bit[x] = add(bit[x], val), x += (x & -x);
}

ll get(int x)
{
	ll res = 0;
	while (x)
		res = add(res, bit[x]), x -= (x & -x);
	return res;
}

int main()
{
	fastio;

	int n, k;
	cin >> n >> k;

	for (int i = 1; i <= k; ++i)
		cin >> range[i].f1 >> range[i].s2;

	ar[1] = 1;
	for (int i = 1; i <= n; ++i)
	{
		//cout << i << " " << ar[i] << '\n';
		for (int j = 1; j <= k; ++j)
		{
			if (i - range[j].f1 >= 1) ar[i] = add(ar[i], get(i - range[j].f1));
			if (i - range[j].s2 - 1 >= 1) ar[i] = sub(ar[i], get(i - range[j].s2 - 1)); 
		}
		add_bit(i, ar[i]);
	}
	cout << ar[n] << '\n';
	return 0;
}


Measured memory_bytes: 6776
N, M, X= list(map(int, input().split()))
arr = [list(map(int, input().split())) for i in range(N)]

def rec(i, rikai, cost):

  flag = True
  for r in rikai:
    if r <= 0: continue
    else: flag = False
  if flag:
    return cost
  if i == N:
    return 10000000000000
  
  use_rikai = [ rikai[j] - arr[i][j+1] for j in range(M) ]
  use_cost = cost + arr[i][0]
  return min(rec(i+1, use_rikai, use_cost), rec(i+1, rikai,cost))

rikai = [X for j in range(M)]
res = rec(0, rikai, 0)
if res >= 10000000000000:
  print(-1)
else: print(res)

Measured memory_bytes: 9172
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,z,ans,sum;
int dp[32800][16],p[32800],c[16][16];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		scanf("%d%d%d",&x,&y,&z);
		x--; y--;
		c[x][y]=c[y][x]=z;
		sum+=z;
	}
	memset(dp,233,sizeof(dp));
	for (int i=0;i<(1<<n);i++)
		for (int j=0;j<n;j++)
			if ((i>>j)&1)
			for (int k=j+1;k<n;k++)
				if ((i>>k)&1) p[i]+=c[j][k];
	dp[1][0]=0;
	for (int i=0;i<(1<<n);i++)
		for (int j=0;j<n;j++)
			if (((i>>j)&1)&&dp[i][j]>=0){
				int x=(((1<<n)-1)^i)|(1<<j);
				for (int y=x;;y=(y-1)&x){
					dp[i|y][j]=max(dp[i|y][j],dp[i][j]+p[y]);
					if (!y) break;
				}
				for (int k=0;k<n;k++){
					if (((i>>k)&1)||c[j][k]==0) continue;
					dp[i|(1<<k)][k]=max(dp[i|(1<<k)][k],dp[i][j]+c[j][k]);
				}
			}
	ans=1e9;
	for (int i=0;i<(1<<n);i++)
		ans=min(ans,sum-dp[i][n-1]);
	printf("%d",ans);
}

Measured memory_bytes: 2432
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d", &tmp);v.push_back(tmp);}}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, m, X, Y;
  cin >> n >> m >> X >> Y;
  
  int max_x = -INF, min_y = INF;
  REP(i,n){
    int tmp;
    cin >> tmp;
    max_x = max(max_x, tmp);
  }
  REP(i,m){
    int tmp;
    cin >> tmp;
    min_y = min(min_y, tmp);
  }
  FOR(i,X+1,Y+1){
    if(min_y >= i && max_x < i){
      cout << "No War\n";
      return 0;
    }
  }
  cout << "War\n";
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  int n;
  cin>>n;
  cout<<"ABC"<<n<<endl;
}

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

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

bool is_prime(int c) {
  if (c == 2) return true;
  if (c < 2 || c % 2 == 0) return false;
  
  for (int i = 2; i * i <= c; i ++)
    if (c % i == 0) return false;

  return true;
}

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

  int cnt = 0;
  rep(i, n) {
    int c;
    cin >> c;
    
    if (is_prime(c)) cnt++;
  }

  cout << cnt << endl;
}



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
typedef long long ll;
int ans, zan;
const ll mod = 1000000007;
string s;

ll pow(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return pow(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = pow(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return pow(x, mod - 2);
}

int main(void)
{
	cin >> s;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'A' || s[i] == 'G' || s[i] == 'C' || s[i] == 'T')
		{
			zan++;
		}
		else
		{
			ans = max(ans, zan);
			zan = 0;
		}
	}
	ans = max(ans, zan);
	cout << ans << endl;
	int www;
	cin >> www;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

ll combination(ll x);


int main() {

    ll N;

    cin >> N;


    vector<string> S(N);

    rep(i, N) {
        cin >> S[i];
        sort(S[i].begin(), S[i].end());
    }

    ll a, b;
    a = S.size();

    sort(S.begin(), S.end());

    S.push_back("end");

    string tmp = "aa";
    ll count = 0, ans = 0;

    rep(i, N + 1) {
        if (tmp == S[i]) {
            count++;
        }
        else {
            if (count > 1) {
                ans += combination(count);
            }
            count = 1;
            tmp = S[i];
        }
    }

    cout << ans;
    
    return 0;
}

ll combination(ll x) {
    ll ans;
    ans = x * (x - 1) / 2;
    return ans;
}


Measured memory_bytes: 7584
/*
  #問題：
  


  # 分析：
  # オブジェクト：

  初項s, 
  
  
  
  # 条件：
  

  # 要求：
  

  # 解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;


int main(void){
  int s,cnt=2;                  // cntは
  cin>>s;

  vector<int> array(1000000,0);
  array[1] = s;
  
  while(1){
    if(0==s%2){
      s = s/2;
      // cout<<s<<endl;
    }else{
      s = 3*s+1;
      // cout<<s<<endl;            // 
    }
    

    auto itr = find(array.begin(),array.end(), s); // arrayの中からsを探す．
    if (itr == array.end() ){                      // arrayの中にsが存在しなかった場合，
      
    }else{
      cout<<cnt<<endl;
      return 0;
    }
    array[cnt] = s;
    cnt++;
  }
}



Measured memory_bytes: 4096
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                Map hs = new HashMap();
                int n = sc.nextInt();
                String[] q = new String[n];
                for(int i = 0 ; i < n ; i++){
                        q[i] = sc.next();
                }
                sc.close();
                for(String s : q){
                        int c = 0;
                        if(hs.containsKey(s)) c = (int)hs.get(s);
                        hs.put(s , c + 1);
                }
                int[] qq = {0};
                hs.forEach((s , c) -> {
                        qq[0] = Math.max(qq[0] , (int)c);
                });
                String[] u = new String[n];
                int[] yono = {0};
                hs.forEach((s , cc) -> {
                        if((int)cc == qq[0]){
                                u[yono[0]] = (String)s;
                                yono[0]++;
                        }
                });
                String[] it = new String[yono[0]];
                for(int i = 0 ; i < yono[0] ; i++){
                        it[i] = u[i];
                }
                Arrays.sort(it);
                for(int i = 0 ; i < yono[0] ; i++){
                        System.out.println(it[i]);
                }
        }
}

Measured memory_bytes: 80996
#include <algorithm>
#include <iostream>
#include <set>
#include <tuple>
#include <unordered_map>
#include <vector>

using std::set;
using std::multiset;
using std::tuple;
using std::vector;
using std::unordered_map;

int solve(int N, const vector<int> &A)
{
	multiset<int> set;
	for (int a : A)
	{
		if (!set.empty() && a > *set.cbegin())
		{
			auto it = set.lower_bound(a);
			set.erase(--it);
		}
		set.emplace(a);
	}
	return set.size();
}

int main(int argc, char *argv[])
{
	int N;
	std::cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) { std::cin >> A[i]; }
	std::cout << solve(N, A) << std::endl;
	return 0;
}


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

int main() {
  string S;
  cin>>S;
  if(S[0]=='S') {
    if(S[1]=='S') {
      if(S[2]=='S') {
        cout<<0;
      } else cout<<1;
    } else if(S[2]=='S') {
      cout<<1;
    } else cout<<2;
  } else if(S[1]=='S') {
    cout<<1;
  } else if(S[2]=='R') {
    cout<<3;
  } else cout<<2;
  cout<<"\n";
}


Measured memory_bytes: 3588
#include <stdio.h>

int main(void)
{
	int a,b,k;
	
	scanf("%d%d%d",&a,&b,&k);
	
	int x=0;
	int	y=k;
	int i=0;
	while(x<k&&a+x<b-k+1){
		printf("%d\n",a+x);
		x++;
	}
	
	while(y!=0){
		if(b-y+1>=a){
		printf("%d\n",b-y+1);
		}
		y--;
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
int main()
{
    string s;
    cin >> s;
    bool ss = true;
    if (s.size() % 2 != 0)
        ss = false;

    rp(i, 0, s.size() - 1)
    {
        if (s[i] != 'h' || s[i + 1] != 'i')
        {
            ss = false;
        }
        i++;
    }
    if (ss)

        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
ll a[100100];
int b[100100];
ll c[100100];

ll solve() {
    sort(a, a+n);
    vector<P> vec(m);
    for (int i = 0; i < m; i++) {
        vec[i]  = P(c[i], b[i]);
    }
    sort(RALL(vec));
    
    int idx = 0;
    for (int i = 0; i < m; i++) {
        int cnt = 0;
        while (idx < n && cnt < vec[i].second && a[idx] < vec[i].first) {
            a[idx] = vec[i].first;
            cnt++;
            idx++;
        }
    }
    
    ll res = 0;
    for (int i = 0; i < n; i++) res += a[i];
    return res;
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) {
        cin >> b[i] >> c[i];
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010
#define SUBMIT

ll T1, T2, A1, A2, B1, B2;

ll brute_force() {
    const ll border = 100000000000000000LL;
    ll cur_a = A1 * T1;
    ll cur_b = B1 * T1;
    ll prev_a = cur_a;
    ll prev_b = cur_b;
    ll ret = (cur_a == cur_b) ? 1 : 0;
    ll turn = 0;
    while(1) {
        if(turn % 2 ==0) {
            cur_a += A2 * T2;
            cur_b += B2 * T2;
            if(cur_a == cur_b) { return -1; }
        }
        else {
            cur_a += A1 * T1;
            cur_b += B1 * T1;
        }
        if(prev_a > prev_b) {
            if(cur_a <= cur_b) { ret++; }
            else { break; }
        }
        if(prev_a < prev_b) {
            if(cur_a >= cur_b) { ret++; }
            else { break; }
        }
        turn++;
        if(cur_a > border) {
            cur_a -= border;
            cur_b -= border;
        }
        prev_a = cur_a;
        prev_b = cur_b;
    }
    return ret;
}

ll solve() {
    ll a1 = T1 * A1;
    ll b1 = T1 * B1;
    ll a2 = T2 * A2;
    ll b2 = T2 * B2;

    ll X = a1 - b1;
    ll Y = a2 - b2;


    if(X + Y == 0) {
        return -1;
    }

    if((X < 0 && Y < 0) || (X > 0 && Y > 0) || Y == 0) {
        return 0;
    }

    if(X == 0) {
        return 1;
    }

    X = abs(X);
    Y = abs(Y);
    if(X > Y) {
        //swap(X, Y);
        return 0;
    }

    ll ret = X / (Y - X) * 2 + 1;
    if(X % (Y - X) == 0) {
        ret = X / (Y - X) * 2;
    }
    return ret;
}

signed main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
#ifdef SUBMIT
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    ll ans = solve();
    //ll ans = brute_force();
    if(ans == -1) {
        printf("infinity\n");
        return 0;
    }
    printf("%lld\n", ans);
#else
    for(T1 = 1; T1 < 10; ++T1) {
        for(T2 = 1; T2 < 10; ++T2) {
            for(A1 = 1; A1 < 10; ++A1) {
                for(A2 = 1; A2 < 10; ++A2) {
                    for(B1 = 1; B1 < 10; ++B1) {
                        for(B2 = 1; B2 < 10; ++B2) {
                            ll ans = brute_force();
                            ll cand = solve();
                            if(ans != cand) {
                                printf("%lld %lld\n", T1, T2);
                                printf("%lld %lld\n", A1, A2);
                                printf("%lld %lld\n", B1, B2);
                                printf("ans: %lld cand: %lld\n", ans, cand);
                                return 0;
                            }
                        }
                    }
                }
            }
        }
    }
#endif
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  char s[2]={0};
  scanf("%s",s);
  if	 (s[0]=='A'){ printf("T\n"); }
  else if(s[0]=='T'){ printf("A\n"); }
  else if(s[0]=='C'){ printf("G\n"); }
  else if(s[0]=='G'){ printf("C\n"); }
  return 0;
}


Measured memory_bytes: 1636
n = int(input())
a = [i-1 for i in map(int, input().split())]
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
prev_ind = 50
for i in a:
    ans += b[i]
    if prev_ind + 1 == i:
        ans += c[prev_ind]
    prev_ind = i

print(ans)

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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


const int MOD = 1000000007;
const int nMax = 2e6;

long long fact[nMax];  // Array of Factorial
long long invFact[nMax]; // Array of Factorial of Inverse Elements
long long inv[nMax]; // Array of Inverse Elements

void calcFact(){
    fact[0] = 1; fact[1] = 1;
    invFact[0] = 1; invFact[1] = 1;
    inv[1] = 1;     //1に対する逆元は1
    
    for(int i = 2; i < nMax; i++){
        fact[i] = fact[i-1] * i % MOD;
        inv[i] = (- inv[MOD % i] * (MOD/i) ) % MOD + MOD;
        invFact[i] = invFact[i-1] * inv[i] % MOD;
    }   
}
    
long long calcComb(long long _n, long long _k){
    if (_n < 0 || _k < 0) return 0;
    if (_n < _k) return 0;
    return fact[_n] * (invFact[_n-_k] * invFact[_k] % MOD) % MOD;
}


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int x, y;
    cin >> x >> y;
    if((2*y-x)%3 != 0 || (2*x-y)%3 != 0){
        cout << "0" << endl;
        return 0;
    }

    int a = (2*y-x)/3;
    int b = (2*x-y)/3;

    calcFact();

    ll ans = calcComb((ll)(a+b), (ll)a);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 47104
let n = Int(readLine()!)!
var a: [Int] = .init(repeating: 0, count: n)
for i in 0..<n {
  a[i] = Int(readLine()!)!
}
var ans: [Int] = []

func binarySearch(_ a: [Int], _ target: Int) -> Int {
  var left = 0
  var right = ans.count - 1
  var ans = a.count
  while left <= right {
    let mid = left + (right - left) / 2
    if target > a[mid] {
      ans = mid
      right = mid - 1
    } else {
      left = mid + 1
    }
  }
  return max(ans, 0)
}

for i in 0..<n {
  let ai = a[i]
  let index = binarySearch(ans, ai)
  if index >= ans.count {
    ans.append(ai)
  } else {
    ans[index] = ai
  }
}
print(ans.count)

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

int main(){
  int n,active = 0,cnt= 0;
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i<n; i++)
    cin >> h.at(i);
  for(int i = 0; i < n; i++){
    if(active >= h.at(i)){
      active = h.at(i);
    }
    else{
      cnt += h.at(i) - active;
      active = h.at(i);
    }
  }
    cout << cnt << endl;
}

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

using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  if (A == B) {
    cout << C << endl;
  }  else if (B == C) {
    cout << A << endl;
  } else {
    cout << B << endl;
  }

  return 0;
}

Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>a>>b>>c>>d>>n;
    a=a*60+b;
    c=c*60+d;
    c=c-a;
    if(c-n<=0) cout<<0<<endl;
    else cout<<c-n<<endl;

    return 0;
}


Measured memory_bytes: 3640
#include <cstdio>
int main() {
	int s[30]={0},n;
	for(int i=0;i<28;i++) {
		scanf("%d",&n);
		s[n-1]=1;
	}
	for(int i=0;i<30;i++) {
		if(!s[i])printf("%d\n",i+1);
	}
}

Measured memory_bytes: 1024
// Running Offline
// g++ tester.cpp
// ./a.out
//#include "/Users/manasgupta/Desktop/stdc++.h"

 #include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pi pair<int,int>
#define pb push_back
#define fi first
#define se second
// #define mp make_pair
#define inf 1e9
#define EPS 1e-6
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FILEIO(name1, name2) \
    freopen(name1".txt","r",stdin); \
    freopen(name2".txt","w",stdout);

const int N=300005;
const int mod = 119 << 23 | 1;

int power(int a, int b, int c)
{
	int res=1;
	while (b)
	{
		if (b&1) res=(res*a)%c;
		a=(a*a)%c;
		b=b>>1;
	}
	return res;
}

int n;
int a[N];
int dp[N];

signed main()
{
	IOS;
	cin>>n;
	for (int i=0; i<n; i++)
	{
		cin>>a[i];
	}
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for (int i=2; i<n; i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1]<<endl;
    return 0;
}





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

int main(){
    int n;
    cin >> n;
    int A[n];
    int B[n];
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        B[i] = A[i];
    }
    sort(B, B + n);
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int tgt_idx = find(A, A + n, B[i]) - A;
        int n_cycle = 1;
        while (tgt_idx != i) {
            int dst_idx = find(A, A + n, B[tgt_idx]) - A;
            cnt += A[tgt_idx] + A[dst_idx];
            swap(A[tgt_idx], A[dst_idx]);
            tgt_idx = dst_idx;
            n_cycle++;
        }
        if ((n_cycle - 3) * B[i] > (n_cycle + 1) * B[0]) {
            cnt -= (n_cycle - 3) * B[i] - (n_cycle + 1) * B[0];
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
 int k,z;
    string s;
    cin >> k>>s;
   z=s.size();
  if(k>=z){cout<<s<<endl;}
  else{for(int i=0;i<k;i++){cout<<s[i];}cout<<"..."<<endl;}
}


Measured memory_bytes: 3632
N = int(input())
A = list(map(int,input().split()))
C = {}
for i in range(N):
    a = A[i]
    if a not in C:
        C[a] = 0
    C[a] += 1
n = len(C)
if (N-n)%2==0:
    print(n)
else:
    print(n-1)

Measured memory_bytes: 88288
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AizuRangeSumQuery solver = new AizuRangeSumQuery();
        solver.solve(1, in, out);
        out.close();
    }

    static class AizuRangeSumQuery {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int q = in.nextInt();

            int[] a = new int[n];
            int[] b = new int[4 * n];

            build(0, 0, n - 1, a, b);

            while (q-- != 0) {
                int o = in.nextInt();
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;

                if (o == 0) {
                    update(0, 0, n - 1, l, r + 1, a, b);
                } else {
                    out.printf("%d\n", query(0, 0, n - 1, l, r, b));
                }
            }
        }

        private void build(int n, int s, int e, int[] a, int[] b) {
            if (s == e) {
                b[n] = a[s];
            } else {
                int m = (s + e) / 2;
                build(2 * n + 1, s, m, a, b);
                build(2 * n + 2, m + 1, e, a, b);

                b[n] = b[2 * n + 1] + b[2 * n + 2];
            }
        }

        private void update(int n, int s, int e, int idx, int val, int[] a, int[] b) {
            if (s == e) {
                a[idx] += val;
                b[n] += val;
            } else {
                int m = (s + e) / 2;
                if (s <= idx && idx <= m) {
                    update(2 * n + 1, s, m, idx, val, a, b);
                } else {
                    update(2 * n + 2, m + 1, e, idx, val, a, b);
                }

                b[n] = b[2 * n + 1] + b[2 * n + 2];
            }
        }

        private long query(int n, int s, int e, int l, int r, int[] b) {
            if (r < s || e < l) {
                return 0;
            } else if (l <= s && e <= r) {
                return b[n];
            } else {
                int m = (s + e) / 2;
                long s1 = query(2 * n + 1, s, m, l, r, b);
                long s2 = query(2 * n + 2, m + 1, e, l, r, b);

                return s1 + s2;
            }
        }

    }
}




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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x;
    cin >> n >> x;
    int sum = 0;
    int mi = 1000000;
    rep(i,n){
        int a;
        cin >> a;
        sum += a;
        if(mi > a) mi = a;
    }
    cout << n + (x - sum)/mi << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main() {
    vector<int> vec(5);
    int maxnum = 0, ans = 0;
    cin >> vec[0] >> vec[1] >> vec[2] >> vec[3] >> vec[4];
    for(auto x : vec){
        if(x%10==0){
            ans += x;
        }else{
            maxnum = max(maxnum,(10-x%10));
            ans += x+(10-x%10);
        }
    }
    cout << ans-maxnum << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

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

int main(){
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];
	vector<vi> v(h, vi(w, 0));
	queue<int> q;
	rep(i, n) rep(j, a[i]) q.push(i+1);
	auto isOutOfRange = [](int h, int w, int H, int W) {
		return h < 0 || h >= H || w < 0 || w >= W;
	};
	
	int y = 0, x = 0;
	while(!q.empty()) {
		int p = q.front(); q.pop();
		//cout << " " << y <<" " << x << " " << p << endl;
		v[y][x] = p;
		int nx = x + (y&1?-1:1);
		if(nx < 0 || nx >= w) {
			nx = x;
			y++;
		}
		x = nx;
	}
	rep(i, h) {
		rep(j, w) {
			cout << v[i][j];
			if(j == w-1) cout<< endl;
			else cout << " ";
		}
	}
}


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

int dig, sum, ans;

void solve(long long N, long long A, long long B){
    ans = 0;
    for(int i = 1; i <= N; ++i){
        sum = 0;
        int t = i;
        for(int j = 0; j < 5; ++j){
            sum = sum + t % 10;
            t = t / 10;
        }
        if(A <= sum && sum <= B) ans = ans + i;
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


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

int main() {
  int n, m, sum = 0, k;
  cin >> n >> m;
  k = m;
  vector<int> a(n);
  rep(i, n) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  rep(i, n) {
    if (a.at(i) * 4 * m >= sum) k--;
  }
  if (k <= 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
int dfs(S,d,s,n){
	if(d==0)return S==s;
	int r=0;
	for(;n<10;n++)r+=dfs(S,d-1,s+n,n+1);
	return r;
}
main(n,s){for(;scanf("%d%d",&n,&s),n|s;)printf("%d\n",dfs(s,n,0,0));exit(0);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
vector<ll> g[ohara];

//-------------------------↓↓↓↓↓↓------------------------

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

    rep(i,3){
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rrep(i,1,5){
        if(Size(g[i])>=3){
            Cout("NO");
            return 0;
        }
    }
    Cout("YES");
    return 0;
}


Measured memory_bytes: 23680
// AOJ 2265: Programming Contest Challenge Book
// 2017.10.15 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

long long a[100005];
char buf[50], *p;

int cmp(long long *a, long long *b)
{
	if (*a < *b) return 1;
	if (*a > *b) return -1;
	return 0;
}

long long getInt()
{
	long long n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int check(int i)
{
	if (a[i+4]+a[i+5] > a[i+3]) return 1;
	if (a[i+4]+a[i+5] > a[i] && a[i+3]+a[i+2] > a[i+1]) return 1;
	if (a[i+3]+a[i+5] > a[i] && a[i+4]+a[i+2] > a[i+1]) return 1;
	if (a[i+3]+a[i+4] > a[i] && a[i+5]+a[i+2] > a[i+1]) return 1;
	if (a[i+2]+a[i+5] > a[i] && a[i+4]+a[i+3] > a[i+1]) return 1;
	if (a[i+2]+a[i+4] > a[i] && a[i+5]+a[i+3] > a[i+1]) return 1;
	if (a[i+2]+a[i+3] > a[i] && a[i+5]+a[i+4] > a[i+1]) return 1;
	if (a[i+1]+a[i+3] > a[i] && a[i+5]+a[i+4] > a[i+2]) return 1;
	if (a[i+1]+a[i+4] > a[i] && a[i+5]+a[i+3] > a[i+2]) return 1;
	if (a[i+1]+a[i+5] > a[i] && a[i+4]+a[i+3] > a[i+2]) return 1;
	return 0;
}

int main()
{
	int n, i, ii;
	long long *aa, pair1, pair2;

	fgets(buf, 10, stdin); n = atoi(buf);
	aa = a, i = n; while (i--) fgets(p = buf, 40, stdin), *aa++ = getInt();
	qsort(a, n, sizeof(long long), cmp);

	// searching first triangle
	for (i = 2; i < n; i++) if (a[i-2] < a[i-1] + a[i]) {
		pair1 = a[i-2] + a[i-1] + a[i];
		break;
	}
	if (i + 3 >= n) { puts("0"); return 0; }

	if (check(ii = i-2)) pair2 = a[ii+3] + a[ii+4] + a[ii+5];
	else {
		// searching second triangle
		for (i += 3; i < n; i++) if (a[i-2] < a[i-1] + a[i]) {
			pair2 = a[i-2] + a[i-1] + a[i];
			break;
		}
		if (i == n) { puts("0"); return 0; }
	}

	printf("%lld\n", pair1 + pair2);
	return 0;
}

Measured memory_bytes: 3036
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <iterator>
#include <cmath>
using namespace std;

void func145c() {
  double ans = 0.0;
  int n;
  cin >> n;
  vector<int> x(n+1);
  vector<int> y(n+1);
  for(int i = 1; i <= n; i++) cin >> x[i] >> y[i];
  for(int i = 1; i <= n; i++) {
    for(int j = i+1; j <= n; j++) {
      ans += sqrt(pow(x[i]-x[j],2) + pow(y[i]-y[j],2))*2/n;
    }
  }
  cout << fixed << setprecision(10) << ans << "\n";
}


int main() {
  func145c();
  return 0;
}

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

using namespace std;

#define int long long
int n, inf = 1e18;
int ans[16], x[16], y[16], p[16];
vector < int > ok_x = {0}, ok_y = {0};

void dfs(int v) {
    if (v == n + 1) {
        int cur = 0;
        for (int i = 1; i <= n; ++i) {
            int t = inf;
            for (auto key : ok_x) t = min(t, abs(x[i] - key));
            for (auto key : ok_y) t = min(t, abs(y[i] - key));
            cur += t * p[i];
        }
        ans[(int)ok_x.size() + ok_y.size() - 2] = min(ans[(int)ok_x.size() + (int)ok_y.size() - 2], cur);
        return;
    }
    ok_x.push_back(x[v]);
    dfs(v + 1);
    ok_x.pop_back();
    ok_y.push_back(y[v]);
    dfs(v + 1);
    ok_y.pop_back();
    dfs(v + 1);
}

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i <= n; ++i) {
        ans[i] = inf;
    }
    for (int i = 1; i <= n; ++i) cin >> x[i] >> y[i] >> p[i];
    dfs(1);
    for (int i = 0; i <= n; ++i) {
        cout << ans[i] << '\n';
    }
    return 0;
}



Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define lowbit(x) x&-x
int c[N*10];
int n,a[N],s[N*10];
void add(int x)
{
    for(int i=x;i<=2*N;i+=lowbit(i))
		c[i]++;
}
long long query(int x)
{
    long long sum=0;
    for(int i=x;i>0;i-=lowbit(i))
		sum+=c[i];
    return sum;
}
bool check(int x)
{
    for(int i=1;i<=2*N;i++)
		c[i]=0;
    s[0]=0;
    for(int i=1;i<=n;i++)
        s[i]=s[i-1]+(a[i]>=x?1:-1);
    long long sum=0;
    for(int i=0;i<=n;i++)
	{
        sum+=query(s[i]+N);
        add(s[i]+N);
    }
    return sum>=1ll*n*(n+1)/4;
}
int main()
{
    cin>>n;
    int l=0,r=0;
    for(int i=1;i<=n;i++)
	{
        cin>>a[i];
        r=max(r,a[i]);
    }
    while(l<=r)
	{
        int mid=(l+r)/2;
        if(check(mid))
			l=mid+1;
        else
			r=mid-1;
    }
    cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 4864
INF = 10**20
def solve(n):
    inf = INF
    for i in range((n//500) + 1):
        for j in range(((n - 500*i)//300) + 1):
            if ((n - 500*i - 300*j)%200 == 0):
                a = (n - 500*i - 300*j)//200
                va = (a//5)*380*5*0.8 + (a%5)*380
                vj = (j//4)*550*4*0.85 + (j%4)*550
                vi = (i//3)*850*3*0.88 + (i%3)*850
                inf = min(inf, va+vj+vi)
    print(int(inf))
            
while True:
    n = int(input())
    if (not n):
        break
    solve(n)


Measured memory_bytes: 5612
n,m = list(map(int,input().split()))

A = [[0 for w in range(m)] for h in range(n)]
B = [0 for h in range(m)]

for i in range(n) :
	A[i] = list(map(int, input().split()))
for i in range(m) :
	B[i] = int(input())


for i in range(n):
	c = 0
	for j in range(m):
		c += A[i][j] * B[j]
	print(c)

Measured memory_bytes: 7996
///***Bismillahir Rahmanir Rahim***///

///*********************************///
///******Ashraful Haque Toni********///
///********Dept. of CSE,JnU*********///
///email:ashrafulhaquetoni@gmail.com///
///*******contact:01640690531*******///
///*********************************///


#include<bits/stdc++.h>

using namespace std;

#define         ash ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define         pb push_back
#define         mp make_pair
#define         sc(n) scanf("%d",&n);
#define         scl(n) scanf("%I64d",&n);
#define         sc2(m,n) scanf("%d%d",&m,&n);
#define         sc2l(m,n) scanf("%I64d%I64d",&m,&n);
#define         pf printf
#define         Big(x,y) max(x,y);
#define         Small(x,y) min(x,y);
#define         input(array,size) for(int i=0;i<size;i++)cin>>array[i];
#define         newline pf("\n");
#define         f(s,l,in) for(ll i=s;i<l;i+=in)
#define         Max INT_MAX
#define         Min INT_MIN
#define         pi acos(-1.0)
#define         Memset(a,val) memset(a,val,sizeof(a));

const int mod =1e9+7;
const int N =5e6+5;
typedef long long ll;



int main()
{

    ash;
    double a,b,x,y;
    cin>>a>>b>>x>>y;



     if(a==x*2.0&&b==y*2.0)
     {
         pf("%0.6f 1\n",a*b/2.0);
     }
     else
     {
         pf("%0.6f 0\n",a*b/2.0);
     }





    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (true) {
String x= sc.next();

if (x.equals("0")) break;
int ans=0;
for(int i=0;i<x.length();i++)ans += x.charAt(i)-'0';
System.out.println(ans);

}
}
}


Measured memory_bytes: 26356
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<sstream>
#include<cstdio>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<functional>
#include<iomanip>
#define LL long long
using namespace std;

int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};

struct node{
    int a[2][4],x,y,step,s;
}t1,t2;

queue<struct node> q;

map<int,int> map_;

bool judge(){
    int x=t2.x,y=t2.y;
    if(x>=0 && x<=1 && y>=0 && y<=3){
        swap(t2.a[x][y],t2.a[t1.x][t1.y]);
        t2.s=0;
        for(int i=0;i<2;i++){
            for(int j=0;j<4;j++){
                t2.s=t2.s*10+t2.a[i][j];
            }
        }
        if(!map_.count(t2.s)) return true;
    }
    return false;
}

void init(){
    for(int i=0;i<2;i++){
        for(int j=0;j<4;j++){
            t1.a[i][j]=4*i+j;
        }
    }
    t1.x=t1.y=t1.step=0;
    t1.s=1234567;
    map_[t1.s]=0;
    q.push(t1);
    while(!q.empty()){
        t1=q.front();
        q.pop();
        t2.step=t1.step+1;
        for(int i=0;i<4;i++){
            t2.x=t1.x+dir[i][0];
            t2.y=t1.y+dir[i][1];
            memcpy(t2.a,t1.a,sizeof(t1.a));
            if(judge()){
                map_[t2.s]=t2.step;
                q.push(t2);
            }
        }
    }
}

int main(void){
    init();
    while(scanf("%d",&t1.a[0][0])!=EOF){
        int i,j;
        t1.s=t1.a[0][0];
        for(i=0;i<2;i++){
            for(j=0;j<4;j++){
                if(i==0 && j==0) continue;
                scanf("%d",&t1.a[i][j]);
                t1.s=t1.s*10+t1.a[i][j];
            }
        }
        printf("%d\n",map_[t1.s]);
    }
    return 0;
}



Measured memory_bytes: 4208
<?php
 
 $a1 = 0; $a2 = 0; $a3 = 0;

    for($i = 0; $i < 10; $i++){
        fscanf(STDIN, "%d\n", $x);
        if($x > $a3){
            $a3 = $x;
        }
        if($x > $a2){
            $a3 = $a2;
            $a2 = $x;
        }
        if($x > $a1){
            $a2 = $a1;
            $a1 = $x;
        }
    }
 
    printf("%d\n%d\n%d\n", $a1, $a2, $a3);
 

Measured memory_bytes: 15300
// ＡＢＣのＡ過去問を解くだけだよ

// フォント:Electroharmonix
// x:小文字(ｘ)    X:大文字(Ｘ)
// +:プラス(＋)    &:アンド(＆)

#include <bits/stdc++.h>

using namespace std;

void Main()
{
    int a, b;
    cin >> a >> b;

    cout << max({a + b, a - b, a * b});
}

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

    //std::cout << std::fixed << std::setprecision(10);

#ifdef DEBUG_BUILD
    while (true)
	{
		Main();
		cout << std::endl;
	}
#endif

    Main();
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import numpy as np

def my_index(l, x, default=False):
        if x in l:
            return l.index(x)
        else:
            return default

lis=[]
for i in range(102):
    lis.append(i)
#print(lis)

listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
#print(listA)
 
X_=listA[0]
X=X_[0]
N=X_[1]
if N!=0:
    P =listA[1]
 
    arr = np.array(lis)
    P_max = max(P)
    P_min = min(P)-1
    arr=arr[arr<=P_max+1]
    arr=arr[arr>=P_min-1]
    lis=arr.tolist()
    for p in P:
        lis.remove(p)
    #print(lis)
    lis_=[]
    for l in lis:
        lis_.append(abs(l-X))
    #print(lis_)
    lis_min=min(lis_)
 
    print(lis[my_index(lis_, lis_min)])
else:
    print(X)

Measured memory_bytes: 27288
s=input()[::-1]
mod=10**9+7
dp=[[0]*13 for i in range(len(s))]
if s[0]=='?':
  for i in range(10):
    dp[0][i]=1
else:
  dp[0][int(s[0])]=1
now=1
for i in range(1,len(s)):
  now=(now*10)%13
  x=s[i]
  if x!='?':
    x=now*int(x)
    for j in range(13):
      dp[i][(j+x)%13]=dp[i-1][j]
  else:
    for j in range(10):
      x=now*j
      for k in range(13):
          dp[i][(k+x)%13]+=dp[i-1][k]
          dp[i][(k+x)%13]=dp[i][(k+x)%13]%mod
print(dp[-1][5]%mod)

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

int main(){
  string al="abcdefghijklnmopqrstuvwxyza";
  int i=0;
  char a;
  cin>>a;
  while (al.at(i)!=a){
    i++;
  }
  cout<<al.at(i+1);
}

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

typedef double ll;

int main() {
	int n,i,j,k;
	cin>>n>>k;
	int a[n+2];
	for(i=1;i<=n;i++)
	cin>>a[i];
	vector<int>dp(k+2,0);
	for(i=1;i<=k;i++)
	{
	    for(j=1;j<=n;j++)
	    {
	        if(i>=a[j])
	        {
	            if(dp[i-a[j]]==0)
	            dp[i]=1-dp[i-a[j]];
	        }
	    }
	}
	if(dp[k])
	cout<<"First";
	else
	cout<<"Second";
	return 0;
}

Measured memory_bytes: 3756
s_d = input()
t = input()
if len(s_d) >= len(t):
    for i in range(len(s_d) - len(t), -1, -1):
        possible = True
        for j in range(len(t)):
            if s_d[i + j] == t[j] or s_d[i + j] == "?":
                continue
            else:
                possible = False
                break
        if possible == False:
            continue
        else:
            s = s_d[:i] + t + s_d[i+len(t):]
            for k in range(len(s)):
                if s[k] == "?":
                    s = s[:k] + "a" + s[k+1:]
            break
else:
    possible = False
if possible == True:
    print(s)
else:
    print("UNRESTORABLE")


Measured memory_bytes: 3188