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

int main(){
  int d;
  cin >> d;
  vector<int> c(26);
  vector<vector<int>> s(d, vector<int>(26));
  for(int i = 0;i < d;i++){
    for(int j = 0;j < 26;j++){
      cin >> s.at(i).at(j);
    }
  }
 /* vector<int> day(26,0);

  for(int i = 0;i < d;i++){
    int ans = 0;
    ll ansc = 0;
    for(int j = 0;j < 26;j++){
      ll now = c[j] * (i - day[j] + 1);
      if(now > ansc){
        ans = j; 
    }else if(now == ansc){
      if(c[ans] < c[j]){
        ans = j;
      }
    }
    day[j] = i;  
  }
    cout << ans + 1 << endl;

  }*/
  for(int i = 0;i < d;i++){
    int ans = 0;
    for(int j = 0;j < 25;j++){
      if(s.at(i).at(j) < s.at(i).at(j+1)){
        ans = j+1;
      }
    }
    cout << ans + 1 << endl; 
  }
} 

Measured memory_bytes: 3676
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXLEN 12
struct Data {
    char S[MAXLEN];
    int index, P;
};

typedef struct Data data;

int cmp(const void *a, const void *b) {
    data *d1 = (data *)a; data *d2 = (data *)b;
    if( strcmp((*d1).S, (*d2).S) == 0) { return (*d1).P < (*d2).P; }
    else { return strcmp((*d1).S, (*d2).S); }
}

int main()
{
    int N, i;
    scanf("%d", &N);
    data list[N+3];
    for(i = 0; i < N; ++i) {
        scanf("%s %d", list[i].S, &list[i].P);
        list[i].index = i + 1;
    }

    /*
    for(i = 0; i < N; ++i) { 
        printf("%d %s %d\n", list[i].index, list[i].S, list[i].P);
    }
    */

    qsort(list, N, sizeof(data), cmp);
    for(i = 0; i < N; ++i) { 
        printf("%d\n", list[i].index);
    }
    return 0;
}

Measured memory_bytes: 128
use proconio::input;

fn main() {
    input! {
        s: usize,
    };
    let magic: usize = 1e9 as usize + 7;
    if s < 3 {
        println!("0");
        return;
    }
    let mut c: Vec<Vec<usize>> = vec![vec![];s];
    c[0].push(1);
    for _j in 1..s {
        c[0].push(0);
    }
    let s3 = s / 3;
    for i in 1..s {
        c[i].push(1);
        for j in 1..=s3 {
            let p = (c[i-1][j] + c[i-1][j-1]) % magic;
            c[i].push(p);
        }
    }
    let mut x: usize = 1;
    for b in 2..=s3 {
        let r = s - b * 3;
        x = (x + c[r + b - 1][b - 1]) % magic;
    }
    println!("{}", x);
}


Measured memory_bytes: 18048
#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++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll a,b,c=1,d=0,n,m1,n2,m2,min=100000,k=0,ans=0;
    string s,s2;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        if(c*2 < c+k){
            c = c*2;
        }
        else c = c+k;
    } 
    cout << c <<endl; 
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
n, m, c = map(int, input().split())
bm = list(map(int, input().split()))
data = [list(map(int, input().split())) for j in range(n)]
ac = 0
total = 0
for i in range(n):
    for k in range(m):
        total += data[i][k] * bm[k]
    total += c
    if total > 0:
        ac += 1
    total = 0
print(ac)


Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		List<Integer> list = new ArrayList();
		for (int i=0; i<n; i++) {
			list.add(scan.nextInt());
		}
		
		List<Integer> sorted = new ArrayList(list);
		Collections.sort(sorted);
		
		if (list.equals(sorted) || isChangeable(list, sorted)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
	
	public static boolean isChangeable(List list, List sorted) {
		boolean isChangeable = false;
		int notEqualCount = 0;
		List<Integer> indexList = new ArrayList();
		
		for (int i=0; i<list.size(); i++) {
			if (list.get(i) == sorted.get(i)) continue;
			if (notEqualCount > 3) break;
			
			indexList.add(i);
			notEqualCount++;
		}
		
		if (indexList.size() == 2) {
			int tmp = (Integer) list.get(indexList.get(0));
			list.set(indexList.get(0), list.get(indexList.get(1)));
			list.set(indexList.get(1), tmp);
			
			if (list.equals(sorted)) {
				isChangeable = true;
			}
		}
		return isChangeable;
	}
}

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

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a,b,c,d[ohara],cmp,cmpp,m,h,w,x,y,sum=0,pos,q,k;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl,visited[ohara];
struct edge{int to,cost;};
vector<ll> graph[ohara];
map<pair<ll,ll>,ll> cost;

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

