akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (ll i = 0; i < H; i++) {
        cin >> S[i];
    }

    vector<vector<ll>> row(H, vector<ll>(W, 0));
    vector<vector<ll>> col(H, vector<ll>(W, 0));

    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            row[i][j] = (S[i][j] == '.' ? 1 : 0);
        }
        for (ll j = 1; j < W; j++) {
            row[i][j] = (S[i][j] == '.' ? row[i][j] + row[i][j - 1] : 0);
        }
        for (ll j = W - 2; j >= 0; j--) {
            row[i][j] = (S[i][j] == '.' ? max(row[i][j], row[i][j + 1]) : 0);
        }
    }
    for (ll j = 0; j < W; j++) {
        for (ll i = 0; i < H; i++) {
            col[i][j] = (S[i][j] == '.' ? 1 : 0);
        }
        for (ll i = 1; i < H; i++) {
            col[i][j] = (S[i][j] == '.' ? col[i][j] + col[i - 1][j] : 0);
        }
        for (ll i = H - 2; i >= 0; i--) {
            col[i][j] = (S[i][j] == '.' ? max(col[i][j], col[i + 1][j]) : 0);
        }
    }

    ll ans = 0;
    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            ans = max(ans, row[i][j] + col[i][j]);
        }
    }

    cout << ans - 1 << endl;
}

Measured memory_bytes: 67072
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int d = sc.nextInt(),
        n = sc.nextInt();
    if(d == 0){
      if(n == 100)
        System.out.println(n + 1);
      else
        System.out.println(n);
    }
    else{
      int p = 1;
      for(int j = 0; j < d; j++)
        p *= 100;
      if(n == 100)
        System.out.println(p * n + p);
      else
        System.out.println(p * n);
      
    }
  }
}

Measured memory_bytes: 21972
#include<iostream>

int main() {
	int N = 0;
	int A[200000];
	int max = 0;
	int max2 = 0;
	std::cin >> N;
	int count = 0;
	for (int i = 0; i < N; i++) {
		std::cin >> A[i];
		if (i == 0) {
			max = A[i];

		}
		else {
			if (max < A[i]) {
				max2 = max;
				max = A[i];
			}
			else if (max2 < A[i]) {
				max2 = A[i];
			}
			
		}
	}

	for (int i = 0; i < N; i++) {
		if (max == A[i]) {
			count++;
		}
	}



	if (count >= 2) {
		for (int i = 0; i < N; i++) {
			std::cout << max << std::endl;
		}
	}
	else {
		for (int i = 0; i < N; i++) {
			if (A[i] == max) {
				std::cout << max2 << std::endl;
			}
			else {
				std::cout << max << std::endl;
			}
		}
	}

}

Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
using ll=long long;
using ii=pair<int, int>;

