akhauriyash/Code-Regression huggingface dataset:
// Anve$hi $hukla
#include <bits/stdc++.h>
using namespace std;
struct ${$(){ios_base::sync_with_stdio(false);cin.tie(NULL);}}$;

typedef long long LL;
const int Maxn = 200005;

LL a[Maxn];

signed main() {
    LL n; 
    cin  >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    long long ans = 0, sum = 0;

    for(int i = 1; i <= n + 1; i++) {
        if(a[i] == 0) {
            ans += sum / 2;
            sum = 0;
        }
        else
            sum += a[i];
    }
    cout << ans << endl;
  
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int count = 0;
        for(int i = 1; i <= n; i++){
            String s = String.valueOf(i);
            int sum = 0;
            for(int j = 0; j < s.length(); j++){
                sum += Integer.parseInt("" + s.charAt(j));
            }
            if(sum >= a && sum <= b){
                count += i;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 27220
n, m = map(int, input().split())
foods = [0] * m
answers = [list(map(int, input().split()))[1:] for i in range(n)]

for answer in answers:
    for i in answer:
        foods[i - 1] = foods[i - 1] + 1

ans = 0
for i in foods:
    if i == n:
        ans += 1

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
using namespace std;

int main(){

  int x;
  cin >> x;
  cout << ( x < 1200 ? "ABC" : "ARC" ) << endl;

  return 0;
}


Measured memory_bytes: 256
a, b, m = map(int, input().split())
priceOfMicrowaves = list(map(int, input().split()))
priceOfRefrigerators = list(map(int, input().split()))
priceTable = [list(map(int,input().split())) for i in range(m)]
cheepest = priceOfMicrowaves[0] + priceOfRefrigerators[0]
for price in priceTable:
    if priceOfMicrowaves[price[0]-1]-price[2] >= cheepest:
        continue
    elif priceOfRefrigerators[price[1]-1]-price[2] >= cheepest:
        continue
    elif priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2] < cheepest:
        cheepest = priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2]
if cheepest > min(priceOfMicrowaves) + min(priceOfRefrigerators):
    cheepest = min(priceOfMicrowaves) + min(priceOfRefrigerators)
print(cheepest)


Measured memory_bytes: 38536
import java.io.*;

import java.math.BigInteger;
import java.util.*;

import java.util.ArrayList;

import java.util.Scanner;


class Main {

    /*static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

    static final int mod = 1000000007;

    public static int gcd(int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    public static boolean isPalindrome(String str)
    {

        // Pointers pointing to the beginning
        // and the end of the string
        int i = 0, j = str.length() - 1;

        // While there are characters toc compare
        while (i < j) {

            // If there is a mismatch
            if (str.charAt(i) != str.charAt(j))
                return false;

            // Increment first pointer and
            // decrement the other
            i++;
            j--;
        }

        // Given string is a palindrome
        return true;
    }*/
    public static void main(String[] args)
        {
            Scanner sc=new Scanner(System.in);



           int n=sc.nextInt();
           int m=sc.nextInt();
           String a=""+n;
            String b=""+m;
            StringBuilder sb=new StringBuilder();
            if(n>=m)
            {
                for(int i=0;i<n;i++)
                    sb.append(b);

            }
            else
            {
                for(int i=0;i<m;i++)
                    sb.append(a);
            }
            System.out.println(sb);


        }
    }



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

const int MAX = 1000000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  int x, y;
  cin >> x >> y;
  if ((x + y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }

  int n, m;
  n = (2 * y - x) / 3;
  m = (2 * x - y) / 3;
  COMinit();
  cout << COM(m + n, n) << endl;

  return 0;
}

Measured memory_bytes: 23680
#include <iostream>

using namespace std;

int main()
{
    unsigned long long res = 0;
    int n;

    cin >> n;

    for(int i=1; i <=n; i++ ){
        if(i % 3 != 0 && i%5!=0){
            res += i;
        }
    }

    cout << res << endl;

    return 0;
}

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

int main() {
  int x;
  cin>>x;
  int c=0;
                //c(c+1)/2 までの全ての座標に行ける
  while(c*(c+1)/2<x){
    c++;
  }
  
  cout<<c<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int k = 0;
    static int t = 0;
    static int[] a = null;
    
    public static void main(String[] args) throws Exception {
        k = sc.nextInt();
        t = sc.nextInt();
        
        a = new int[t];
        int aMax = 0;
        for(int i = 0; i < t; ++i) {
            a[i] = sc.nextInt();
            aMax = Math.max(aMax, a[i]);
        }
        
        int ans = Math.max(0, aMax - 1 - (k - aMax));
        System.out.println(ans);
    }
}


Measured memory_bytes: 21204
#include <iostream>
#include<vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
typedef long long ll;

using namespace std;



int main() {
    int n,m,k;
    cin>>n>>m>>k;
    vector<int>a(n);
    vector<int>b(m);
    rep(i,n)cin>>a[i];
    rep(i,m)cin>>b[i];

    ll t = 0;
    int ans = 0;
    int i = 0;
    while(t<=k&&i<n){
        t += a[i];
        i++;
    }
    rep(j,m+1){
        while(t>k&&i>0){
            i--;
            t -= a[i];
        }
        if(t>k)break;
        ans = max(ans,i+j);
        if(j==m)break;
        t += b[j];
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String string = scanner.nextLine();
		for(int i=0;i<string.length();i++) {
			char temp = string.charAt(i);
			if('a'<=temp&&temp<='z') {
				System.out.print((char)(temp-32));
			}else if('A'<=temp&temp<='Z') {
				System.out.print((char)(temp+32));
			}else {
				System.out.print(temp);
			}
		}
		System.out.println();
		scanner.close();
	}
}


Measured memory_bytes: 26892
#include<stdio.h>
void insertionSort(int A[],int N){
    int i,j,v;

    for(i=0;i<N;i++){
        if(i!=0){
            v=A[i];
            j=i-1;
            while(j>=0&&A[j]>v){
                A[j+1]=A[j];
                A[j]=v;
                j--;
            }
            for(j=0;j<N;j++){
                if(j!=N-1){
                    printf("%d ",A[j]);
                }else{
                    printf("%d\n",A[j]);
                }
            }
        }else{
            for(j=0;j<N;j++){
                if(j!=N-1){
                    printf("%d ",A[j]);
                }else{
                    printf("%d\n",A[j]);
                }
            }
        }

    }
}
int main(void){
    int i,A[100],N;

    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }

    insertionSort(A,N);

    return 0;
}