void dfs(ll now,ll depth){
    if(visited[now])return;
    visited[now]=true;
    d[now]=depth;
    rep(i,Size(graph[now])){
        ll to=graph[now][i];
        dfs(to,depth+cost[{now,to}]);
    }
    return;
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
      
    cin>>n;
    rep(i,n-1){
        cin>>a>>b>>c;
        a--;b--;
        cost[{a,b}]=c;
        cost[{b,a}]=c;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    cin>>q>>k;k--;
    dfs(k,0);
    rep(i,q){
        cin>>a>>b;
        a--;b--;
        Cout(d[a]+d[b]);
    }
    return 0;
}


Measured memory_bytes: 55040
#include <cstdio>
#include <unordered_map>
#include <algorithm>
#include <map>
#include <vector>
#include <cstring>
using namespace std;
int n;
bool ans;
int main()
{
    scanf("%d", &n);
    while (n --)
    {
        int x;
        scanf("%d", &x);
        ans |= x & 1;
    }
    ans ? printf("first") : printf("second");
    return 0;
}

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


Measured memory_bytes: 2040
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
ll mod = 1e9+7;
ll dp[123456][4];
int main(){
    string s;
    cin >> s;
    int n = (int) s.size();
    dp[0][0] = 1;
    rep(i,n){
        rep(j,4) dp[i+1][j] += dp[i][j];
        if(s[i] == 'A'){
            dp[i+1][1] += dp[i][0];
        }
        if(s[i] =='B'){
            dp[i+1][2] += dp[i][1];
        }
        if(s[i] == 'C'){
            dp[i+1][3] += dp[i][2];
        }
        if(s[i] == '?'){
            rep(j,4)dp[i+1][j] += 2*dp[i][j];
            rep(j,3)dp[i+1][j+1] += dp[i][j];
        }
        rep(j,4) dp[i+1][j] %= mod;
    }
    cout << dp[n][3] << endl;
}

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

//.define
// #define FILE_IN_OUT
#define RET(_x)                       return cout << (_x) << '\n', 0;
#define all(_obj)                     std::begin(_obj), std::end(_obj)
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define ceilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define has(_obj, _val)               ((_obj).find(_val) != (_obj).end())
#define sz(_obj)                      static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)                     std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                     {}
#endif
#define endl "\n"
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
ll dp[101005];

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n, w;
    cin >> n >> w;
    memset(dp, -1, sizeof(dp));
    dp[0] = 0;
    loop(n) {
        int wi, v;
        cin >> wi >> v;
        for (int curw = w; curw >= wi; --curw) {
            if (dp[curw - wi] != -1) {
                dp[curw] = max(dp[curw], dp[curw - wi] + v);
            }
        }
    }
    cout << *max_element(dp, dp + w + 1) << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
	int a,b,s=0;
	scanf("%d %d",&a,&b);
	s=(1900*b+100*(a-b))*(int)pow((double)2,(double)b);
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int MAX = 10;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int t=0;t<n;t++) {
			boolean[][] map = new boolean[MAX][MAX];
			for(int i=0;i<MAX;i++) for(int j=0;j<MAX;j++) {
				map[i][j] = sc.nextInt() == 0;
			}
			int ans = -1;
			boolean[][] fld = new boolean[MAX][MAX];
			for(int i=0;i<1<<MAX;i++) {
				boolean[][] tmp = new boolean[MAX][MAX];
				for(int j=0;j<MAX;j++) fill(fld[j], false);
				for(int j=0;j<MAX;j++) for(int k=0;k<MAX;k++) tmp[j][k] = map[j][k];
				for(int j=0;j<MAX;j++) if( ((i>>>j)&1) == 1 ) {
					rev(j, 0, tmp);
					fld[0][j] = true;
				}
				for(int j=1;j<MAX;j++) for(int k=0;k<MAX;k++) {
					if(!tmp[j-1][k]) {
						rev(k, j, tmp);
						fld[j][k] = true;
					}
				}
				boolean flg = true;
				for(int k=0;k<MAX;k++) {
					flg &= tmp[MAX-1][k];
				}
				if(flg) {
					ans = i; break;
				}
			}
			for(int j=0;j<MAX;j++) for(int k=0;k<MAX;k++) {
				System.out.print( (fld[j][k]? 1: 0) + ( k==MAX-1? "\n": " " ) );
			}
		}
	}
	int dx[] = {-1,0,1,0,0};
	int dy[] = {0,-1,0,1,0};
	void rev(int x, int y, boolean[][] map) {
		for(int i=0;i<5;i++) if( !( x+dx[i] < 0 || y+dy[i] < 0 || x+dx[i] >= MAX || y+dy[i] >= MAX ) ){
			map[y+dy[i]][x+dx[i]] = !map[y+dy[i]][x+dx[i]];
		}
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <utility>
#include <set>
#include <tuple>
using namespace std;
using Vertex = tuple<set<int>, int, int>;    //to, status, longestPath to t
using Graph = vector<Vertex>;

int max(int x, int y)
{
    return x > y ? x : y;
}

bool isAcyclic(Graph& g, Vertex& v)
{
    get<1>(v) = 1;    // Active
    auto itEnd = get<0>(v).end();
    for (auto it = get<0>(v).begin(); it != itEnd; ++it)
    {
        switch (get<1>(g[*it]))
        {
            case 0: // New
                {
                    if (!isAcyclic(g, g[*it])) return false;
                }
                break;
            case 1: // Active
                {
                    return false;
                }
            case -1: // Finished
                break;
            default:
                break;
        }
    }
    get<1>(v) = -1;   // Finished
    return true;
}

int longestPath(Graph& g, int begin, int end)
{
    if (begin == end) return 0;
    if (get<2>(g[begin]) == 0)
    {
        auto itEnd = get<0>(g[begin]).end();
        for (auto it = get<0>(g[begin]).begin(); it != itEnd; ++it)
        {
            get<2>(g[begin]) = max(get<2>(g[begin]), longestPath(g, *it, end) + 1);
        }
    }
    return get<2>(g[begin]);
}

int main()
{
    int n;
    cin >> n;
    int m = n * (n - 1) / 2;
    Graph g(n * n + 2);
    int p1, p2;
    int prev, cur;
    for (int i = 1; i <= n; ++i)
    {
        prev = 0;
        for (int j = 1; j < n; ++j)
        {
            p1 = i;
            cin >> p2;
            if (p1 > p2)
            {
                int tmp = p1;
                p1 = p2;
                p2 = tmp;
            }
            cur = (p1 - 1) * n + p2;
            get<0>(g[prev]).insert(cur);
            prev = cur;
        }
        get<0>(g[prev]).insert(n * n + 1);
    }

    if (!isAcyclic(g, g[0]))
    {
        cout << -1 << endl;
    }
    else
    {
        cout << (longestPath(g, 0, n * n + 1) - 1) << endl;
    }

    return 0;
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
int N,M,K;
LL group[1<<16];
LL dp[16][1<<16];
int vis[16][1<<16];
LL g[16][16];
#define POS(b,x) ((b>>x)&1)
void f(int v,LL bit){
    if(v==0){
        dp[v][bit]=group[bit];
        return;
    }
    if(vis[v][bit])return;
    vis[v][bit]=1;
    dp[v][bit]=-(1<<13);
    int sup=bit-(1<<v)-1;
    int sub=sup;
    do{
        sub=(sub-1)&sup;
        int use_bit=sub+(1<<v);
        int nxt_bit=bit-use_bit;
        REP(u,N)if(POS(nxt_bit,u))if(g[u][v]){
            f(u,nxt_bit);
            chmax(dp[v][bit],dp[u][nxt_bit]+group[use_bit]+g[u][v]);
            }
    }while(sub!=sup);

}
int main(){

    cin>>N>>M;
    REP(i,N)REP(j,N)g[i][j]=0;
    K=1<<N;
    LL sum=0;
    REP(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        a--,b--;
        g[a][b]=c;
        g[b][a]=c;
        sum+=c;
    }
    FOR(bit,1,K){
        group[bit]=0;
        REP(i,N)FOR(j,i+1,N)
            if(POS(bit,i)&&POS(bit,j))
                group[bit]+=g[i][j];
        REP(i,N)vis[i][bit]=0;
    }
    f(N-1,K-1);
    cout<<sum-dp[N-1][K-1]<<endl;
    return 0;
}


Measured memory_bytes: 11776
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int N;
vector<int> L;

int main(void){
	int a;
	cin >> N;
	N *= 2;
	for(int i = 0; i < N; i++){
		cin >> a;
		L.push_back(a);
	}

	sort(L.begin(), L.end());
	reverse(L.begin(), L.end());

	int sum = 0;
	for(int i = 1; i < N; i += 2){
		sum += L[i];
	}

	cout << sum << endl;

	return 0;
}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int h = Integer.parseInt(sc.next());
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n+1];
		int[] b = new int[n+1];
		int[][] dp = new int[n+1][h+1];

		for(int i = 1 ; i < n +1 ; i++) {
			a[i] = Integer.parseInt(sc.next());
			b[i] = Integer.parseInt(sc.next());
		}

		for (int i = 0 ; i < n + 1 ; i++) {
			for (int j = 0 ; j < h+1 ; j++) {
				dp[i][j] = 999999999;
			}
		}

		for (int i = 1 ; i < n + 1 ; i++) {
			for (int j = 1 ; j < h+1 ; j++) {

				if(j-a[i] > 0) {
					dp[i][j] = Math.min(dp[i-1][j -a[i]] + b[i],dp[i-1][j]);
					dp[i][j] = Math.min(dp[i][j] ,dp[i][j -a[i]] +  b[i]);
				}else {
					dp[i][j] = Math.min(b[i],dp[i-1][j]);
				}
			}
		}



		System.out.println(dp[n][h]);
	}




}