const int INF = 100000000;
ll a,b,c,i,j,l,m,n,ans,tmp,hoge,fuga,piyo;
int h, w;
int MAP[20][20];
int d[20][20];
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int get_longest(int i, int j, int h, int w) {
    int max = 0;
    queue<ii> que;
    for (int hh = 0; hh < h; hh++) {
        for (int ww = 0; ww < w; ww++) {
            d[hh][ww] = INF;
        }
    }
    d[i][j] = 0;
    que.push(ii(i, j));
    while (que.size()) {
        ii p = que.front(); que.pop();
        // printf("%d, %d\n", p.first, p.second);
        for (int n = 0; n < 4; n++) {
            int nx = p.first + dx[n];
            int ny = p.second + dy[n];
            if (0 <= nx && nx < h && 0 <= ny && ny < w && MAP[nx][ny] == 1 && d[nx][ny] == INF) {
                que.push(ii(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
                max = d[nx][ny] > max ? d[nx][ny] : max;
                // printf("%d, %d, %d, %d, %d\n", nx, ny, i, j, max);
            }
        }
    }
    return max;
}

int main() {
    cin >> h >> w;
    for (int i = 0; i < h + 1; i++) {
        string str;
        getline(cin, str);
        if (i == 0) continue;
        for (int j = 0; j < w; j++) {
            MAP[i-1][j] = str[j] == '.' ? 1 : 0;
            //printf("%d", MAP[i-1][j]);
        }
        //printf("\n");
    }
    int longest = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (MAP[i][j] == 1) {
            int l = get_longest(i, j, h, w);
            if (l > longest) {
                longest = l;
            }
            }
        }
    }
    printf("%d", longest);
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int d = saori.saori_hayami();
		int[][] x = new int[n][d];
		for(int i = 0;i < n;i++){
			for(int j = 0;j < d;j++){
				x[i][j] = saori.saori_hayami();
			}
		}
		int ans = 0;
		double num = 0;
		for(int i = 0;i < n-1;i++){
			for(int j = i+1;j < n;j++){
				num = 0;
				for(int k = 0;k < d;k++){
					num += Math.pow(x[i][k] - x[j][k], 2);
				}
				num = Math.sqrt(num);
				if(num == Math.rint(num)){
					ans++;
				}
			}
		}
		System.out.println(ans);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 23124
/**
 *    Author:   ElProfesor
 *	       
**/

#include<bits/stdc++.h>

using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
typedef vector <lli> vl;
typedef vector <string> vs;
typedef vector < pair <long, long> > vll;

// Debugging :
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
#define deb debug
 
#define forz(i,n) for(lli i=0; i<n; i++)
#define rep(i,k,n) for (lli i = k; i < n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

// Printing Data :
#define pvec(v) forz(i,v.si) cout<<v[i]<<" "; cout<<endl;
#define parr(arr, n) forz(i,n) cout<<arr[i]<<" "; cout<<endl;
#define p1(i) cout<<i<<endl;
#define p2(i, j) cout<<i<<" "<<j<<endl;
#define p3(i, j, k) cout<<i<<" "<<j<<" "<<k<<endl;
#define p4(i, j, k, l) cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl;

typedef pair <lli,lli> pll;
 
// CODE BEGINS :

int main()
{
    kira; 

    lli a, b, n; cin>>a>>b>>n;

    if(b-1<=n)
    {
        cout<<((a*(b-1))/b)<<endl;
    }

    else
    {
        cout<<((a*n)/b)<<endl;
    }

    return 0;
}




















































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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            if (N % 2 == 1)
            {
                Console.WriteLine("No");
                return;
            }

            var k = N / 2;
            var S = Console.ReadLine();

            Console.WriteLine(S.Substring(0, k) == S.Substring(k) ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9
 
 
int main(){
   int N;
   cin >> N;
   vector<int> A(N), B(N);
   REP(i, N){
      cin >> A[i] >> B[i];
   }
   ll ans = 0;
   ll sum = 0;
   REPR(i, N-1){
      int dif = (B[i]-(A[i]+ sum)% B[i]);
      if(dif == B[i]){
         dif = 0;
      }
      ans += dif;
      sum += dif;
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <unordered_map>

using namespace std;

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

    int64_t s = 0;
    unordered_map<int64_t, int64_t> val;
    val[0]++;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        s += a;
        val[s]++;
    }

    int64_t total = 0;
    for (auto& kv : val) {
        int64_t cnt = kv.second;
        if (cnt > 1)
            total += cnt * (cnt - 1) / 2;
    }
    cout << total << endl;
}


Measured memory_bytes: 8520
if __name__ == "__main__":
    N=int(input())
    robot=[]
    cnt=0
    last = -1e9
    for _ in range(N):
        x, l = map(int,input().split())
        robot.append((x - l, x+l))
    robot.sort(key=lambda x: x[1])
    for i in range(N):
        if last <=robot[i][0]:
            cnt+=1
            last = robot[i][1]
    print(cnt)


Measured memory_bytes: 23868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
  int n, m;
  cin >> n >> m;
  string a[50], b[50];
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  for(int i = 0; i <= n - m; i++){
    for(int j = 0; j <= n - m; j++){
      bool flag = true;
      for(int k = 0; k < m; k++){
        if(b[k] != a[i+k].substr(j, m)){
          flag = false;
          break;
        }
      }
      if(flag){
        cout << "Yes" <<endl;
        return 0;
      }
    }
  }
  cout << "No"<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int n,m;
int cnt[2][200001];
char s[200005];
Vi v[200001];
bool chk[200001];
int main(){
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	fup(i,1,m,1)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].pb(y);
		v[y].pb(x);
	}
	fup(i,1,n,1)
	{
		for(int next:v[i])
			cnt[s[next]-'A'][i]++;
	}
	queue<int> q;
	fup(i,1,n,1)
		if(cnt[0][i]==0 || cnt[1][i]==0)
		{
			chk[i]=1;
			q.push(i);
		}
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(int next:v[x])
		{
			if(!chk[next])
			{
				cnt[s[x]-'A'][next]--;
				if(cnt[s[x]-'A'][next]==0)
				{
					chk[next]=1;
					q.push(next);
				}
			}
		}
	}
	int t=0;
	fup(i,1,n,1)if(chk[i])t++;
	puts(t==n?"No":"Yes");
}