Measured memory_bytes: 2044
n, k = gets.split.map(&:to_i)
arr = [0] + gets.split.map(&:to_i)

cur = arr[1]
route = []
hash = {}
loop_ind = nil
(n + 1).times do
  break if !hash[cur].nil?

  hash[cur] = route.length
  route << cur
  cur = arr[cur]
end

if route.length >= k
  puts route[k - 1]
  return
end

loop_ind = hash[cur]
if !loop_ind.nil?
  loop_arr = route[loop_ind..-1]
  kk = (k - route.length - 1) % loop_arr.length
  cur = loop_arr[kk]
end

puts cur


Measured memory_bytes: 39508
#include<bits/stdc++.h>
using namespace std;
int n,x,dp[300001],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		ans=max(ans,dp[x]=dp[x-1]+1);
	}
	printf("%d\n",n-ans);
}


Measured memory_bytes: 1024
n, t = map(int, input().split())
a = list(map(int, input().split()))

mn = a[0]
d = {}

for x in a:
    d[x-mn] = d.get(x-mn, 0) + 1
    mn = min(mn, x)

print(max(d.items(), key=lambda x:x[0])[1])


Measured memory_bytes: 20740
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000000
#define mod 1000000007

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	ll X,ans=0;
	cin>>X;
	if(X%11>6 && X%11!=0)
		ans=(X/11+1)*2;
	else if(X%11<=6 && X%11!=0)
		ans=(X/11+1)*2-1;
	else
		ans=(X/11)*2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll  long long
#define endl '\n'
#define pi 3.14159265
int main()
{       
    IOS;
    ll n,x;
    cin>>n>>x;
    vector<ll> v(n);
    for(ll i=0;i<n;i++)
    	cin>>v[i];
    ll ans=0;
    for(ll i=1;i<n;i++)
    {
    	ll sum=v[i]+v[i-1];
    	if(sum<=x)
    		continue;
    	ll diff=sum-x;
    	ans+=diff;
    	if(v[i]>=diff)
    	{
    		v[i]-=diff;
    		continue;
    	}
    	v[i]=0;
    }
    cout<<ans;
}   

Measured memory_bytes: 1024
import java.util.*;

public class Main{
	
