akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//↑templete
long long GCD(long long a,long long b){
	if(b==0)
		return a;
	else
		return GCD(b,a%b);
}
ll mod_pow(ll x, ll n, ll mod) {
    if(n == 0) return 1;
    ll res = mod_pow((x * x) % mod, n / 2 , mod);
    if(n & 1) res = (res * x) % mod;
    return res;
}
signed main(){

    ll N, K;
    cin>>N>>K;

    ll DP[SIZE]={};
    ll ans=0;
    for(int g=K;g>=1;g--){
        //gの倍数
        ll temp=0, num=1;
        for(int i=2;i<=K && g*i<=K;i++){
            temp+=DP[g*i];
            num++;
        }
        //cout<<g<<" "<<temp<<" "<<num<<endl;
        DP[g]=(MOD+mod_pow(num, N, MOD)-temp)%MOD;
    }

    for(int i=1;i<=K;i++)
        (ans+=DP[i]*i)%=MOD;

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 4420
N,X = [int(i) for i in input().split()]
xa = [int(i) for i in input().split()]
from fractions import gcd
lia = [0]*N
for i in range(N):
    lia[i] = abs(X-xa[i])
ans = lia[0]
for i in range(1,N):
    ans = gcd(ans,lia[i])
print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
    int a;
    cin >> a;
    int ans = 0;
    REP(i, a) {
        int b;
        cin >> b;
        while (b % 2 == 0){
            b /= 2;
            ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int pos[10001];
char a[6],b[8],c[6];
int main(){
	string s;
	int len,i;
	char x;
	for(i=1;i<=5;i++){
		cin>>a[i];
	}
	cin>>x;
	for(i=1;i<=7;i++){
		cin>>b[i];
	}
	cin>>x;
	for(i=1;i<=5;i++){
		cin>>c[i];
	}
	for(i=1;i<=5;i++){
		cout<<a[i];
	}
	cout<<" ";
	for(i=1;i<=7;i++){
		cout<<b[i];
	}
	cout<<" ";
	for(i=1;i<=5;i++){
		cout<<c[i];
	}
	return 0;
}
 

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

#define rep(i, n) for (int i = 0; i < (n); ++ i)
vector<int> to[100005];
const int INF = 1001001001;

int main()
{
  int n, m;
  cin >> n >> m;
  rep(i, m)
  {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  
  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  dist[0] = 0;
  q.push(0);
  
  while(!q.empty())
  {
    int v = q.front(); q.pop();
    for (int u : to[v])
    {
      if (dist[u] != INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }
  
  cout << "Yes" << endl;
  rep(i, n)
  {
    if (i == 0) continue;
    int ans = pre[i];
    ++ ans;
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 10728
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()

	fmt.Println(n * n * n)
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

int main(void) {
  ios::sync_with_stdio(false);
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<int64_t> A(X);
  rep(i, X) cin >> A[i];
  vector<int64_t> B(Y);
  rep(i, Y) cin >> B[i];
  vector<int64_t> C(Z);
  rep(i, Z) cin >> C[i];

  vector<int64_t> AB(X * Y);
  rep(i, X) rep(j, Y) AB[i * Y + j] = A[i] + B[j];
  sort(AB.rbegin(), AB.rend());

  int KXY = min(K, X * Y);
  vector<int64_t> ABC(KXY * Z);
  rep(i, KXY) {
    rep(j, Z) { ABC[i * Z + j] = AB[i] + C[j]; }
  }
  sort(ABC.rbegin(), ABC.rend());
  rep(i, K) { cout << ABC[i] << endl; }
  return 0;
}


Measured memory_bytes: 34684
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1000000000

int main(){
  int a,b;
  cin>>a>>b;
  if(b%a==0){
    cout<<a+b<<endl;
  }
  else cout<<b-a<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(int argc, char *argv[]) {
	map<string,int> p;
	p["SAT"]=1; p["FRI"]=2; p["THU"]=3; p["WED"]=4;
	p["TUE"]=5; p["MON"]=6; p["SUN"]=7;
	string a; cin>>a;
	cout<<p[a]<<endl;
	return 0;
}

Measured memory_bytes: 256
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    if n % 2 == 0 {
        println!("{:.10}", 0.5);
    } else {
        if n == 1 {
            println!("{:.10}", 1);
        } else {
            let cnt = (n / 2 + 1) as f64;
            println!("{:.10}", cnt / n as f64);
        }
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
int main( ) {
    //freopen("A.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char c;
    rep(i,0,3){
        cin >> c;
        cout << ((c=='9')?1:9);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1234567890

int main(){
    ll i,j;
    ll m,d;
    cin>>m>>d;
    ll ans=0;
    for(i=1;i<=m;i++){
        for(j=1;j<=d;j++){
            ll d1=j/10;
            ll d2=j%10;
            if(d1>=2&&d2>=2&&d1*d2==i){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
using namespace std;
#define lli long long int
#define test                lli t;cin>>t;while(t-->0)
#define ainput  int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];}
#define vec vector<lli>v;
vec
#define avinput  int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];v.push_back(a[i]);}
#define vp  for(lli i=0;i<v.size();i++) {cout<<v[i]<<" ";}cout<<endl;
#define vp1  for(lli i=0;i<v1.size();i++) {cout<<v1[i]<<" ";}cout<<endl;
#define vp2  for(lli i=0;i<v2.size();i++) {cout<<v2[i]<<" ";}cout<<endl;
#define vp3  for(lli i=0;i<v3.size();i++) {cout<<v3[i]<<" ";}cout<<endl;
#define vp6  for(lli i=0;i<v6.size();i++) {cout<<v6[i].first<<" "<<v6[i].second<<endl;}
#define ln cout<<endl;
  //cout << fixed << setprecision(10) <<((double)((sum*1.0)/((n*1.0-k*1.0)+1.0))) << endl;
set<lli>s1;
set<lli>s2;
set<string>st2;
vector<lli>v1;
vector<lli>v2;
vector<lli>v3;
vector<lli>v4;
vector<lli>v5;
vector<pair<lli,lli> >v6;
vector<pair<char,int> >v16;
vector<string>v7;
vector<string>v8;
vector<char>v9;
vector<double>v11;
list<lli>l;
//****coding start****
int main()
{
lli n;cin>>n;
lli a[n],b[n];
for(lli i=0;i<n;i++){
    cin>>a[i];
}
for(lli i=0;i<n;i++){
    cin>>b[i];
}
for(lli i=0;i<n;i++){
    v6.push_back(make_pair(a[i]-b[i],i));
}
sort(v6.begin(),v6.end());
reverse(v6.begin(),v6.end());
lli m=0;
lli sum1=0,sum2=0;
for(lli i=0;i<v6.size();i++){
        sum1=sum1+a[v6[i].second];
sum2=sum2+b[v6[i].second];
    m=max(m,sum1-sum2);
}
cout<<m<<endl;
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N , a;
  a = 0;
  string S;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> S;
    if(S == "Y"){
      a = 1;
    }
  }
  if(a == 0){
    cout << "Three" << endl;
  }else{
    cout<< "Four" << endl;
  }
}

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

class Main{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int num1=0,num2=0;
        String s = br.readLine();
        String[] str = s.split(" ");
        int x = Integer.parseInt(str[0]);
        int y = Integer.parseInt(str[1]);
        int z = Integer.parseInt(str[2]);
        //System.out.println(x +"<"+ y +"<"+ z);
        
        if(x < y && y < z){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
}

Measured memory_bytes: 16952
import sys

X, Y = map(int, input().split())

n = (2*Y-X) / 3
m = (2*X-Y) / 3

if (X + Y) % 3 != 0 or n < 0 or m < 0:
    print(0)
    sys.exit(0)

N = int(n + m)
r = int(min([n, m]))
p = 10**9 + 7
fact = [1, 1]
inv = [0, 1]
factinv = [1, 1]

for i in range(2, N+1):
    fact.append(fact[-1]*i % p)
    inv.append(-inv[p%i] * (p//i) % p)
    factinv.append(factinv[-1] * inv[-1] % p)

print(fact[N] * factinv[r] * factinv[N-r] % p)

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

int main() {
	int N, M;
	cin >> N >> M;
	int cnt = 0;
	if (N >= 2)
		cnt += N * (N - 1) / 2;
	if (M >= 2)
		cnt += M * (M - 1) / 2;
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	public int minJumps(int[] heights) {
        int n = heights.length;
        int[] memo = new int[n];
        Arrays.fill(memo, -1);
		dfs(heights, 0, memo);
        // System.out.println(Arrays.toString(memo));
        return memo[0];
	}
	private int dfs(int[] heights, int position, int[] memo) {
		int n = heights.length;
		if (position >= n - 1) {
            return 0;
		}
        if (memo[position] != -1) {
            return memo[position];
        }
		int result = Math.abs(heights[position] - heights[position + 1]) + dfs(heights, position + 1, memo);
        if (position + 2 < n) {
            result = Math.min(result, Math.abs(heights[position] - heights[position + 2]) + dfs(heights, position + 2, memo)); 
        }
        return memo[position] = result;
	}


    public static void main(String[] args)  {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            int n = Integer.parseInt(br.readLine());
            String heightsStr = br.readLine();
            String[] split = heightsStr.split(" ");
          	int[] heights = new int[n];
            for (int i = 0; i < n; i++) {
              	heights[i] = Integer.parseInt(split[i]);
            }
          	Main app = new Main();
            int result = app.minJumps(heights);
            System.out.println(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 50336
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

/*------------------------------------*/

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

    int N;
    cin>>N;
    vector<int> a(N);
    rep(i,N)cin>>a[i];
    int ans = 0;
    int minn = INF;
    rep(i,N){
        if(chmin(minn, a[i])){
            ans = i+1;
        }
    }
    cout<<ans<<endl;
}


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

int main(){
	string s,t;
  	cin >> s >> t;
  	if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) {
    	cout << "YES" << endl;  
    } else {
     	cout << "NO" << endl; 
    }
}


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

int main() {
	ll X;
 	cin>>X;
  
  	ll yokin=100;
  	ll nen=0;
  while(yokin<X){
  	nen++;
    yokin+=(yokin*0.01); 
  }
  
  cout<<nen<<endl;
 
  
  
}

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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> A, B;
  for(int i = 0; i < M; i++) {
    int b = 0;
    cin >> b;
    B.push_back(b);
  }
  int count = 0;
  for(int j = 0; j < N; j++) {
    int res = 0;
    for(int i = 0; i < M; i++) {
      int a = 0;
      cin >> a;
      res += (a * B[i]);
    }
    if(res + C > 0) count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 888
N = int(input())
A = list(map(int,input().split()))
ans = int(1)

A.sort()

for i in A:
    if 0 <= (ans * i) and (ans * i) <= 1000000000000000000:
        ans *= i
        #print(ans)
    else:
        print("-1")
        exit(0)

print(ans)

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

int main() {
  string s;
  cin >> s;
  int a, b, n = s.size();
  
  for (int i=0; i<n; i++){
    if (s[i] == 'A'){
      a = i;
      break;
    }
  }
  
  for (int j=n-1; j>=0; j--){
    if (s[j] == 'Z'){
      b = j;
      break;
    }
  }
  
  cout << b-a+1 << endl;
}

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

public class Main {
    private static boolean elapsed = false;

    private int minCount = Integer.MAX_VALUE;

    private void solve(Scanner sc, PrintWriter out) {
        String s = sc.next();

        search(new StringBuilder(s));

        out.println(minCount);
    }
    private void search(StringBuilder sb) {
        if (check(sb)) {
            minCount = 0;
            return;
        }

        int leftCount = 0;
        boolean bFlg = (sb.charAt(0) == 'B');
        for (int i = 1; i < sb.length(); ++i) {
            if (sb.charAt(i) == 'B') {
                if (!bFlg) {
                    ++leftCount;
                }
                bFlg = true;
            } else if (sb.charAt(i) == 'W') {
                if (bFlg) {
                    ++leftCount;
                }
                bFlg = false;
            }
        }

        int rightCount = 0;
        bFlg = (sb.charAt(0) == 'B');
        for (int i = sb.length() - 1; i >= 0; --i) {
            if (sb.charAt(i) == 'B') {
                if (!bFlg) {
                    ++rightCount;
                }
                bFlg = true;
            } else if (sb.charAt(i) == 'W') {
                if (bFlg) {
                    ++rightCount;
                }
                bFlg = false;
            }
        }

        minCount = Math.min(leftCount, rightCount);
    }
    private boolean check(StringBuilder sb) {
        boolean bFlg = false;
        boolean wFlg = false;
        for (int i = 0; i < sb.length(); ++i) {
            if (sb.charAt(i) == 'B') {
                bFlg = true;
            } else if (sb.charAt(i) == 'W') {
                wFlg = true;
            }
            if (bFlg && wFlg) {
                return false;
            }
        }
        return true;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        new Main().solve(sc, out);
        out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            System.err.println((G - S) + "ms");
        }
    }
}

Measured memory_bytes: 13620
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string>

int main() {
	int N;
	scanf("%d",&N);
	unsigned long long a[100010];
	for (int i = 0; i < N ;i++) {
		scanf("%llu",&a[i]);
	}
	std::sort(&a[0], &a[N]);
	
	unsigned long long w=0, h=0;
	bool flag=false;
	for (int i = N - 1; i >= 1;i--) {
		if (a[i]==a[i-1]) {
			if (flag == false) {
				w = a[i];
				flag = true;
			}
			else {
				h = a[i];
				break;
			}
			i=i-1;
		}
	}
	
	unsigned long long ans =w;
	ans *= h;
	printf("%llu\n",ans);
	
	return 0;
}

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

int main() {
    int n;
    scanf("%d", &n);
    vector<int> vec(n), stdvec(n);
    rep(i,n) scanf("%d", &vec.at(i));
    stdvec = vec;
    sort(all(stdvec));
    int SEGOSE = 0;
    rep(i,n) {
        if (vec.at(i) == stdvec.at(i)) SEGOSE++;
    }
    if (SEGOSE == n) {printf("0\n"); return 0;}
    int q;
    scanf("%d", &q);
    rep(i,q) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        if (vec.at(b) == stdvec.at(a)) SEGOSE++;
        if (vec.at(a) == stdvec.at(b)) SEGOSE++;
        if (vec.at(a) == stdvec.at(a)) SEGOSE--;
        if (vec.at(b) == stdvec.at(b)) SEGOSE--;
        swap(vec.at(a), vec.at(b));
        if (SEGOSE == n) {printf("%d\n", i+1); return 0;}
    }
    printf("-1\n");
}


Measured memory_bytes: 5196
#include<stdio.h>

int main()
{
	int n, m;
	
	scanf("%d %d", &n, &m);
	
	char str[n];
	
	scanf("%s", str);
	
	str[m - 1] >= 'A' && str[m - 1] <= 'C' ? str[m - 1] += 32: str[m - 1] += 0;
	
	printf("%s\n", str);
}

Measured memory_bytes: 1636
n , x = map(int, input().split())
l = 2**(n+2)-3

ans = 0
k=n
while l>=1:
    if x==(l+1)//2:
        ans+=2**(k)
        break
    if x==(l+1)//2-1:
        ans+=2**(k)-1
        break
    if x>(l+1)//2:
        ans+=2**(k)
        x-=(l+1)//2-1
    k-=1
    x-=1
    l=(l-1)//2-1
print(ans)


Measured memory_bytes: 3064
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    static Map<String, String> map = new HashMap<>();
    static {
        map.put("Sunny", "Cloudy");
        map.put("Cloudy", "Rainy");
        map.put("Rainy", "Sunny");
    }

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

        System.out.println(map.get(N));
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

vector<long long int> graph[100005];
long long int vis[100005]={0};
long long int dp[100005][2];

void dfs(long long int node)
{
    vis[node]=1;
    long long int si=graph[node].size(),i;

    for(i=0;i<si;i++)
    {
        if(vis[graph[node][i]]==0)
        {
            dfs(graph[node][i]);
            dp[node][0]=(dp[node][0]*((dp[graph[node][i]][0]+dp[graph[node][i]][1])%mod))%mod;
            dp[node][1]=(dp[node][1]*dp[graph[node][i]][0])%mod;
        }
    }
}
int main()
{
    long long int n,i;
    cin>>n;

    for(i=0;i<n-1;i++)
    {
        long long int u,v;
        cin>>u>>v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    for(i=0;i<100005;i++)
        dp[i][0]=dp[i][1]=1;

    dfs(1);
    cout<<(dp[1][0]+dp[1][1])%mod;
}


Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int n,k;
  cin >> n >> k;
  int a[n]; REP(i,n) cin >> a[i];
  sort(a,a+n);
  int right = n-(upper_bound(a,a+n,a[0])-a);
  COUT( ceil(right / (double)(k-1)) );
  return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <cstdio>
#define INF 100000000
#define t first
#define x second
using namespace std;
typedef pair <double,int> P;
double b,v,e,f;
int r;
double mk(int x) {
  if(x >= r) return 1.0/(v-e*(x-r));
  return  1.0/(v-f*(r-x));
}

int main() {
  while(1) {
    int n,a[102]={};
    cin >> n;
    if(n==0) break;
    for(int i=1;i<=n;i++) cin >> a[i];
    cin >> b >> r >> v >> e >> f;
    P dp[10010]={};
    for(int i=1;i<=a[n];i++) dp[i] = make_pair(INF,0);
    
    for(int i=0;i<n;i++) {
      int nx=dp[a[i]].x,cx= 0;
      double nt=dp[a[i]].t,ct=dp[a[i]].t+b;

      for(int j=a[i]+1;j<=a[n];j++){
	nt += mk(nx),ct += mk(cx);
	dp[j] = min(dp[j],min((P){nt,++nx},(P){ct,++cx}));
      }
    }
    printf("%.4f\n",dp[a[n]].t);
  }
  return 0;
}

Measured memory_bytes: 1400
#AGC006 A
'''
問題
文字列s, tが与えられる
長さN以上で, 先頭N文字がsに一致し, 末尾N文字がtに一致するような文字列として可能なものの最小の長さは？

考察
sとtが完全に等しければ答えはN
sとtが完全に違っていれば答えは2*N
sの最後の文字とtの最初の文字が同じで,sの最後から2番目の文字とtの最初から2番目の文字が違っていれば答えは2*N-1

sの最後の文字とtの最初から2文字目の文字が同じで
sの最後から2番目の文字とtの最初の文字が同じなら
答えは2*N-1

sの最後から1番目の文字とtの最初からi文字目が同じで
sの最後から2番目の文字とtの最初からi-1文字目が同じで
...
sの最後からi番目の文字とtの最初から1文字目が同じなら
答えは2*N-i

Nは1以上100以下
計算量はO(N**2)
最小の文字列の長さを求めたいのでiはNからはじめて1ずつ減らしていき条件が最初に満たされたときのiを答えとする
'''

N = int(input())
s = str(input())
t = str(input())

m = 0

for i in range(N,0,-1): #iはN,N-1,...,1で試す
	unity = True
	for j in range(i):
		#print(s[-(j+1)],t[j])
		if s[-(j+1)] == t[i-j-1]:
			continue
		else:
			unity = False
	#print(unity)
	if unity:
		m = i
		break
	
print(str(2*N-m))

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main ()
{
	int i,c=0,n,k;
	char s[50];
	scanf("%d",&k);
	scanf("%s",s);
	n=strlen(s);
	if(n>=3)
	{
	 	for(i=0;i<n;i++)
	 {
	 	if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
	 	{
	 		c++;	
		}
	 	
	 }
}
printf("%d",c);
return 0;
	
}

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

int main(){
  string S;
  cin>>S;
  map<char,int>cha;
  for (int i=0;i<S.length();i++){
    cha[S.at(i)]++;
  }
  if((max(max(cha['a'],cha['b']),cha['c'])-min(min(cha['a'],cha['b']),cha['c']))<2){
    cout<<"YES"<<endl;
    return 0;
  }
  cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner

object Main {

  def solve(sc: => Scanner): Unit = {
    val N, M = sc.nextInt
    if (N != 0 && M != 0) {
      var maxV: Int = -1
      val A = Array.fill[Int](N)(sc.nextInt)
      for (i <- 0 until A.length) {
        for (j <- i + 1 until A.length) {
          if (A(i) + A(j) <= M) (
            maxV = math.max(maxV, A(i) + A(j))
            )
        }
      }
      if (maxV == -1) (println("NONE")) else (println(maxV))

      solve(sc)
    }
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 65824
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
 
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
double dp[3010][3010];
double p[3030];
int main(){
	cin>>N;
	rep(i,N)rep(j,N)dp[i][j]=0.0;
	rep(i,N)cin>>p[i];
	dp[1][1]=p[0];
	dp[1][0]=1.0-p[0];
	for(int i=2;i<=N;i++){
		for(int j=0;j<=i;j++){
			dp[i][j]+=dp[i-1][j]*(1-p[i-1]);
			if(j>0)dp[i][j]+=dp[i-1][j-1]*p[i-1];
		}
	}
	double ans=0.0;
	//rep(i,N)cout<<dp[N][i]<<endl;
	for(int i=N/2+1;i<=N;i++){
		ans+=dp[N][i];
	}
	printf("%.9lf\n",ans);
	
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N,M;
  cin >> N >> M;
  vi u(M),u2(M);
  vvi v(N*3);
  rep(i,M) {
    cin >> u[i] >> u2[i];
    u[i]--;u2[i]--;
    v[u[i]*3].push_back(u2[i]*3+1);
    v[u[i]*3+1].push_back(u2[i]*3+2);
    v[u[i]*3+2].push_back(u2[i]*3);
  }
  int S,T;
  cin >> S >> T;
  S--;T--;
  
  vi dis(N*3,INF);
  dis[S*3]=0;
  queue<int> que;
  que.push(S*3);
  while(!que.empty()) {
    int q=que.front();
    que.pop();
    for(int x:v[q]) {
      if(dis[x]==INF) que.push(x);
      dis[x]=min(dis[x],dis[q]+1);
    }
  }
  
  if(dis[T*3]!=INF) cout << dis[T*3]/3 << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 21648
#include<stdio.h>

void trace(int A[], int N) {
    int i;
    for(i = 0; i < N; i++) {
        if(i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");

}

void insertionSort(int A[], int N) {
    int i, j, t;
    for(int i = 1; i < N; i++) {
        t = A[i];
        j = i - 1;
        while(j >= 0 && t < A[j]) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = t;
        trace(A, N);
    }
}

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

    trace(A, N);
    insertionSort(A, N);

    return 0;
}


Measured memory_bytes: 2712
N = int(input())
l = [int(x) for x in input().split()]
Q = int(input())
ans = sum(l)
from collections import defaultdict
d = defaultdict(int)
for i in range(N):
    d[l[i]] += 1
for i in range(Q):
    b,c = [int(x) for x in input().split()]
    ans = ans + (c-b)*d[b]
    d[c] += d[b]
    d[b] = 0
    print(ans)

Measured memory_bytes: 90600
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nk = readln.split.to!(long[]);
    auto N = nk[0];
    auto K = nk[1];
    long r;
    foreach (n; K+1..N+1) {
        r += N/n * (n-K);
        r += max(0, N - N/n * n - max(0, K-1));
    }
    writeln(r);
}

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

int main() {
    int n;
    cin >> n;
    set<string> st;
    vector<string> s(n);
    for (int i=0;i<n;i++) {
        cin >> s[i];
        st.insert(s[i]);
    }
    int l=st.size();
    vector<pair<int,string>> a(l);
    int k=0;
    vector<string> t;
    for (auto itr=st.begin();itr!=st.end();itr++) {
        t.push_back(*itr);
        a[k].second=*itr;
        a[k].first=1000000;
        k++;
    }
    for (int i=0;i<n;i++) {
        int m=lower_bound(t.begin(),t.end(),s[i])-t.begin();
        a[m].first--;
    }
    sort(a.begin(),a.end());
    int x=a[0].first;
    for (int i=0;i<l;i++) {
        if (a[i].first==x) cout << a[i].second << endl;
    }
}

Measured memory_bytes: 28404
H, W, K = map(int, input().split())
c = [[0 for i in range(W)] for j in range(H)]
cnt = 0
ans = 0
for i in range(H):
    line = input()
    for j, l in enumerate(line):
        if l == '.':
            continue
        else:
            c[i][j] = 1
            cnt += 1
for i in range(1<<H):
    for j in range(1<<W):
        flags = [[0 for i in range(W)] for j in range(H)]
        for n in range(H):
            if i>>n & 1:
                for p in range(W):
                    flags[n][p] = 1
                    '''
                    if c[n][p] & flags[n][p] == 0:
                        res -= 1
                        flags[n][p] = 1
                    '''
        for m in range(W):
            if j>>m & 1:
                for q in range(H):
                    flags[q][m] = 1
                    '''
                    if c[q][m] & flags[q][m] == 0:
                        res -= 1
                        flags[q][m] = 1
                    '''
        res = 0
        for p in range(H):
            for q in range(W):
                if flags[p][q] == 0 and c[p][q] == 1:
                    res += 1
        if res == K:
            ans += 1
print(ans)

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

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

	int cnt = 1;
	rep(i, n-1){
		if(s.at(i) != s.at(i+1)) cnt++;
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=100005;
int n,a[maxn],b[maxn];
ll ans;
inline int read(){
    int res=0,f_f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f_f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') res=(res<<3)+(res<<1)-'0'+ch,ch=getchar();
    return res*f_f;
}
int main(){
    n=read();
    for (int i=1;i<=n;i++){
        a[i]=read(),b[i]=read();
    }
    for (int i=n;i;i--){
        a[i]=(ans+a[i])%b[i];
        if(a[i]) ans+=b[i]-a[i];
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4496
#include<iostream>
using namespace std;
long long max(long long x,long long y)
{
     if(x>y) return x;
     return y;
}
long long a[200010],n,f[200010][3][2],inf=1999999999,ans;
int main()
{
    int i;
    cin>>n;
    inf=inf*-inf;
    for(i=1;i<=n;i++) 
    {
        cin>>a[i];
        if(i-2>=0) f[i][0][0]=f[i-2][0][0]+a[i];
        else f[i][0][0]=a[i];
        f[i][1][0]=inf;
        if(i-2>=0) f[i][1][0]=max(f[i][1][0],f[i-2][1][0]+a[i]);
        if(i-3>=0) f[i][1][0]=max(f[i][1][0],f[i-3][0][0]+a[i]);
        f[i][0][1]=inf;
        if(i-2>=0) f[i][0][1]=max(f[i][0][1],f[i-2][0][1]+a[i]);
        if(i-4>=0) f[i][0][1]=max(f[i][0][1],f[i-4][0][0]+a[i]);
        f[i][2][0]=inf;
        if(i-2>=0) f[i][2][0]=max(f[i][2][0],f[i-2][2][0]+a[i]);
        if(i-3>=0) f[i][2][0]=max(f[i][2][0],f[i-3][1][0]+a[i]);
    }
    ans=inf;
    if(n%2==0) ans=max(max(f[n][0][0],f[n][1][0]),f[n-1][0][0]);
    else
    {
        if(f[n-2][0][0]>ans) ans=f[n-2][0][0];
        if(f[n-1][0][0]>ans) ans=f[n-1][0][0];
        if(f[n-1][1][0]>ans) ans=f[n-1][1][0];
        if(f[n][0][0]>ans) ans=f[n][0][0];
        if(f[n][1][0]>ans) ans=f[n][1][0];
        if(f[n][2][0]>ans) ans=f[n][2][0];
        if(f[n][0][1]>ans) ans=f[n][0][1];
    }
    cout<<ans;
    cin>>i;
    return 0;
}
    


Measured memory_bytes: 14584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
int main(){
    int a,b;
    int s= -1;
    cin >> a >> b;
    cout << ((max(a,b)>=10)?s:(a*b)) << endl;
}

Measured memory_bytes: 256
S=input()
B=[]
ACGT=['A','C','G','T']
for s in S:
    if s in ACGT: B.append(True)
    else: B.append(False)
B.append(False)
ans=0
for start in range(len(B)):
    if not B[start]: continue
    count=0
    for end in range(start,len(B)):
        if not B[end]:
            ans=max(ans,count)
            break
        count+=1
print(ans)


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

#define CIN1(a) long long a;cin >> a;
#define CIN2(a,b) int a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int main(){
    CIN2(n,m)
    CIN2(X,Y)
    vector<int> vx(n),vy(m);
    rep(i,n) cin >> vx[i];
    rep(i,m) cin >> vy[i];
    int condx=max(X,*max_element(vx.begin(),vx.end()));
    int condy=min(Y,*min_element(vy.begin(),vy.end()));
    string s;
    if(condy-condx>=1) s = "No War";
    else s = "War";
    cout << s << endl;
}

Measured memory_bytes: 384
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    int N;
    in1(N);

    vector<ull> A(N + 1);
    inN(A, N + 1);

    //根のチェック
    if (A[0] >= 2)
    {
        outl(-1);
        return 0;
    }
    if (A[0] > 0)
    {
        if (N > 0)
        {
            outl(-1);
        }
        else
        {
            outl(1);
        }
        
        return 0;
    }

    //C[i] := 深さがi + 1以上の葉の枚数
    vector<ull> C(N + 1);
    rrep(i, N) C[i] = C[i + 1] + A[i + 1];

    //葉に対して一直線に枝をつける
    ull ans = 0;
    rep(i, N + 1) ans += (i + 1) * A[i];

    //根を束ねる
    ans -= C[0] - 1;

    ull parentCount = 1;

    repse(i, 1, N)
    {
        ull childrenCount = parentCount * 2;

        //葉の枚数に対して親が足りなければエラー
        if (childrenCount < A[i])
        {
            outl(-1);
            return 0;
        }

        //葉に親を割り当て、残りに下位改装を割り当て
        childrenCount -= A[i];

        if (childrenCount <= C[i])
        {
            ans -= C[i] - childrenCount;
        }

        parentCount = childrenCount;
    }

    outl(ans);

    return 0;
}


Measured memory_bytes: 4776
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N = int(input())
Ws = list(mi())
wsum = sum(Ws)

ans = 100000000
leftw = 0
rightw = wsum
for w in Ws[:-1]:
  leftw += w
  rightw = wsum-leftw
  ans = min(ans,abs(leftw-rightw))

print(ans)



Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();

        int[][] dp = new int[count][3];
        int[][] arr = new int[count][3];
        for (int i = 0; i < count; ++i) {
            for (int j = 0; j < 3; ++j) {
                arr[i][j] = scanner.nextInt();
            }
        }

        for (int j = 0; j < 3; ++j) {
            dp[0][j] = arr[0][j];
        }

        for (int i = 1; i < count; ++i) {
            for (int j = 0; j < 3; ++j) {
                for (int k = 0; k < 3; ++k) {
                    if (j != k) {
                        dp[i][j] = Math.max(dp[i][j], dp[i - 1][k] + arr[i][j]);
                    }
                }
            }
        }

        int res = 0;
        for (int j = 0; j < 3; ++j) {
            res = Math.max(dp[count - 1][j], res);
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 102952
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		
		ArrayList<Integer> list = new ArrayList<>();
		list.add(a);
		list.add(b);
		list.add(c);
		list.sort(null);
		
		for(int i = 0; i < k; i++) {
			int max = list.get(2) * 2;
			list.set(2, max);
			
		}
		
		int result = list.get(0) + list.get(1) + list.get(2);
		System.out.println(result);
		
	}
}

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

const int INF = 100000000;

typedef pair<int, int> P;

int H, W;
char s[50][50];

int d[50][50]; // (1, 1)からの距離

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // 移動ベクトル

int bfs() {
  queue<P> que;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++) d[i][j] = INF;
  que.push(P(0, 0));
  d[0][0] = 1;
  while (que.size()) {
    P p = que.front(); que.pop();
    if (p.first == H - 1 && p.second == W - 1) break;
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W &&
          s[nx][ny] == '.' && d[nx][ny] == INF) {
        que.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[H-1][W-1];
}

int main() {
  cin >> H >> W;
  int white = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> s[i][j];
      if (s[i][j] == '.') white++;
    }
  }
  if (bfs() == INF) cout << -1 << endl;
  else cout << white - bfs() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
	f = 0; _T fu = 1; char c = getchar();
	while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
	while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
	f *= fu;
}

template <typename T>
void print(T x) {
	if (x < 0) putchar('-'), x = -x;
	if (x < 10) putchar(x + 48);
	else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
	print(x); putchar(t);
}

const int N = 20;

int a[N];
int n;

ll dfs(int l, int r, int L, int R) {
	if (l > r) return 0;
	ll ans = 1e18;
	for (int i = l; i <= r; i++) ans = min(ans, dfs(l, i - 1, L, L + R) + dfs(i + 1, r, L + R, R) + 1ll * a[i] * (L + R));
	return ans;
}

int main() {
	read(n);
	for (int i = 1; i <= n; i++) read(a[i]);
	print(dfs(2, n - 1, 1, 1) + a[1] + a[n], '\n');
	return 0;
}

Measured memory_bytes: 3616
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

// template version 2.0
using namespace std;
#include <bits/stdc++.h>

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    string s,t;cin>>s>>t;
    ll n = sz(s);
    ll m = sz(t);

    ll ans = INF;
    rep(i, n-m+1){
        ll cnt = 0;
        rep(j, m){
            if (s[i+j] != t[j]){
                cnt++;
            }
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,m;
  cin>>n>>m;
  ll h[n];
  for(ll i=0;i<n;i++)
    cin>>h[i];
  ll roads[n]={0},ans[n]={0};
  ll f1,f2;
  while(m--){
    cin>>f1>>f2;
    if(h[f1-1]==h[f2-1]){
        roads[f1-1]++;
        roads[f2-1]++;
    }
    else
    if(h[f1-1]>h[f2-1]){
        roads[f1-1]++;
        roads[f2-1]++;
        ans[f1-1]++;
    }
    else{
      roads[f1-1]++;
        roads[f2-1]++;
        ans[f2-1]++;
    }
  }
  ll res=0;
  for(ll i=0;i<n;i++){
      if(roads[i]==ans[i])
      res++;
  }
 //cout<<map.size()<<"\n";
  cout<<res<<"\n";
}


Measured memory_bytes: 5972
p['   '];t['   '];n,x,j;main(i){for(;i++<1e6;)for(x=i;x<1e6;p[x+=i]=1);for(;scanf("%d%d",&n,&x),n;memset(t,!printf(x<2?"NA\n":"%d\n",x),4e6)){for(;n--;)for(i=-scanf("%d",t);++i<x;)t[i+*t]|=t[i];for(;p[x]|!t[x];x--);}}

Measured memory_bytes: 15000
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	final int n = stdin.nextInt();

	final long[][] map = new long[n][n];
	for ( int i = 0; i < n; i++ ) {
	    for ( int j = 0; j < n; j++ ) {
		map[i][j] = stdin.nextLong();
	    }	    
	}

	final long[][] cumCol = new long[n + 1][n];
	for ( int i = 0; i < n; i++ ) {
	    for ( int j = 1; j <= n; j++ ) {
		cumCol[j][i] = cumCol[j - 1][i] + map[j - 1][i];
	    }
	}

	// final long[][] cumRow = new long[n][n + 1];
	// for ( long i = 0; i < n; i++ ) {
	//     for ( long j = 1; j <= n; j++ ) {
	// 	cumRow[i][j] = cumRow[i][j - 1] + map[i][j - 1];
	//     }
	// }

	long maxSum = Long.MIN_VALUE;
	for ( int fy = 0; fy < n; fy++ ) {
	    for ( int fx = 0; fx < n; fx++ ) {
		for ( int ty = fy; ty < n; ty++ ) {
		    long sum = 0;
		    for ( int tx = fx; tx < n; tx++ ) {
			sum += cumCol[ty + 1][tx] - cumCol[fy][tx];
			maxSum = max( maxSum, sum );
		    }
		}
	    }
	}
	System.out.println( maxSum );
    }    
}

Measured memory_bytes: 36624
n,m = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
x = sorted(x,key=lambda x:x[0])
t = x[0][1]
res = 0
ans = 0
for i in range(n):
    res += x[i][1]
    ans += x[i][0]*x[i][1]
    if m-res<=0:
        print(ans-((res-m)*x[i][0]))
        exit()

Measured memory_bytes: 29796
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <iterator>
#include <array>
#include <iomanip>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007
#define pi 3.14159265358979323846264338327950

void solve()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
}

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

Measured memory_bytes: 3640