Measured memory_bytes: 12672
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}




int main(){
    ll n,can[5];
    
    std::cin >> n;
    for (int i = 0; i < 5; i++) {
        std::cin >> can[i];
    }
    
    sort(can,can+5);
    
    
    
    
    std::cout << (ll)ceil(n*1.0/can[0])+4 << std::endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		sc.close();

		int ans;
		for (int i = 1; i < 2 * k; i++) {

			ans = x - k + i;

			System.out.println(ans);

		}
	}
}

Measured memory_bytes: 23380
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

char str[100005];

int main(int argc, char* argv[])
{
    int n, k;
    scanf("%d%d", &n, &k);
    scanf("%s", str);

    int cnt=0, cnt2=0;
    int i;
    for(i=1; i<n; i++) {
        if(str[i-1]==str[i]) cnt++;
        else cnt2++;
    }
    int tmp=cnt2/2;

    int tmp2=MIN(k,tmp);
    int ans=cnt+tmp2*2;
    if(tmp2<k && cnt2%2) ans++;

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

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<climits>
using namespace std;

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

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

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

    double ans = -1;
    for(int i = 0; i < n-2; i++){
        ans = max(ans, (double)(a[n-1]+a[n-2]) / (a[i+1]-a[i]) );
    }

    ans = max(ans, (double)(a[n-1]+a[n-4]) / (a[n-2]-a[n-3]));
    ans = max(ans, (double)(a[n-3]+a[n-4]) / (a[n-1]-a[n-2]));

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


Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n;
  int sum=0;
  cin>>n;
  vector<int>a(n),b(n-1);
  rep(i,n-1) cin>>b[i];
  a[0]=b[0];
  for(int i=1;i<n-1;i++)
    a[i]=min(b[i-1],b[i]);
  a[n-1]=b[n-2];
  rep(i,n)
    sum+=a[i];
  cout<<sum<<endl;
}

Measured memory_bytes: 256
a,b,c,d = map(int,input().split())

def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
    
def lcm(x,y):
    return x*y//gcd(x,y)
    
ans = (b-a+1) - (b//c-(a-1)//c)- (b//d-(a-1)//d) + b//lcm(d,c) - (a-1)//lcm(d,c)
print(ans)

Measured memory_bytes: 3060
n,l=map(int,input().split())
li=[]
liabs=[]
for i in range(n):
    li.append(l+i+1-1)
    
if 0 in set(li):
    print(sum(li))
elif li[0]>0:
    print(sum(li)-min(li))
else:
    print(sum(li)-max(li))
        
    
    

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
//#include <algorithm>
#include <vector>


int main(int argc, char* argv[])
{
    long k;
    scanf("%ld", &k);

    long i, j;
    if(k<=4) {
        long n = k;
        printf("%d\n", n);
        for(i=0; i<n; i++) {
            for(j=0; j<n; j++) {
                printf("%d", j+1);
                if(j!=n-1) {
                    printf(" ");
                }
            }
            printf("\n");
        }
    }
    else {
        long n = ((k-1)/4+1)*2;
        printf("%d\n", n);
        for(i=0; i<n; i++) {
            for(j=0; j<n; j++) {
                long tmp = (i+j)%n+1;
                if(i%2==1) {
                    tmp += n;
                    if(tmp>k) {
                        tmp -= n;
                    }
                }
                printf("%d", tmp);
                if(j!=n-1) {
                    printf(" ");
                }
            }
            printf("\n");
        }
    }

    return 0;
}


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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

const int maxn = 1e5+10;

int dp[maxn];

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int h,n;
	cin>>h>>n;
	vi a(n),b(n);
	for(int i=0;i<n;++i){
		cin>>a[i]>>b[i];
	}
	for(int i=0;i<maxn;++i){
		dp[i]=112345678;
	}
	for(int i=0;i<=h;++i){
		for(int j=0;j<n;++j){
			if(i-a[j] <= 0) dp[i] = min(dp[i],b[j]);
			else dp[i] = min(dp[i],b[j]+dp[i-a[j]]);
		}
	}
	cout<<dp[h]<<endl;
	return 0;
}

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