	char [][] map;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		init();
		while(sc.hasNext()){
			char [] c = sc.nextLine().toCharArray();
			int len = c.length;
			
			if(len % 2 != 0){
				System.out.println("NA");
				continue;
			}
			StringBuilder sb = new StringBuilder();
			boolean flg = false;
			for(int i = 0; i < len; i+=2){
				int col = c[i] - '0' - 1;
				int row = c[i+1] - '0' - 1;
				if(! isOK(col, row)){
					flg = true;
					break;
				}
				sb.append(map[row][col]);
			}
			if(flg){
				System.out.println("NA");
			}
			else{
				System.out.println(sb.toString());
			}
		}
	}
	
	private boolean isOK(int col, int row) {
		if(0 <= col && col < 6 && 0 <= row && row < 5){
			return true;
		}
		return false;
	}

	private void init() {
		map = new char[5][6];
		int ind = 0;
		for(int i = 'a'; i <= 'z'; i++){
			map[ind % 5][ind / 5] = (char)i;
			ind++;
		}
		map[1][5] = '.';
		map[2][5] = '?';
		map[3][5] = '!';
		map[4][5] = ' ';
	}

	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

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

Measured memory_bytes: 12000
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie();
	cout.tie();
	int N;
	cin>>N;
	int q,j;
	q=j=1;
	for(int i=0;i<N;i++)
	{
		int x;
			cin>>x;
		q*=3;
		if( x%2==0 )
		{
			j*=2;
		}
	}
	cout<<q-j<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <stdio.h>
#include <stdlib.h>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) > 0 ? (a) : (-1 * (a)))
#define rep(i, n) for ((i) = 0; (i) < (n); (i)++)
#define rep2(i, s, e) for ((i) = (s); (i) < (e); (i)++)
#define LIM (1000000007)

int main(void)
{

    int n, i;
    long long s = 0;
    scanf("%d", &n);
    rep2(i, 1, n + 1)
    {
        if (i % 3 != 0 && i % 5 != 0)
            s += i;
    }
    printf("%lld", s);

    return 0;
}


Measured memory_bytes: 1732
'use strict';
process.stdin.on('data', function(chunk) {
  var lines = chunk.toString().split('\n');
  var params = lines[0].split(' ').map(Number);
  var result = (function(m,n) {
    return [
      m * n
      ,2 *(m + n)
    ].join(' ');
  }(params[0],params[1]
  ));

  console.log(result);
});

process.stdin.resume();
process.stdin.setEncoding('utf8');

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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    string s, t;
    cin >> s >> t;
    vector<int> mp(1 << 8), inv(1 << 8);
    for(int i = 0; i < s.size(); ++i) {
        if(mp[s[i]] != 0 && mp[s[i]] != t[i]) {
            cout << "No" << endl;
            return 0;
        }
        if(inv[t[i]] != 0 && inv[t[i]] != s[i]) {
            cout << "No" << endl;
            return 0;
        }
        mp[s[i]] = t[i];
        inv[t[i]] = s[i];
    }
    cout << "Yes" << endl;

}

Measured memory_bytes: 916
n,m = map(int,input().split())
light_bulb = [] #light_bulb[[k,s1,s2,,,sk],[k,,,,]]
for _ in range(m):
    x = list(map(int,input().split()))
    light_bulb.append(x)
p = list(map(int,input().split()))

def judge(switch):            
    for i in range(m):
        k = light_bulb[i][0]
        count = 0
        for j in range(1,k+1):
            on = light_bulb[i][j]-1
            if switch[on] == 1:
                count +=1
        if count % 2 != p[i]:
            return False
    return True
counter = 0
for i in range(2**n):
    switch = [0]*n
    for j in range(n):
        if (i>>j)&1:
            switch[j] = 1
    if judge(switch):
        counter += 1
print(counter)


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

using namespace std;

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

	vector<int> h(n);
	for(int &i : h) {
		cin >> i;
	}

	vector<int> ban(n);

	for(int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		if(h[a] >= h[b]) {
			ban[b] = 1;
		}
		if(h[a] <= h[b]) {
			ban[a] = 1;
		}
	}

	int ans = 0;
	for(int i : ban) {
		ans += (i == 0);
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for(int i=0; i <N; i++) cin >> l[i];
  
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  int ans =0;
  for(int i=0; i<K; i++) ans += l[i];
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 100005;
const ll MOD = 1000000007;

string str;
int n;

int findEdge (int st, int dl) {
    int ptr = st;
    while (ptr >= 0 && ptr < n && str[ptr] == str[st]) {
        ptr += dl;
    }
    return ptr;
}
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> str;
    n = SZ(str);

    int l = findEdge((n-1)/2, -1);
    int r = findEdge(n/2, 1);
    if (str[(n-1)/2] != str[n/2]) {
        cout << n/2 << endl;
    } else {
        cout << min(r, n-l-1) << endl;
    }

}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics; 

class _Class
{
  void _Do()
  {
    var ab = Split.ints();
    var a = ab[0];
    var b = ab[1];

    if (a+b==15)
      Console.WriteLine("+");
    else if (a * b == 15)
      Console.WriteLine("*");
    else
      Console.WriteLine("x");
  }