Measured memory_bytes: 83060
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
// #include<bits/stdc++.h>
using namespace std; 

typedef long long int ll;

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

    int n;
    cin >> n;
    
    // long double A[n];
    // for(int i = 0; i < n; i++)cin >> A[i];
    // long double x = 0;
    // for(int i = 0; i < n; i++) x+=(1/A[i]);

    // x = (1/x);
    // cout << x;


    long double num;
    long double fracSum = 0;
    long double A[n];

    for(int i = 0; i < n; i++)
    {
        cin >> num;
        fracSum += (1/num);
    }
    
    fracSum = 1/fracSum;
    cout << fracSum;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,z;
    cin>>x>>y;
    if(x==2 || y==2)
        cout<<"No"<<endl;
    else if(x==4 || x==6 || x==9 || x==12)
        if(y==4 || y==6 || y==9 || y==12)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    else if(x== 3 || x==1 || x==5 || x==7 || x==8 || x==10 || x==12)
        if(y==3 || y==1 || y==5 || y==7 || y==8 || y==10 || y==12)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    else
        cout<<"No"<<endl;
    return 0;

}


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

int main() {
	int n, z, w;
	cin >> n >> z >> w;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	if (n == 1)
		cout << abs(a[0] - w) << endl;
	else
	cout << max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1])) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