int main(void)
{
	int A, B, K;
	cin >> A >> B >> K;
	vector<int> cd;
	for (int i = min(A, B); i > 0; i--) {
		if (A%i == 0 && B%i == 0)cd.push_back(i);
	}
	cout << cd[K - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	map<ll,ll> mp;
	rep(i,n){
		ll x;
		cin>>x;
		mp[x]++;
	}
	vector<ll> now;
	for(auto itr:mp){
		if(itr.se>=4){
			now.push_back(itr.fi);
			now.push_back(itr.fi);
		}else if(itr.se>=2){
			now.push_back(itr.fi);
		}
	}
	sort(begin(now),end(now),greater<ll>());
	ll ans=0;
	if(now.size()>=2){
		ans=now[0]*now[1];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6528
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
#define ll long long

char s[200005];
ll n;

ll t[200005];
inline ll lowbit(ll x){
	return x&-x;
}
inline void add(ll x,ll k){
	for(;x<=n;x+=lowbit(x))
		t[x]+=k;
}
inline ll pre_sum(ll x){
	ll ans=0;
	for(;x;x-=lowbit(x))
		ans+=t[x];
	return ans;
}
inline ll sum(ll l,ll r){
	return pre_sum(r)-pre_sum(l-1);
}

ll ans,num[26];
vector<ll> v[26];
bool vis[200005];

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for(ll i=1;i<=n;i++){
		ll tmp=s[i]-'a';
		num[tmp]++;
		v[tmp].push_back(i);
		add(i,1);
	}
	for(ll i=0;i<26;i++)
		ans-=num[i]%2;
	if(ans<-1){
		printf("-1");
		return 0;
	}
	ans=0;
	for(ll i=1;i<=n;i++){
		if(vis[i])
			continue;
		ll tmp=s[i]-'a',j=v[tmp][v[tmp].size()-1];
		if(i==j)
			ans+=sum(i+1,n)/2;
		else
			ans+=sum(j+1,n);
		add(i,-1);
		add(j,-1);
		vis[i]=vis[j]=1;
		v[tmp].erase(v[tmp].end()-1);
	}
	printf("%lld",ans);
}

Measured memory_bytes: 4724
#include<iostream>
using namespace std;
int main()
{
	int A[7] = { 1,3,5,7,8,10,12 }, B[4] = { 4,6,9,11 }, C = 2;
	int x, y;

	cin >> x >> y;

	for (int i = 0; i < 7; i++)
	{
		if (A[i] == x)
		{
			for (int j = 0; j < 7; j++)
			{
				if (A[j] == y)
				{
					cout << "Yes" << endl;
					break;
				}
				if (j == 6)
				{
					cout << "No" << endl;
				}
			}
		}
	}


	for (int i = 0; i < 4; i++)
	{
		if (B[i] == x)
		{
			for (int j = 0; j < 4; j++)
			{
				if (B[j] == y)
				{
					cout << "Yes" << endl;
					break;
				}
				if (j == 3)
				{
					cout << "No" << endl;
				}
			}
		}
	}

	if (x == 2)
	{
		cout << "No" << endl;
	}

	return 0;
	
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

const int Maxn = 510;
const int Maxm = 35;

int cost[3][Maxm];
int d[Maxm][Maxm];

int n, m;

int main() {
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
     */
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> d[i][j];
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int x;
            cin >> x;
            x--;
            for (int k = 0; k < m; ++k) {
                cost[(i + j) % 3][k] += d[x][k];
            }
        }
    }

    int ans = (int)1e9;
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < m; ++j) {
            for (int k = 0; k < m; ++k) {
                if (i == j || j == k || k == i) continue;
                int x = cost[0][i] + cost[1][j] + cost[2][k];
                ans = min(ans, x);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
from collections import defaultdict

def main():
    N = int(input())
    d = defaultdict(int)
    for _ in range(N):
        S = input()
        d[S] += 1

    max_d = max(d.values())
    ans = []
    for key, value in d.items():
        if value == max_d:
            ans.append(key)
    ans.sort()
    for a in ans:
        print(a)
    
    



if __name__ == "__main__":
    main()

Measured memory_bytes: 97804
n, m = map(int, raw_input().split())
a = [[input(),i] for i in xrange(n)]
t = [[0,i+1] for i in xrange(n)]
for b in [input() for i in xrange(m)]:
    t[filter(lambda x: x[0]<=b, a)[0][1]][0] += 1
print sorted(t, reverse=True)[0][1]

Measured memory_bytes: 4464
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
int main(){
  char C;
  cin >> C;
  cout << (char) (C + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    B = []
    for a in A:
        B.append(a - 1)
        B.append(a)
        B.append(a + 1)
    D = Counter(B)
    res = max([v for v in D.values()])
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 27416
/*
  -> Sayan Bose
  -> Do Good Die Great
*/
#include <bits/stdc++.h>
#define int long long int
#define pii pair<int, int>
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define MOD 1000000007
#define Hiraishin                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr);                 \
    cout.tie(nullptr);
#define tests \
    int t;    \
    cin >> t; \
    while (t--)
using namespace std;

int binpow(int a, int b)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = ((res % MOD) * (a % MOD)) % MOD;
        a = ((a % MOD) * (a % MOD)) % MOD;
        b >>= 1;
    }
    return res;
}
 
// Extended Euclid's (a / b) % m = (a * inv(b)) % m
int modInverse(int a)
{
    int m = MOD;
    int m0 = m;
    int y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1) {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}
 
// Euclid's Gcd
int gcd(int a, int b)
{
    int temp = a % b;
    while (temp) {
        a = b;
        temp = a % b;
    }
    return a;
}

// global

 
void solve()
{
    string s, t;
    cin >> s >> t;
    int res = 0;
    for(int i = 0; i < s.length(); i++)
        res += (s[i] != t[i]);
    cout << res << '\n';
}
 
signed main()
{
    Hiraishin
        //tests
        solve();
    return 0;
}

Measured memory_bytes: 3812
n=int(input())
s=input()
ans1="SS"
ans2="SW"
ans3="WS"
ans4="WW"

def check(ans):
    for i in range(1,n-1):
        if s[i]=="o"  and ans[i]=="S":
            ans+=ans[i-1]
        elif s[i]=="o" and ans[i]=="W":
            if ans[i-1]=="W":
                ans+="S"
            else:
                ans+="W"
         
        elif s[i]=="x"  and ans[i]=="S":
            if ans[i-1]=="W":
                ans+="S"
            else:
                ans+="W"
        elif s[i]=="x" and  ans[i]=="W":
            ans+=ans[i-1]
    flg=False
    if s[n-1]=="o":
        if ans[n-1]=="S":
            if ans[0]==ans[n-2]:
                flg=True
    if s[n-1]=="o":
        if ans[n-1]=="W":
            if ans[0]!=ans[n-2]:
                flg=True
    if s[n-1]=="x":
        if ans[n-1]=="S":
            if ans[0]!=ans[n-2]:
                flg=True
    if s[n-1]=="x":
        if ans[n-1]=="W":
            if ans[0]==ans[n-2]:
                flg=True
    if flg:
        if s[0]=="o":
            if ans[0]=="S":
                if ans[1]==ans[n-1]:
                    print(ans)
                    exit()
        if s[0]=="o":
            if ans[0]=="W":
                if ans[1]!=ans[n-1]:
                    print(ans)
                    exit()
        if s[0]=="x":
            if ans[0]=="S":
                if ans[1]!=ans[n-1]:
                    print(ans)
                    exit()
        if s[0]=="x":
            if ans[0]=="W":
                if ans[1]==ans[n-1]:
                    print(ans)
                    exit()
check(ans1)
check(ans2)
check(ans3)
check(ans4)
print(-1)

Measured memory_bytes: 143252
def simple_gcd(x, y):
  if y == 0:
    return x;
  else:
    return simple_gcd(y, x % y)

def main():
  n = int(input())
  l = 0
  for a in range(1, n+1):
     for b in range(1, n+1):
        d = simple_gcd(a,b)
        for c in range(1, n+1):
          l += simple_gcd(d,c)
  print(l)
main()


Measured memory_bytes: 70340
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();

    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let x: u8 = read();
    let y: u8 = read();
    let z: u8 = read();

    println!("{} {} {}", z, x, y);
}


Measured memory_bytes: 4352
a, b, c, d = map(int, input().split())

def between_time(before, after):
  diff = after - before
  if diff > 0:
    return diff
  else:
    return 0
  
if a > c:
  start = a
else:
  start = c

if b > d:
  fin = d
else:
  fin = b

print(between_time(start, fin))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using Graph = vector<vector<int>>;
using P = pair<int,int>;
using ll =long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    string s;
    cin >> s;
    bool ok = true;
    if(s.size()==1){
        cout << "No" << endl;
        return 0;
    }
    for(int i=0;i<s.size();i++){
        if(s[i]=='h' &&s[i+1]=='i'){
            i++;
            continue;
        }else{
            ok = false;
            break;
        }
    }
    cout << (ok? "Yes":"No") << endl;
}

Measured memory_bytes: 256
// https://arc061.contest.atcoder.jp/tasks/arc061_a

open System

let rec solve (s: string) i =
    seq {
        if (s = "") then yield 0L
        elif (i = String.length s) then yield int64 s
        else
            yield! Seq.map (fun x -> x + int64 s.[..(i - 1)]) (solve s.[i..] 1)
            yield! solve s (i + 1)
    }

let S = stdin.ReadLine()
(S, 1) ||> solve |> Seq.sum |> printfn "%d"


Measured memory_bytes: 14044
#include <bits/stdc++.h>
using namespace std;
#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(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
#define PI 3.14159265359
typedef long long ll;
//
int main(){
    int n;cin>>n;
    string s;cin>>s;
    int cor=0,cow=0;
    for(auto e:s){
        if(e=='R')cor++;
        if(e=='W')cow++;
    }
    int ans1=0;
    for(int i=s.size()-cow;i<s.size();i++){
        if(s[i]=='R')ans1++;
    }
    cout<<ans1<<endl;
    int ans2=0;
    
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll n,m;
ll k[100];
ll s[100][100],ss[20][20];
ll p[100];
ll swit[20];
ll ans;
ll ccc;
void solve(int num){
    if(num != n){
    swit[num] = 0;
    solve(num+1);
    swit[num] = 1;
    solve(num+1);
    }
    else{
    ll cou;
    bool f = true;
    for(int i = 0; i < m; i++){
        cou = 0;
        for(int j = 1; j <= n; j++){

            if(ss[i][j] == swit[j-1] && ss[i][j] == 1) ++cou;
        }
        if(p[i] != cou % 2) f = false;
    }
    if(f) ++ans;
    ++ccc;
    }

    return;
}


int main(){
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            cin >> s[i][j];
            ss[i][s[i][j]] = 1;
        }
    }
    for(int i = 0; i < m; i++){
        cin >> p[i];
    }

    solve(0);
    cout << ans << endl;
}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> board(h, vector<char>(w));
    rep(y, h) rep(x, w) cin >> board[y][x];

    vector<vector<int>> dp(h, vector<int>(w, INT_MAX / 10));
    if (board.front().front() == '.') dp[0][0] = 0;
    else dp[0][0] = 1;

    struct Direction {
        int x, y;
    };

    vector<Direction> directions = {
            {0, 1},
            {1, 0},
    };

    auto set = [&](int y, int x, int value) {
        cmin(dp[y][x], value);
    };

    rep(y, h) {
        rep(x, w) {
            for (Direction d : directions) {
                int ny = y + d.y;
                int nx = x + d.x;
                if (ny == h || nx == w) continue;

                if (board[ny][nx] == '.') set(ny, nx, dp[y][x]);
                else if (board[y][x] == '#') set(ny, nx, dp[y][x]);
                else if (board[y][x] == '.' && board[ny][nx] == '#') set(ny, nx, dp[y][x] + 1);
                else __throw_runtime_error("konaide");
            }
        }
    }

    cout << dp.back().back() << endl;

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ss  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element) != container.end())
#define ss  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(c) c.begin(), c.end()
#define pb push_back
#define mp make_pair
#define mod (1000000000 + 7)
#define inf (1e10+9)
#define fi first
#define se second
#define MAXN   1000001 
typedef long long ll;
using namespace std;
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> new_set;