  //
  static void Main(string[] args)
  {
    _(args);
    new _Class()._Do();
  }

  [Conditional("DEBUG")]
  static void _(string[] args)
  {
    if (args.Length != 0 && File.Exists(args[0]))
      Console.SetIn(new StreamReader(args[0]));
    else
      Console.Error.WriteLine("in");
  }
}

static class Split
{


  // 1
  public static string[] strings()
  {
    return Console.ReadLine().Split();
  }


  // [2.1] -2,147,483,648 ~ +2,147,483,647
  public static int[] ints()
  {
    var _s = Console.ReadLine().Split();

    var x = new int[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = int.Parse(_s[i]);

    return x;
  }

  // [2.2] 
  // -9,223,372,036,854,775,808 ~ 
  // +9,223,372,036,854,775,807
  public static long[] longs()
  {
    var _s = Console.ReadLine().Split();

    var x = new long[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = long.Parse(_s[i]);

    return x;
  }

  public static double[] doubles()
  {
    var _s = Console.ReadLine().Split();

    var x = new double[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = double.Parse(_s[i]);

    return x;
  }

  public static BigInteger[] bigs()
  {
    var _s = Console.ReadLine().Split();

    var x = new BigInteger[_s.Length];
    for (var i = 0; i < _s.Length; i++)
      x[i] = BigInteger.Parse(_s[i]);

    return x;
  }
}



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

    String S = sc.next();

    char[] s = S.toCharArray();
    
    boolean flag = false;
    
    for(int i = 0 ; i < 3 ; i++){
      if(s[i]==s[i+1]){
        flag = true;
        break;
      }
    }
    
    if(flag){
      System.out.println("Bad");
    }else{
      System.out.println("Good");
    }
    
  }
}

Measured memory_bytes: 20820
mod = 998244353

# 貰うDP
# Pythonで普通に通った．
# Aのような累積， のようなものを使って復元して高速化するケースはよくあるらしい．
def main(N, S):
    dp = [0 if n != 0 else 1 for n in range(N)]     # dp[i]はマスiに行く通り数． (答えはdp[-1]), dp[0] = 1 (最初にいる場所だから1通り)
    A = [0 if n != 0 else 1 for n in range(N)]      # dp[i] = A[i] - A[i-1] (i >= 1), A[0] = dp[0] = 1 (i = 0) が成り立つような配列を考える． (累積を取っておく配列)

    for i in range(1, N):   # 今いる点 (注目点)
        for l, r in S:  # 選択行動範囲 (l: 始点, r: 終点)
            if i - l < 0:   # 注目点が選択行動範囲の始点より手前の場合 → 注目点に来るために使用することはできない．
                break
            else:           # 注目点に来るために使用することができる場合
                if i - r <= 0:  # lからrの間で，注目点に行くために使用できる点を逆算． そこに行くことができる = 選択行動範囲の値を選択することで注目点に達することができる通り数．
                    dp[i] += A[i-l]
                else:
                    dp[i] += A[i-l] - A[i-r-1]
        dp[i] %= mod
        A[i] = (A[i-1] + dp[i]) % mod
    print(dp[-1])

if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    S = {tuple(map(int, input().split())) for k in range(K)}
    S = sorted(list(S), key = lambda x:x[0])    # 始点でsort (範囲の重複がないため)
    main(N, S)

Measured memory_bytes: 24652
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        h: usize,
        w: usize,
        mut s: [Chars; h],
    }

    solve(h, w, &mut s);
}

fn solve(h: usize, w: usize, s: &mut Vec<Vec<char>>) {
    for i in 0..h {
        for j in 0..w {
            match s[i][j] {
                '.' => s[i][j] = '0',
                _ => continue,
            }
        }
    }

    let points = vec![
        (-1, -1),
        (0, -1),
        (1, -1),
        (1, 0),
        (1, 1),
        (0, 1),
        (-1, 1),
        (-1, 0),
    ];
    for i in 0..h {
        for j in 0..w {
            if s[i][j] == '#' {
                continue;
            }
            for &p in points.iter() {
                let row = (i as i32) + p.0;
                let col = (j as i32) + p.1;
                if row > -1 && row < (h as i32) && col > -1 && col < (w as i32) {
                    match s[row as usize][col as usize] {
                        '#' => {
                            let num = char::to_digit(s[i][j], 10).unwrap();
                            s[i][j] = std::char::from_digit(num + 1, 10).unwrap();
                        }
                        _ => continue,
                    }
                }
            }
        }
    }

    for i in 0..h {
        for j in 0..w {
            print!("{}", s[i][j]);
        }
        println!("");
    }
}


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