int dp[110][110];

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

ll d[101][101];
char c[101][101];
ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll h, w;

void bfs(pair<ll, ll> P) {
	queue<pair<ll, ll>>q;
	d[P.first][P.second] = 0;
	q.push(P);
	while (!q.empty()) {
		pair<ll, ll>q2 = q.front();
		q.pop();
		ll y = q2.first;
		ll x = q2.second;
		rep(i, 4) {
			ll X = x + dx[i];
			ll Y = y + dy[i];
			if (0 <= X && X < w && 0 <= Y && Y < h && c[Y][X] == '.') {
				if (d[Y][X] == INF) {
					d[Y][X] = d[y][x] + 1;
					q.push(make_pair(Y, X));
				}
			}
		}
	}
}

//long longしか使わない
int main() {
	cin >> h >> w;
	ll white = 0;
	rep(i, h) {
		rep(j, w) {
			d[i][j] = INF;
			cin >> c[i][j];
			if (c[i][j] == '.')white++;
		}
	}
	pair<ll, ll>P = make_pair(0, 0);
	bfs(P);
	if (d[h - 1][w - 1] == INF)cout << -1 << endl;
	else {
		cout << white - d[h - 1][w - 1]-1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int D = saori.saori_hayami();
		int G = saori.saori_hayami();
		int[] p = new int[D];
		int[] c = new int[D];
		

		for(int i = 0;i < D;i++){
			p[i] = saori.saori_hayami();
			c[i] = saori.saori_hayami();
		}
		int ans = G/100;
		

		for(int i = 0; i < Math.pow(2, D);i++){
			HashSet<Integer> hs = new HashSet<>();
			int sum = 0;
			int hayami = 0;
			for(int j = 0; j < D ; j++){
				if ((1 & i >> j) == 1) {
					sum += 100*(j+1)*p[j] + c[j];
					hayami += p[j];
					hs.add(j);
                }
			}
			a:if(sum < G){
				for(int j = D-1;j >= 0;j--){
					if (hs.contains(j)) continue;
					for(int m = 0;m < p[j];m++){
						sum+=100*(j+1);
						hayami++;
						if(sum >= G)break a;
					}
				}
			}
			ans = Math.min(ans, hayami);
		}
		System.out.println(ans);
		
    }
}

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: 21972
def main():
    N = int(input())
    A = list(map(int, input().split()))

    a = [0] + A + [0]
    dist = 0
    for i in range(N + 1):
        dist += abs(a[i] - a[i+1])

    for i in range(1, N + 1):
        cost = dist - abs(a[i-1] - a[i]) - abs(a[i] - a[i+1]) + abs(a[i-1] - a[i+1])
        print(cost)

main()


Measured memory_bytes: 14048
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	string s;
	cin>>s;
	int n=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='+'){
			n++;
		}
		else{
			n--;
		}
	}
	cout<<n<<endl;

    return 0;
}

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

int main(){
  int64_t n,a,b;
  cin >> n >> a >> b;
  if(a+b==0){
    cout << 0 << endl;
    return 0;
  }
  int64_t amari = min(n%(a+b),a);
  cout << amari+n/(a+b)*a << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    lvec x(2),y(2);
    rep(i,2) cin>>x[i]>>y[i];
    string s;
    rep(i,y[1]-y[0]) s+='U';
    rep(i,x[1]-x[0]) s+='R';
    rep(i,y[1]-y[0]) s+='D';
    rep(i,x[1]-x[0]+1) s+='L';
    rep(i,y[1]-y[0]+1) s+='U';
    rep(i,x[1]-x[0]+1) s+='R';
    s+='D';
    s+='R';
    rep(i,y[1]-y[0]+1) s+='D';
    rep(i,x[1]-x[0]+1) s+='L';
    s+='U';
    cout<<s<<endl;
}