long long fastpow(long long n, long long x, long long m){
	
    long long ret = 1;
    
    while(x){
    if(x&1) (ret*=n)%=m;
    x>>=1;
    (n*=n)%=m;
    }
  
 return ret;
}
ll add(ll a,ll b){
	return((a%mod)+(b%mod))%mod;
}
ll prod(ll a,ll b){
	a%=mod;
	b%=mod;
	return ((a%mod)*(b%mod)%mod);
}
int main()
{
	ss
    ll a,b;
    cin>>a>>b;
    if(b>=a){
    	cout<<"unsafe\n";
	}
	else cout<<"safe\n";
    
    
    
    
    
   
    return  0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(void){
	int i,j,n=0;
	long long int A[200001];
	long long int t,p;
 
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&A[i]);
	}
	p=n;
	t=A[0];
	i=0;
	j=1;
	while(j<n){
		while((t+A[j])==(t^A[j])&&j<n){
			t^=A[j];
			j++;
		}
		while((t+A[j])!=(t^A[j])||(j==n)&&(i<j)){
			t^=A[i];
			i++;
			p+=(long long int)(j-i);
		}
	}
 
	printf("%lld\n",p);
 
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=100005*2;
int n,m;
int a[N];
int check(int x){
	int p=x*2-1;
	For(i,p,n*2)
		if (a[i]+a[n*2-(i-p)]<m)
			return 0;
	return 1;
}
int main(){
	n=read(),m=read();
	For(i,1,n*2)
		a[i]=read();
	sort(a+1,a+n*2+1);
	int L=0,R=n,ans=n+1;
	while (L<=R){
		int mid=(L+R)>>1;
		if (check(mid))
			R=mid-1,ans=mid;
		else
			L=mid+1;
	}
	int mx=0;
	int p=ans*2-1;
	For(i,1,p-1)
		mx=max(mx,(a[i]+a[p-i])%m);
	For(i,p,n*2)
		mx=max(mx,(a[i]+a[n*2-(i-p)])%m);
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
using namespace std;

int main() {
	int n, room[4][3][10] = { 0 };
	(void)scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int b, f, r, v;
		(void)scanf("%d %d %d %d", &b, &f, &r, &v);
		room[b - 1][f - 1][r - 1] += v;
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				printf(" %d", room[i][j][k]);
			}
			printf("\n");
		}
		if(i != 3) printf("####################\n");
	}
	return 0;
}