const int mod = 1'000'000'007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


int main() {
  string L;
  cin >> L;

  mint ans = 0;

  mint cnt1 = 1;
  rep(i, L.length()) {
    if (L[i] == '1') {
      ans += cnt1 * mint(3).pow(L.length()-i-1);
      cnt1 *= 2;
    }
  }
  ans += cnt1;

  cout << ans.x << endl;

  return 0;
}


Measured memory_bytes: 512
using System;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());

            if (A + B == 3)
            {
                Console.WriteLine("3");
            }
            else if (A + B == 4)
            {
                Console.WriteLine("2");
            }
            else
            {
                Console.WriteLine("1");
            }
        }
    }
}

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

using namespace std;

#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;
const int MAXN = (int)3e5+1;

void setIO(string name)
{
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}

bool check_palindrome(string str)
{
    for(int i=0; i<str.length(); i++)
    {
        if(str[i] != str[str.length()-i-1])
        {
            return false;
        }
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //setIO("");
    string s;
    cin >> s;
    int n = s.length();
    if(check_palindrome(s) && check_palindrome(s.substr((n+1)/2)))
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }


    return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long A = scan.nextLong();
        long B = scan.nextLong();
        long C = scan.nextLong();
        if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
            System.out.println(0);
            return;
        }
        long answer = A * B;
        answer = Math.min(answer, B * C);
        answer = Math.min(answer, C * A);
        System.out.println(answer);
    }
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N;
  cin >> N;
  bool is_ok = false;
  if (N % 10 == 9)
    is_ok = true;
  N /= 10;

  if (N % 10 == 9)
    is_ok = true;

  printYesNo(is_ok);
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int a, b; cin >> a >> b;
    string ans = "Impossible\n";
    if(!(a%3)) ans = "Possible\n";
    if(!(b%3)) ans = "Possible\n";
    if(!((a+b)%3)) ans = "Possible\n";
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

struct P
{
    int p, money, damage;

    bool operator >(const P& p ) const  {
        return damage > p.damage;
    }
};

struct edge
{
    int to, cost, enemy;
};

int main() {
    int town_n, road_n, money;

    while(cin >> town_n >> road_n >> money, town_n|road_n|money){
        vector<edge> E[town_n + 1];

        REP(i, road_n){
            int from ,to, cost, enemy;
            cin >> from >> to >> cost >> enemy;

            E[from].push_back({to, cost, enemy});
            E[to].push_back({from, cost, enemy});
        }

        int G[town_n + 1][money + 1];
        fill_n((int*)G, (town_n + 1)*(money + 1), INT_MAX);
        G[1][money] = 0;

        priority_queue<P, vector<P>, greater<P>> que;
        que.push({1, money, 0});
        int result = -1;
        while(!que.empty()){
            P p = que.top(); que.pop();
//            printf("now town :%d, money:%d, damage: %d\n", p.p, p.money, p.damage);
            if(p.p == town_n){
                result = p.damage;
                break;
            }

            for(edge e:E[p.p]){
                int to = e.to;
                int usedmoney = p.money - e.cost;
                int damaged = p.damage + e.enemy;

                //お金を使う
                if(usedmoney >= 0 && G[e.to][usedmoney] > p.damage){
                    que.push({to, usedmoney, p.damage});
                    G[e.to][usedmoney] = p.damage;
                }
                //お金を使わない
                if(G[e.to][p.money] > damaged){
                    que.push({to, p.money, damaged});
                    G[e.to][p.money] = damaged;
                }
            }
        }

        if(result == -1)
            assert(result);

        cout << result << endl;
    }
}

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

int a[100050];
int n;