Measured memory_bytes: 256
(let* ((n (read))
       (d (read))
       (x (read))
       (l (loop repeat n
                collect (read))))

  (defun f (p q)
    (multiple-value-bind (q r)
      (truncate p q)
      (if (zerop r)
        q
        (1+ q))))


  (defun g (s lst)
    (if (null lst)
      nil
      (cons (f s (car lst)) (g s (cdr lst)))))

  (format t "~A~%"
          (+ (reduce #'+ (g d l))
             x)))


Measured memory_bytes: 24396
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ii=pair<ll,ll>;
using vi=vector<ll>;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (ll)1e18
#define all(x) (x).begin(),(x).end()
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ld arr[n];
    for(int i=0;i<n;i++)cin>>arr[i];
    sort(arr,arr+n);
    ld sum=arr[0];
    for(int i=1;i<n;i++){
        sum+=arr[i];
        sum/=2.0;
    }
    cout<<sum<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define N	 100
void solve(){
	int a, b;
	cin>>a>>b;
	cout<<ceil((a+b)/2.0)<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,x;
	scanf("%d %d",&n,&x);
	int p=0;
	double zong=0;
	for(int i=1;i<=n;i++)
	{
		int k=0;
		for(int t=i;;)
		{
			if(t>=x)break;
			else
			{
				t=t*2;
				k++;
			}
		}
		zong=zong+1.0/n*pow(0.5,k);
	}
	printf("%.12f",zong);
	return 0;
}

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

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      StrSplitToInt str;
      int n = Integer.parseInt(br.readLine());
      int[] seqA = new int[n];
      str = new StrSplitToInt(br.readLine(), " ");
      for(int i=0; i<n; i++) {
        seqA[i] = str.nextInt();
      }
      int q = Integer.parseInt(br.readLine());
      int[] seqQ = new int[q];
      str = new StrSplitToInt(br.readLine(), " ");
      for(int i=0; i<q; i++) {
        seqQ[i] = str.nextInt();
      }

      boolean result = false;
      int i=0;
      for (int m : seqQ) {
        if( solve(n, seqA, i, m) )
          System.out.println("yes");
        else
          System.out.println("no");
      }
    }
  }

  private static boolean solve(int n, int[] a, int i, int m) {
    if( m == 0 ) return true;
    if( i >= n ) return false;

    boolean res = solve(n, a, i+1, m) || solve(n, a, i+1, m-a[i]);

    return res;
  }
}
 
class StrSplitToInt {
  final String s;
  final String split;
  final int endPos;
  final int splitLen;
  int currentPos;
  int nextPos;
 
  public StrSplitToInt(String s,String split) {
    this.s = s;
    this.split = split;
    currentPos = 0;
    nextPos = s.indexOf(split, currentPos);
    endPos = s.length();
    splitLen = split.length();
  }
 
  public int nextInt() {
    if( currentPos < endPos ) {
      int ret = Integer.parseInt( s.substring(currentPos, nextPos) );
      currentPos = nextPos + splitLen;
      nextPos = s.indexOf(split, currentPos);
      if(nextPos == -1) nextPos = endPos;
 
      return ret;
    }
    else
      return -1;
  }
}


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

void move(int x1, int y1, int x2, int y2) {
  if (y2 - y1 > 0 ) {
    for (int i = 0; i < y2 - y1; i++)
      cout << "U";
  }
  else {
    for (int i = 0; i < y1 - y2; i++)
      cout << "D";
  }
  if (x2 - x1 > 0) {
    for (int i = 0; i < x2 - x1; i++)
      cout << "R";
  }
  else {
    for (int i = 0; i < x1 - x2; i++)
      cout << "L";
  }
}

void move2(int x1, int y1, int x2, int y2) {
  if (x1 < x2) {
    cout << "L";
    x1--;
  }
  else {
    cout << "R";
    x1++;
  }
  if (y1 < y2) {
    y2++;
    move(x1, y1, x2, y2);
    cout << "D";
  }
  else {
    y2--;
    move(x1, y1, x2, y2);
    cout << "U";
  }
}

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  move(sx, sy, tx, ty);
  move(tx, ty, sx, sy);
  move2(sx, sy, tx, ty);
  move2(tx, ty, sx, sy);
  cout << endl;
}

Measured memory_bytes: 3592
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.nio.charset.IllegalCharsetNameException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        FastReader in = new FastReader();
        test a=new test();
        a.solve(in,out);
        out.close();
    }
}

class test {
    public void solve(FastReader in, PrintWriter out){
        String s=in.next();
        if(Character.isUpperCase(s.charAt(0))){
            out.println("A");
        }else{
            out.println("a");
        }
    }
}

class FastReader{
    BufferedReader br;
    StringTokenizer st;

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

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

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

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