Measured memory_bytes: 2728
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int n;
int a[410];
int dp[410][410];
bool vis[410][410];

int solve(int l, int r) {
	if (vis[l][r]) {
		return dp[l][r];
	}
	vis[l][r] = true;
	if (l + 1 >= r) return 0;
	int res = INF;
	for (int i = l + 1; i < r; i++) {
		chmin(res, solve(l, i) + solve(i, r));
	}
	for (int i = l; i < r; i++) res += a[i];
	return dp[l][r] = res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	cin >> n;
	rep(i, n) cin >> a[i];
	cout << solve(0, n) << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int a, b;
	cin >> a >> b;
	if(a > 8 || b > 8)
	{
		cout << ":(" << endl;
	}
	else
	{
		cout << "Yay!" << endl;
	}
	return 0;
}

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

typedef long long lint;
typedef pair<int, int> ii;

int MOD = 1e9 + 7;
int INF = 0x3f3f3f3f;

int n, m;
set<ii> edg;

int solve(){
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int u, v; cin >> u >> v;
		edg.insert({u, v});
		edg.insert({v, u});
	}
	int ok = 0;
	for(int i=1;i<=n;i++) if(edg.count({1, i}) && edg.count({i, n})) ok = 1;
	cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << endl;
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
	// int t; cin >> t; while(t--)
	solve();
	// cout << (solve() ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 19072
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	int N;
	cin >> N;
	auto result = N;
	for (auto i = 0; i <= N; ++i)
	{
		auto count = 0;
		for (auto temp = i; temp > 0; temp /= 6)
		{
			count += temp % 6;
		}
		for (auto temp = N - i; temp > 0; temp /= 9)
		{
			count += temp % 9;
		}

		result = min(result, count);
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = sorted([int(i) for i in input().split()], reverse=True)
allzero = True
element = {}
for i in a:
    if i != 0:
        allzero = False
    if i not in element.keys():
        element[i] = 0
    element[i] += 1
if allzero:
    print('Yes')
else:
    if n % 3 != 0:
        print('No')
    elif len(element) == 2:
        if 0 in element.keys() and element[0] == n//3:
            print('Yes')
        else:
            print('No')
    elif len(element) == 3:
        judge = 0
        for k, v in element.items():
            judge ^= k
            if v != n//3:
                print('No')
                break
        else:
            if judge == 0:
                print('Yes')
            else:
                print('No')
    else:
        print('No')

Measured memory_bytes: 14212
import java.util.Scanner;

class Main {

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

		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();

		String ans = s.substring(0, k - 1);
		ans += Character.toLowerCase(s.charAt(k - 1));
		ans += s.substring(k);

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 23124
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    var x = nextLong()
    var ans = (x / 11) * 2
    x %= 11
    when {
        x > 6 -> ans += 2
        x > 0 -> ans += 1
        else -> {
        }
    }
    println(ans)
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


#define INF             1e9
#define INFL            1e19
#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair

#define NEWLINE         cout << endl;
#define HOISE           cout << "hoise" << endl
#define PAUSE           system("pause")
#define DEBUG(x)        cout << #x << " = " << x << endl
#define READ            freopen("alu.txt", "r", stdin)
#define WRITE           freopen("vorta.txt", "w", stdout)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)

#define MASK(x)         for(int i = 0; i < 8; i++){ if(x&(1<<i)){ cout << i << " "; } } cout << endl;

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

const int MAX = 200000 + 2;
const int MAXLOG = log2(MAX) + 2;
const int MAXN = 1e6 + 2;
const int MOD = 1000000007;
const double PY = acos(-1.0);

int main()
{
//    READ;
//    WRITE;
    FASTIO;

    ll a, b;
    cin >> a >> b;
    ll g = __gcd(a, b);
    cout << (a*b)/g;

    return 0;
}




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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
int a[200005];
int bad[1000005];

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    forn(i, n) {
        cin >> a[i];
        ++bad[a[i]];
    }
    for (int i = 1000000; i >= 1; --i) {
        if (bad[i]) {
            for (int j = 2 * i; j <= 1000000; j += i) {
                bad[j] += bad[i];
            }
        }
    }
    int ans = 0;
    forn(i, n) if (bad[a[i]] == 1) {
        ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8292
N,M = map(int,input().split())
A = []
B = []
C = []
D = []
check = []

def Manhattan(a,b,c,d):
  distant = abs(a-c)+abs(b-d)
  return distant

for i in range(N):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)

for i in range(M):
  c,d = map(int,input().split())
  C.append(c)
  D.append(d)

  
for i in range(N):
  for j in range(M):
   if(j == 0):
    min = Manhattan(A[i],B[i],C[j],D[j])
    check.append(j+1)
   else:
    tmp = Manhattan(A[i],B[i],C[j],D[j])
    if(min > tmp):
      min = tmp
      check[i] = j+1
  print(check[i])



Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

bool used[100][100];
int dist[100][100];
int dy[]={0,0,-1,1};
int dx[]={1,-1,0,0};
int main(){
  int h,w;
  cin>>h>>w;
  string s[h];
  r(i,h)cin>>s[i];
  queue<P>q;
  q.push(P(0,0));
  used[0][0]=0;
  dist[0][0]=0;
  while(!q.empty()){
    P p=q.front();q.pop();
    int x=p.fi%100;
    int y=p.fi/100;
    dist[y][x]=p.se;
    r(i,4){
      int yy=y+dy[i];
      int xx=x+dx[i];
      if(xx<0||yy<0||y>=h||x>=w)continue;
      if(used[yy][xx])continue;
      if(s[yy][xx]=='#')continue;
      used[yy][xx]=1;
      q.push(P(yy*100+xx,p.se+1));
    }
  }
  int sum1=0;
  r(i,h)r(j,w)if(s[i][j]=='#')sum1++;
  if(dist[h-1][w-1]==0)cout<<-1<<endl;
  else cout<<h*w-(dist[h-1][w-1]+1+sum1)<<endl;
}

Measured memory_bytes: 256