int main() {
	cin >> n;
	for (int i=  1;i<=n;++i)cin>>a[i];
	long long res = 0;
	for (int i = 1; i <= n; ++i) res +=a[i]-1;
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
/* Generated by powerful Codeforces Tool
 * You can download the binary file in here https://github.com/xalanq/cf-tool (Windows, macOS, Linux)
 * Author: alireza_kaviani
 * Time: 2020-09-20 18:09:52
**/
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 2e5 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

int n , k , q , A[MAXN];
ll nxt[LOG][MAXN] , prv[LOG][MAXN] , nxts[LOG][MAXN] , prvs[LOG][MAXN];

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

	cin >> n >> k;
	for(int i = 1 ; i <= n ; i++)	cin >> A[i];
	for(int i = 1 , ptr = 1 ; i <= n ; i++){
		while(ptr <= n && A[ptr] < A[i] + k)	ptr++;
		nxt[0][i] = ptr;
		nxts[0][i] = i + ptr;
//		cout << i << sep << ptr << endl;
	}
	for(int i = n , ptr = n ; i >= 0 ; i--){
		while(ptr >= 1 && A[ptr] > A[i] - k)	ptr--;
		prv[0][i] = ptr;
		prvs[0][i] = i + ptr;
//		cout << i << sep << ptr << endl;
	}
	nxt[0][n + 1] = n + 1;
	for(int i = 1 ; i < LOG ; i++){
		for(int j = 0 ; j < MAXN ; j++){
			prv[i][j] = prv[i - 1][prv[i - 1][j]];
			prvs[i][j] = prvs[i - 1][j] + prvs[i - 1][prv[i - 1][j]] - prv[i - 1][j];
			nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
			nxts[i][j] = nxts[i - 1][j] + nxts[i - 1][nxt[i - 1][j]] - nxt[i - 1][j];
			if(1 <= j && j <= n){
//				cout << i << sep << j << sep << nxt[i][j] << sep << prv[i][j] << endl;
			}
		}
	}

	cin >> q;
	while(q--){
		int L , R , x;
		cin >> L >> R;
		ll ans = R - L + 1;
		x = L;
		for(int i = LOG - 1 ; i >= 0 ; i--){
//			cout << L << sep << nxt[i][L] << endl;
			if(nxt[i][L] <= R){
				ans += L - nxts[i][L];
				L = nxt[i][L];
//				cout << L << sep << ans << endl;
			}
		}
//		cout << endl;
		L = x;
		for(int i = LOG - 1 ; i >= 0 ; i--){
			if(prv[i][R] >= L){
				ans += prvs[i][R] - R;
				R = prv[i][R];
				ans += (1 << i);
//				cout << R << sep << ans << endl;
			}
		}
		cout << ans << endl;
	}

    return 0;
}
/*

*/


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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  int N;

  CIN(N);

  int p;
  CIN(p);
  int mi = p;

  int c = 1;
  for (int i = 1; i < N; i++) {
    CIN(p);
    if (p <= mi)
      c++;

    mi = min(p, mi);
  }

  COUT(c);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main() {
    map<string, int> count;
    int N;
    string s;
    cin >> N;
    rep(i,0,N) {cin >> s;count[s]++;}
    int max=-1;
    fore(p, count){
        if (p.second > max) max = p.second;
    }
    fore(p, count){
        if (p.second == max)
            cout << p.first << endl;
    }
}



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