    double nextDouble(){
        return Double.parseDouble(next());
    }
    String nextLine(){
        String str="";
        try{
            str=br.readLine();
        }
        catch(IOException e){
            e.printStackTrace();
        }
        return str;
    }
}

Measured memory_bytes: 32896
#include<stdio.h>

int main(){
    
    int h, m, s;
    scanf("%d\n",&s);
    
    h=s/3600;
    m=s%3600/60;
    s=s%3600%60;
    
    printf("%d:%d:%d\n",h ,m, s);
   
    return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
//fflush(stdin);
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
	ll n;
	cin>>n;
	ve <ll> arr(n-1);
	rep (i,0,n-1)
	{
		cin>>arr[i];
	}
	ll ans=0;
	ans+=arr[0];
	ans+=arr[n-2];
	rep (i,1,n-1)
	{
		ans+=min(arr[i],arr[i-1]);
	}
	cout<<ans<<"\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
main()
{
    int d, n;
    cin >> d >> n;
    int res = 1;
    for(int i = 1; i <= d; i++)
        res *= 100;
    if(n == 100)
        res *= (n+1);
    else
        res *= n;
    cout << res << endl;
//    main();
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (x, y) = readLine()!!.split(" ").map { it.toInt() }
    val three = 100000
    val two = 200000
    val one = 300000
    val double = 400000
    val calc = { i: Int ->
        when (i) {
            3 -> three
            2 -> two
            1 -> one
            else -> 0
        }
    }
    var sum = 0
    sum = calc(x) + calc(y)
    if (x == 1 && y == 1) {
        sum += double
    }
    println(sum)
}

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

bool field[11][10010];
int r, c;

int calc(int bit){
  for(int i = 0 ; i < r ; i++){
    if((bit >> i) & 1){
      for(int j = 0 ; j < c ; j++){
	field[i][j] = !field[i][j];
      }
    }
  }
  
  int ret = 0;
  for(int i = 0 ; i < c ; i++){
    int a = 0, b = 0;
    for(int j = 0 ; j < r ; j++){
      a += field[j][i];
      b += !field[j][i];
    }
    ret += max(a, b);
  }
  
  for(int i = 0 ; i < r ; i++){
    if(bit >> i & 1){
      for(int j = 0 ; j < c ; j++){
	field[i][j] = !field[i][j];
      }
    }
  }
  
  return ret;
} 

int main(){
  while(cin >> r >> c){
    if(r == 0 && c == 0) break;
    
    for(int i = 0 ; i < r ; i++){
      for(int j = 0 ; j < c ; j++){
	cin >> field[i][j];
      }
    }
    
    int ans = 0;
    for(int i = 0 ; i < (1<<r) ; i++){ //bit know reverse position
      ans = max(ans, calc(i));
    }
    
    cout << ans << endl;
  }
  return 0;
}

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

ll f(ll x) {
  ++x;
  ll res = 0;
  ll t = 2;
  for(int i = 0; i < 50; ++i){
    ll tmp = (x / t) * (t / 2);
    ll d = x % t - t / 2;
    tmp += max(0LL, d);
    if(tmp % 2) res += t / 2;
    t = t<<1;
  }
  return res;
}

int main(){
  ll a, b;
  cin >> a >> b;
  cout << (f(b) ^ f(a - 1)) << endl;
}

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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x;
  cin >> n >> x;
  vector<int> m;
  for(int i=0, cur; i<n; i++){
    cin >> cur;
    m.push_back(cur);
  }
  sort(m.begin(), m.end());
  int ans = 0;
  for(auto y : m){
    if(x <= 0) break;
    x -= y;
    ans++;
  }
  for(auto y : m){
    if(x <= 0 || y > x) break;
    ans += x / y;
    x %= y;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int N,W,H,L;
vector<P> t;

bool check(P p,int a){
  if(p.first<p.second)
    return (p.first<=a&&a<=p.second);
  return (p.first<=a||a<=p.second);
}
int solve(int si){
  int res=1,last=t[si].second;
  for(int i=si;i<si+N;i++){
    if(check(t[i],last)) continue;
    res++;
    last=t[i].second;
  }
  return res;
}
int main(){
  cin>>N>>W>>H;
  L=W+W+H+H;
  for(int i=0;i<N;i++){
    int x,y,a,b;
    char ch;
    cin>>x>>y>>ch;
    if(ch=='N'){
      a = (x+y+L)%L;
      b = (H+x-y+H)%L;
    }
    if(ch=='E'){
      a = (H+H-y+x+L)%L;
      b = (L-y-x)%L;
    }
    if(ch=='S'){
      a = (L-x-y+L)%L;
      b = (L-x+y)%L;
    }
    if(ch=='W'){
      a = (y-x+L)%L;
      b = (y+x)%L;
    } 
    t.push_back(P(a,b));
  }
  for(int i=0;i<N;i++) swap(t[i].first,t[i].second);
  sort(t.begin(),t.end());
  for(int i=0;i<N;i++) t.push_back(t[i]);
  for(int i=0;i<N+N;i++) swap(t[i].first,t[i].second);
  int ans = N;
  for(int i=0;i<N;i++)ans = min(ans,solve(i));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3124
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.NavigableSet;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		char[] s = br.readLine().toCharArray();
		br.close();

		List<TreeSet<Integer>> list = new ArrayList<>(26);
		for (int i = 0; i < 26; i++) {
			list.add(new TreeSet<>());
		}
		for (int i = 0; i < n; i++) {
			list.get(s[i] - 'a').add(i);
		}

		int ans = 0;
		for (int i = 0; i < n - 1; i++) {
			TreeSet<Integer> set = list.get(s[i] - 'a');
			NavigableSet<Integer> set2 = set.tailSet(i, false);
			label:
			for (int j : set2) {
				int end = j - i;
				if (j + end > n) {
					end = n - j;
				}
				if (end < ans) {
					continue;
				}
				for (int k = 0; k < end; k++) {
					if (s[i + k] != s[j + k]) {
						ans = Math.max(ans, k);
						j += k - 1;
						continue label;
					}
				}
				ans = Math.max(ans, end);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 26180
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  unordered_map<ll, ll> mp;
  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    mp[A.at(i)] += 1;
  }
  for (ll i = N - 1; i >= 0; --i) {
    if (mp[A.at(i)] == 0) {
      continue;
    }
    mp[A.at(i)] -= 1;
    ll pow2 = 1;
    while (pow2 <= A.at(i)) {
      pow2 *= 2;
    }
    ll need = pow2 - A.at(i);
    // cout << "need" << need << endl;
    if (mp[need] != 0) {
      mp[need] -= 1;
      ans += 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 18420
#include<bits/stdc++.h>
     
    #define INF 1000000007
    #define LINF 1000000000000000007
     
    using namespace std;
     
    typedef long long ll;
    typedef pair<ll, ll> P;
     
    int a,b;
     
    int main(){
    	cin >> a>>b;
     
    	ll c = 0;
    	for(int i = 0; i <= 999; i++){
    		if(i == b-a){
    			cout << c-b << endl;
    			break;
    		}
    		c += i+1;
    	}
    	
    	return 0;
    }

Measured memory_bytes: 256
import functools


N, MOD = int(input()), 10 ** 9 + 7


def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True


@functools.lru_cache(maxsize=None)
def dfs(cur, last3):
    if cur == N:
        return 1
    ret = 0
    for c in 'ACGT':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:] + c)) % MOD
    return ret


print(dfs(0, 'TTT'))


Measured memory_bytes: 5544
import kotlin.system.exitProcess

val dic = mutableMapOf<Long, Char>()

fun main(args: Array<String>) {
	val (n, m) = readLine()!!.split(' ').map { it.toLong() }
	val s = readLine()!!
	val t = readLine()!!

	val l = lcm(n, m)

	judge(s, l)
	judge(t, l)
	println(l)
}

fun judge(s: String, l: Long) {
	for ((i, c) in s.withIndex()) {
		val j = l / s.length * i
		if (dic[j] != null && dic[j] != c) {
			println(-1)
			exitProcess(0)
		}
		dic[j] = c
	}
}

fun gcd(a: Long, b: Long): Long {
	return when {
		a < b -> {
			gcd(b, a)
		}
		b == 0L -> {
			a
		}
		else -> {
			gcd(b, a % b)
		}
	}
}

fun lcm(a: Long, b: Long): Long {
	return (a * b) / gcd(a, b)
}


Measured memory_bytes: 50668
using System;

public class test
{
  static void Main(string[] args)
  {
    string n = Console.ReadLine();
    string[] arry =  n.Split(' ');

    int max = int.Parse(arry[0]);
    int[] nums = new int[max];

    int max2 = int.Parse(arry[1]);
    int[] nums2 = new int[max2];

    string n2 = Console.ReadLine();
    string[] arry2 =  n2.Split(' ');

    int[] val = new int[arry2.Length];
    for ( int i=0; i<val.Length; i++ )
    {
      val[i] = int.Parse(arry2[i]);
    }

    Array.Sort(val);

    for ( int i=0; i<max2; i++ )
    {
      nums2[i] = val[i];
    }

    int b = 0;

    for ( int i=0; i<max2; i++ )
    {
      b += nums2[i];
    }

    Console.WriteLine(b);
  }
}

Measured memory_bytes: 27900
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pii;

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<unordered_set<int>> dp(4);
  dp[0].insert(0);
  for (char c : S) {
    int digit = c - '0';
    for (int i = 3; i >= 1; i--) {
      for (int num : dp[i - 1]) {
        dp[i].insert(num * 10 + digit);
      }
    }
  }
  cout << dp[3].size() << endl;
  return 0;
}


Measured memory_bytes: 384
//
// Created by kuroneko on 2019-07-06.
//

#include <iostream>
#include <vector>
#include <string>

typedef long long ll;
using namespace std;

int main() {
    int N, K; cin >> N >> K; K--;
    string s; cin >> s;

    if (s[K] == 'A') s[K] = 'a';
    else if (s[K] == 'B') s[K] = 'b';
    else s[K] = 'c';

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef queue<int> Q;

int main(){
    int n; cin>>n;
    map<string, vector<P>> map;
    for(int i=0; i<n; i++){
        string s;
        int p;
        cin>>s>>p;
        map[s].push_back(make_pair(p,i));
    }
    for(auto p: map){
        sort(ALL(p.second),greater<P>());
        for(int i=0; i<p.second.size(); i++) OUT(p.second[i].second+1);
    }
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = list(map(str, input()))

if S[K-1] == 'A':
    S[K-1] = 'a'
elif S[K-1] == 'B':
    S[K-1] = 'b'
else:
    S[K-1] = 'c'
    
T = ''.join(S)

print(T)

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

#define ll long long
#define p_q priority_queue
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)


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

    vector<vector<ll>> abc(n+1,vector<ll>(3,0));

    vector<vector<ll>> dp(n+1,vector<ll>(3,0));

    for(ll i=1;i<=n;i++){
        cin>>abc.at(i).at(0)>>abc.at(i).at(1)>>abc.at(i).at(2);
    }

    for(ll i=1;i<=n;i++){
        for(ll j=0;j<3;j++){
            for(ll k=0;k<3;k++){
                if(j==k)continue;
                dp.at(i).at(j) =
                        max(dp.at(i-1).at(k)+abc.at(i).at(k),dp.at(i).at(j));
            }
        }
    }

    ll ans = max(dp.at(n).at(0),dp.at(n).at(1));
    ans = max(dp.at(n).at(2),ans);

    cout<<ans<<endl;
}


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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    string s;
    int k;
    cin >> s >> k;
    int sz = SZ(s);
    set<string> S;
    FOR(l, 1, 5) {
        for (int i = 0; i + l <= sz; i++) {
            string ss = s.substr(i, l);
            S.insert(ss);
        }
    }
    vector<string> V;
    for (auto ss : S) {
        V.push_back(ss);
    }
    cout << V[k - 1] << endl;

}

Measured memory_bytes: 1920
n = int(input())
d = list(map(int, input().split()))

l = [0]*(max(d)+1)
for i in d:
    l[i] += 1

if d[0] != 0 or l[0] != 1:
    print(0)
    exit()

ans = 1
for i in range(1, len(l)):
    ans *= l[i-1]**l[i]

print(ans%998244353)

Measured memory_bytes: 52824
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d;
    int e,f,g,h;
    cin >> a >> b >> c >> d;
    cin >> e >> f >> g >> h;
    int x = a+b+c+d;
    int y = e+f+g+h;
    if(x>y){
        cout << x <<endl;
    }
    else{
        cout << y << endl;
    }
    
}


Measured memory_bytes: 3032
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i = 3; i <= n; i++){
	if(i % 3 == 0){
	cout << " " << i;
	continue;
	}
	if(i < 100 && (i / 10 == 3 || i % 10 == 3)){
	cout << " " << i;
	continue;
	}
	int a = i %100;
	if(i < 1000 && (i / 100 == 3 || a / 10 == 3 || a % 10 == 3)){
        cout << " " << i;
        continue;
	}
	int b = i % 1000;
	if(i < 10000 && (i / 1000 == 3 || b / 100 == 3 || a / 10 == 3 || a % 10 == 3)){
	cout << " " << i;
	continue;
	}
        }
	 cout << endl;
	return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

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

  int p[n], a[n];

  int cnt = 0;

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

  for(int i=0; i<n; ++i) a[i] = i+1;

  for(int i=0; i<n; ++i){
    if(p[i] != a[i]) cnt++;
  }

  if(cnt == 2 || cnt == 0) cout << "YES";
  else cout << "NO";

  return 0;
}

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

int main(){
    array<int,6> n;
    array<int,3> prob;
    array<int,3> mod;

    while(true){
        for( auto &t:n ) cin>>t;
        if( !accumulate(n.begin(),n.end(),0,[](int acc,int x){ return acc|x;}) ) break;

        for( int i=0; i<3;i++ ){
            prob[i]=n[i]+n[i+3];
            mod[i]=prob[i]%3;
        }

        int sum=0;

        for( auto t:prob ){
            sum += t/3;
        }

        if( mod[0]>0 && mod[1]>0 && mod[2]>0 ){
            sum += min({mod[0],mod[1],mod[2]});
        }else if( mod[0]==2 ){
            if( mod[1]==2 && prob[2]/3>0 || mod[2]==2 && prob[1]/3>0 ){
                sum++;
            }
        }else{
            if( mod[1]==mod[2] && mod[2]==2 && prob[0]/3>0 ){
                sum++;
            }
        }

        cout<<sum<<endl;
    }

    return 0;
}

Measured memory_bytes: 1160