int main(){
  int A, B, ans;
  cin >> A >> B;
  if(A<=5){
    ans = 0;
  }else if(A>=6 && A<=12){
    ans = B/2;
  }else{
    ans = B;
  }

  cout << ans << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
def swap(w):
    return("S" if w == "W" else "W")

N = int(input())
s = input()

inits = ["SS","SW","WS","WW"]

for init in inits:
    ans = init
    for i in range(1,N):
        if(ans[i] == 'S'):
            if(s[i] == 'o'):
                ans = ans + ans[i-1]
            else:
                ans = ans + swap(ans[i-1])
        else:
            if(s[i] == 'o'):
                ans = ans + swap(ans[i-1])
            else:
                ans = ans + ans[i-1]

    if(ans[0] == ans[-1]):
        ans = ans[0:N]

        if(ans[0] == 'S'):
            if(s[0] == 'o'):
                val = (ans[1] == ans[-1])
            else:
                val = (ans[1] != ans[-1])
        else:
            if(s[0] == 'o'):
                val = (ans[1] != ans[-1])
            else:
                val = (ans[1] == ans[-1])
        
        if(val):
            break

    ans = "-1"

print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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

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

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

  ll ans = 0;
  vector<int> r;
  vector<int> g;
  vector<int> b;
  string s;
  cin >> s;

  rep(i, n)
  {
    if (s[i] == 'R')
      r.push_back(i);
    else if (s[i] == 'G')
      g.push_back(i);
    else if (s[i] == 'B')
      b.push_back(i);
  }
  ans = r.size() * g.size() * b.size();

  repi(aida, 0, n)
  {
    rep(i, n)
    {
      int j = i + aida;
      int k = j + aida;
      if (j <= n - 1 && k <= n - 1 && s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
      {
        ans--;
      }
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(void){
    string A,B;
    int ans = 0;
    cin >> A >> B;
    
    if(A.length() > B.length()){
        ans = 1;
    }else if(A.length() < B.length()){
        ans = 2;
    }else if(A.length() == B.length()){
        for(int i = 0; i < A.length(); i++){
            if(A[i] > B[i]){
                ans = 1;
                break;
            }else if(A[i] < B[i]){
                ans = 2;
                break;
            }else{
                ans = 3;
            }
        }
    }
    
    if(ans == 1){
        cout << "GREATER" << endl;
    }else if(ans == 2){
        cout << "LESS" << endl;
    }else{
        cout << "EQUAL" << endl;
    }
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

import java.util.PriorityQueue;
import java.util.Comparator;
import java.util.HashSet;
import java.util.*;

class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
		int N = in.nextInt();
		int M = in.nextInt();
		Comparator<Work> comparator_1 = new Comparator<Work>() {
		    @Override
		    public int compare(Work o1, Work o2) {
		        return Integer.compare(o1.A, o2.A);
		    }
		};
		Comparator<Work> comparator_2 = new Comparator<Work>() {
		    @Override
		    public int compare(Work o1, Work o2) {
		        return Integer.compare(o2.B, o1.B);
		    }
		};
		PriorityQueue<Work> queue_1 = new PriorityQueue<Work>(comparator_1);
		for (int i=0;i<N;i++) {
			int A = in.nextInt();
			int B = in.nextInt();
			queue_1.add(new Work(A, B));
		}

		long ans = 0L;
		PriorityQueue<Work> queue_2 = new PriorityQueue<Work>(comparator_2);
		for (int i=0;i<=M;i++) {
			while(true) {
				if (queue_1.isEmpty()) {
					break;
				}
				Work tmp = queue_1.peek();
				if (tmp.A<=i) {
					queue_2.add(queue_1.poll());
				} else {
					break;
				}
			}
			if (!queue_2.isEmpty()) {
				Work rem = queue_2.poll();
				ans += rem.B;
			}
		}
		System.out.println(ans);
	}

	static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }

	static class Work {
		public int A;
		public int B;

		public Work(int A, int B) {
			this.A = A;
			this.B = B;
		}
	}
}


Measured memory_bytes: 45096
from collections import Counter
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    cum = [0]*(N+1)
    for i in range(1,N+1):
        cum[i] = cum[i-1]+A[i-1]
    c = Counter(cum)
    ans = 0
    for v in c.values():
        ans += v*(v-1)//2
    return ans
print(solve())

Measured memory_bytes: 41760
import copy
S = input()

'''
bit探索
2 進数表記した場合の下から数えて n 桁目（一番下の桁を 0 とします）が 1 であるかどうかをチェックするためのコードは、(i >> n) & 1 
'''
def bit_cal2(n):
    return_list = ['']* (2 ** n)
    for i in range(2 ** n):
        for j in range(n):
            if ((i >> j) & 1):
                return_list[i] = return_list[i] + '1'
            else:
                return_list[i] = return_list[i] + '0'
    return return_list

#自作のは遅かった
'''
def bit_cal(max_num,cal_list=[],current_cnt=0):
    new_list = []
    if len(cal_list) == 0:
        for i in range(2):
            new_list.append([i])
    else:
        for cal_val in cal_list:
            for i in range(2):
                tmp = copy.deepcopy(cal_val)
                tmp.append(i)
                new_list.append(tmp)
    current_cnt += 1
    if max_num == current_cnt:
        return new_list
    return bit_cal(max_num,new_list,current_cnt)

'''
all_plus_combination = bit_cal2(len(S)-1)
ans = 0
for plus_combination in all_plus_combination:
    start_idx = 0
    for i in range(len(S)-1):
        if plus_combination[i] == '1':
            ans += int(S[start_idx:i+1])
            start_idx = i+1
    ans +=int(S[start_idx:100])
print(ans)



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

namespace ABC055A___Restaurant
{
    class Program
    {
        private static readonly int _price = 800;
        private static readonly int _cash_back_price = 200;

        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            int eatNum = int.Parse(input);

            int payMoney = _price * eatNum;
            int cashBack = eatNum / 15 * _cash_back_price;

            Console.WriteLine(payMoney - cashBack);

        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>
int main()
{
    long long int a,b;
    scanf("%lld",&a);
    if(a%2==0)
    {
        printf("%lld\n",a);
    }
    else if(a%2!=0)
    {
        printf("%lld\n",a*2);
    }
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    public static void Main()
    {
        int P, Q, R;
        var read = Console.ReadLine().Split().Select(int.Parse).ToArray();

        Console.WriteLine(read.Sum() - read.Max());

    }
    
}

Measured memory_bytes: 13396
N,W = gets.split(/\s/).map(&:to_i)
obj = Array.new(N)
for i in 0..N-1
	obj[i] = gets.split(/\s/).map(&:to_i)
end

w = [[0],[0],[0],[0]]
w0 = obj[0][0]

for i in 0..N-1
	wNow = obj[i][0]
	vNow = obj[i][1]
	if wNow == w0
		w[0].insert(1, vNow)
	elsif wNow == w0 + 1
		w[1].insert(1, vNow)
	elsif wNow == w0 + 2
		w[2].insert(1, vNow)
	else w[3].insert(1, vNow)
	end
end

for i in 0..3
	w[i] = w[i].sort{|a, b| (-1)* (a <=>b)}
	w[i].insert(0,0)
	w[i].delete_at(w[i].length-1)
end

value = 0
v0,v1,v2,v3 = 0,0,0,0

for i in 0..w[0].length()-1
	v0 += w[0][i]
	for j in 0..w[1].length()-1
		v1 += w[1][j]
		for k in 0..w[2].length()-1
			v2 += w[2][k]
			for l in 0..w[3].length()-1
				v3 += w[3][l]
				vadd = v0 + v1 + v2 + v3
				if value < vadd && (i*w0 + j*(w0+1) + k*(w0+2) + l*(w0+3)) <= W
					value = vadd
				end
			end
			v3 = 0
		end
		v2 = 0
	end
	v1 = 0
end

puts value



Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
#define PI 3.14159265358979
#define MOD 998244353
const int MAX = 510000;

int main() {
  ll N,L;
  cin>>N>>L;
  vector<ll>a(N);
  vector<ll>dif(N-1);
  rep(i,N){cin>>a[i];}
  int flag=0;
  rep(i,N-1){dif[i]=a[i]+a[i+1];if(dif[i]>=L){flag=i+N+1;}}
  if(flag==0){cout<<"Impossible";}
  else{
    cout<<"Possible"<<endl;
  	flag-=N;
  	for(int i=1;i<flag;i++){cout<<i<<endl;}
  	for(int i=N-1;i>flag;i--){cout<<i<<endl;}
    cout<<flag;
  }
}

Measured memory_bytes: 2432
n=int(input())
ans=1000
lst_1=list(map(int,input().split()))
# print(lst_1)
for i in range(n-1):
    if (lst_1[i]<lst_1[i+1]):
        k=ans//lst_1[i]
        ans+=(lst_1[i+1]-lst_1[i])*k
print(ans)

Measured memory_bytes: 9104
#include <stdio.h>
int main(){
  char weather[10];
  char *s1 = "Sunny";
  char *s2 = "Cloudy";
  char *s3 = "Rainy";
  
  scanf("%s",weather);
  if(strcmp(s1,weather)==0) printf("%s",s2);
  if(strcmp(s2,weather)==0) printf("%s",s3);
  if(strcmp(s3,weather)==0) printf("%s",s1);
  return 0;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,m; cin >> n >> m;
  vector<pair<int,string>> ps(m);
  rep(i,m){
    int p; cin >> p;
    string s; cin >> s;
    ps[i] = make_pair(p,s);
  }

  int ac=0,wa=0;
  vector<bool> acd(n+1,false);
  /*cout << "size: " << acd.size() << endl;
    cout << acd[3] << endl;*/
  vector<int> wan(n+1,0);
  rep(i,m){
    int p = ps[i].first;
    string s = ps[i].second;
    //cout << "p: " << p << " " << s << " acd: " << acd[p] << endl;
    if(!acd[p]){
      if(s=="AC"){
	ac++;
	acd[p]=true;
	wa += wan[p];
      }
      else wan[p]++;
    }
    //printf("ac: %d wa: %d\n",ac,wa);
  }

  printf("%d %d\n",ac,wa);
  
  return 0;
}


Measured memory_bytes: 7488
package main

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

func main() {
	N := ReadInt()
	if N%2 == 0 {
		fmt.Println(N)
	} else {
		fmt.Println(2 * N)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int>d(n);
	for (int i = 0; i < n; i++)cin >> d[i];

	int val=0;
	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j < n; j++) {
			int a, b;
			a = d[i]; b = d[j];
			val += a*b;
		}
	}

	cout << val;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());

using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;



int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n){
    TSTART();
    vector<bool> P(n);
    vector<int> A(n);
    REP(i,n){
      int a;
      cin >> a;
      A[i] = a-1;
    }

    int next = 0;
    int ans = 0;
    bool Clear = true;
    while(next != 1){
      DUMP(next);
      if(P[next]){
	Clear = false;
	break;
      }
      P[next] = true;
      next = A[next];
      ans++;
    }
    if(!Clear) ans = -1;
    cout << ans << endl;
    TSTOP();
  }
  return 0;
}



Measured memory_bytes: 640