akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;


const int MAX_ROW = 510; // to be set appropriately
const int MAX_COL = 510; // to be set appropriately
struct BitMatrix {
    int H, W;
    bitset<MAX_COL> val[MAX_ROW];
    BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
    inline bitset<MAX_COL>& operator [] (int i) {return val[i];}
};

int GaussJordan(BitMatrix &A, bool is_extended = false) {
    int rank = 0;
    for (int col = 0; col < A.W; ++col) {
        if (is_extended && col == A.W - 1) break;
        int pivot = -1;
        for (int row = rank; row < A.H; ++row) {
            if (A[row][col]) {
                pivot = row;
                break;
            }
        }
        if (pivot == -1) continue;
        swap(A[pivot], A[rank]);
        for (int row = 0; row < A.H; ++row) {
            if (row != rank && A[row][col]) A[row] ^= A[rank];
        }
        ++rank;
    }
    return rank;
}


const int MOD = 998244353;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() { 
    int N, M; cin >> N >> M;
    BitMatrix A(N, M);
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            int a; cin >> a;
            if (a) A[i][j] = 1;
        }
    }
    vector<int> res;
    int r = GaussJordan(A);  
    cout << (modpow(2LL, N+M-1, MOD) - modpow(2LL, N+M-r-1, MOD) + MOD) % MOD << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}


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

  int n,m;
  cin>>n>>m;
  string s;
  cin>>s;
  vi v;
  rep(i,s.size()){
    if(s[i]=='0') v.PB(1);
    else v[v.size()-1]++;
  }
  v.erase(v.end()-1);

  rep(i,v.size()){
    if(v[i]>m){
      cout<<-1<<endl;
      return 0;
    }
    //cout<<v[i]<<endl;
  }

  rrep(i,v.size()-1){
    if(i==0) break;
    if(v[i-1]+v[i]<=m){
      v[i-1]+=v[i];
      v.erase(v.begin()+i);
    }
  }

  rep(i,v.size()){
    cout<<v[i]<<endl;
  }


}

Measured memory_bytes: 1528
import heapq
n,m=map(int,input().split())
a=list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(a)
while m>0:
  heapq.heappush(a,(-1)*int((-1)*heapq.heappop(a)//2))
  m=m-1

print(-sum(a))

Measured memory_bytes: 14180
#include <stdio.h>

int main(void)
{
    int N;
    long double p_ans,p_1,p_2,p_3;
    
    scanf("%d",&N);
    
    if(N%2 == 0){
        p_ans = 0.5;
    } else {
        p_1 = N-1;
        p_2 = p_1/2;
        p_3 = p_2 + 1;
        p_ans = p_3/N;
    }
    
    printf("%Lf\n",p_ans);
 
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

#define INF ((1LL << 31) - 1)
#define MOD int(1e9)
#define repi(i,j,n) for (int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    string s;
    cin >> s;
    if (s[0] == s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
    ll A, B, N; cin >> A >> B >> N;
    if (N < B) {
        cout << (A*N)/B << endl;
    }
    else {
        cout << (A*(B-1))/B - A*((B-1)/B) << endl;
    }
}

Measured memory_bytes: 3544
#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 x first
#define y second
#define N 131072
#define pi acos(-1)
typedef complex<double> C;
vector<int> prime;
int isprime[10005];
int main(){
	for(int i = 2;i<10005;i++){
		if(!isprime[i]){
			prime.pb(i);
			for(int j =i;j<10005;j+=i){
				isprime[j]=1;
			}
		}
	}
	int n;
	scanf("%d",&n);
	int a[10005];
	for(int i = 0;i<=n;i++)
	scanf("%d",&a[i]);
	int gcd=abs(a[0]);
	for(int i = 1;i<=n;i++){
		gcd=__gcd(gcd,abs(a[i]));
	}
	set<int> s;
	a[n]=abs(a[n]);
	for(int i = 2;i*i<=a[n];i++){
		while(a[n]%i==0){
			s.insert(i);
			a[n]/=i;
		}
	}
	if(a[n]!=1&&a[n]!=0)
	s.insert(a[n]);
	set<int> ans;
	for(auto it:s){
		LL cnt[10005];
		fill(cnt,cnt+10005,0);
		int mod=it-1;
		for(int i = 0;i<n;i++){
			int degree=n-i;
			cnt[degree%mod]+=a[i];
		}
		int ok=1;
		for(int i = 0;i<mod&&i<=n;i++){
			if(cnt[i]%it!=0)
			ok=0;
		}
		if(ok)ans.insert(it);
	}
	if(a[n]==0){
		for(auto it:prime){
			LL cnt[10005];
			fill(cnt,cnt+10005,0);
			int mod=it-1;
			for(int i = 0;i<n;i++){
				int degree=n-i;
				cnt[degree%mod]+=a[i];
			}
			int ok=1;
			for(int i = 0;i<mod&&i<=n;i++){
				if(cnt[i]%it!=0)
				ok=0;
			}
			if(ok)ans.insert(it);
		}
		for(int i = 2;i*i<=gcd;i++){
			if(gcd%i==0){
				//if(ans.back()<i)
				ans.insert(i);
				while(gcd%i==0){
					gcd/=i;
				}
			}
		}
		if(gcd!=1){
			//if(ans.back()<gcd)
			ans.insert(gcd);
		}
	}
	for(auto it:ans)
	printf("%d\n",it);
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, d, x, a;
    cin >> n >> d >> x;
    while (n--) cin >> a, x += (d - 1) / a + 1;
    cout << x;
}


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

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

fn main() {
    let a = read::<i64>();
    let b = read::<i64>();
    let d = b - a;
    let ans = d * (1 + d) / 2 - b;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
    using namespace std;
    typedef unsigned long long ull;
    typedef long long ll;
    typedef long double ld;
    #define FOR(type,a,b,c,d) for(type i = a;i b c;i += d)
    #define QUICK ios_base::sync_with_stdio(0);cout << fixed;
    #define MOD 1000000007

    string upper(string);
    string lower(string);
    bool isalup(string);
    bool isalow(string);

    int main(){

      ll a,b;;
      cin >> a >> b;
      vector<ll>wow(a);
      for(int i = 0;i<a;i++){
        cin >> wow[i];
        if(i>=b){
           ll res = wow[i-1]*wow[i-b],res_2 = wow[i]*wow[i-1];
           cout << (res_2>res?"Yes\n":"No\n");
        }
      }

        return 0;
    }









                string upper(string a){
                    for(char& c:a){
                        if(islower(c))
                            c -= 32;
                       }
                    return a;
                }
                    string lower(string a){
                        for(char& c : a){
                            if(isupper(c))
                                c += 32;
                        }
                        return a;
                    }
                    bool isalup(string a){
                        for(char& c: a){
                            if(islower(c))
                                return false;
                        }
                        return true;
                    }
                    bool isalow(string a){
                        for(char& c:a){
                            if(isupper(c))
                                return false;
                        }
                       return true;
                    }


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

char i[200005];
int ans,len;

int main()
{
  int count=0;

  scanf("%s",i);
  for(int c=0;i[c];c++)
  {
    if (i[c]=='S')count++;
    else if (i[c]=='T'&&count>0)count--,ans++;
    len++;
  }
  printf("%d\n",len-(ans*2));
}


Measured memory_bytes: 384
import java.util.*;


public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			
			char [][] data = new char[n][n];
			for(int i = 0; i < n; i++){
				String str = sc.next();
				for(int j = 0; j < str.length();j++){
					data[i][j] = str.charAt(j);
				}
			}
			if(n == 1){
				System.out.println(1);
				continue;
			}
			
			boolean [][][] dp = new boolean[n][n][n];
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					dp[i][j][0] = true;
				}
			}
			
			int sum = 0;
			for(int i = 1; i < n; i++){
				for(int j = 0; j< n; j++){
					for(int k = 0; k < n; k++){
						if(dp[j][k][i-1] == false) continue;
						dp[j][k][i] = dp[j][k][i-1] && dp[(j+1)%n][(k+1)%n][i-1] && data[j][(k+i)%n] == data[(j+i)%n][k];
						if(i == n-1 && dp[j][k][i]){
							sum ++;
						}
					}
				}
			}

			System.out.println(sum);
		}
	}

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

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

}


Measured memory_bytes: 57624
import java.io.FileNotFoundException;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		BigInteger sum = BigInteger.valueOf(0);
		BigInteger sqsum = BigInteger.valueOf(0);

		for(int i=0;i<N;i++) {
			int A = sc.nextInt();
			BigInteger bigA = BigInteger.valueOf(A);
			sum = sum.add(bigA);
			sqsum = sqsum.add(bigA.pow(2));
		}
		BigInteger sumsq = sum.pow(2);
		BigInteger d = (sumsq.subtract(sqsum)).divide(BigInteger.valueOf(2));

		BigInteger ans = d.mod(BigInteger.valueOf(1000000007));

		System.out.println(ans);
	}
}


Measured memory_bytes: 58716
N = int(input())
s = [""]*N #[]*Nとしてしまうと, 要素が何もないのでindex指定ができない
t = [""]*N

for i in range(N):
    s[i],t[i] = input().split()
    t[i] = int(t[i])
X = input()

index=0
for i in range(N):
    if s[i]==X:
        index=i+1

ans=0
"""
if index==N:
    print(0)
    exit()
else:
"""
for i in range(index,N):
    ans+= t[i]

print(ans)

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());

        int count = 0;
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= b; j++) {
                for (int k = 0; k <= c; k++) {
                    int result = 500 * i + 100 * j + k * 50;
                    if (result == x) {
                        count++;
                    }
                }
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 22228
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<LL> a(n);
		REP(i,n) cin >> a[i];
		LL suma = accumulate(ALL(a),0LL);
		LL sum = 0;
		LL ans = 1e18;
		REP(i,n-1){
			sum += a[i];
			chmin(ans, abs(sum-(suma-sum)));
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1792
#include<complex>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<deque>
#include<queue>
#include<climits>
#include<list>
#include<stack>
#include<fstream>
#include<ctime>
#define all(n) n.begin(),n.end()
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define pb push_back
#define INF (1<<27)
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)

using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef unsigned long long ull;
typedef long long ll;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};


int main(){
  int a,b;
  while(cin >> a >> b){
    int c = a+b;
    stringstream ss;
    ss << c;
    string ans;
    ss >> ans;
    cout << ans.length() << endl;
  }

  /* 
  ofstream ofs("tes");
  ofs << "script -k test.log" << endl;
  system("chmod 755 tes");
  system("at -m -f tes 2:35");
  

  
  system("at exit 2:40");
  system("at cat test.log 2:41");
  */

//ofstream ofs("test.t");
//ofs << "testetete" << endl;
  //cerr << system("rm test.t") << endl;


return 0;
}

Measured memory_bytes: 1220
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

ll gcd(ll A, ll B) {
	if (B == 0) return A;
	return gcd(B, A % B);
}

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


	int N;
	cin >> N;
	pair<ll, ll> AB[200200], BA[200200];
	int a0 = 0, b0 = 0;
	int ab00 = 0;
	int ka = 0, kb = 0;
	rep(i, N) {
		ll a, b;
		cin >> a >> b;

		if (a == 0 && b == 0) {
			ab00++;
			continue;
		}
		if (a == 0) {
			a0++;
			continue;
		}
		if (b == 0) {
			b0++;
			continue;
		}

		ll G = gcd(a, b);
		a /= G;
		b /= G;
		if (a < 0) {
			a = -a;
			b = -b;
		}
		if (b > 0) AB[ka++] = { a,b };
		else BA[kb++] = { -b,a };
	}

	ll kotae = 1;
	sort(AB, AB + ka);
	sort(BA, BA + kb);
	BA[kb] = { 2e18, 2e18 };

	pair<ll, ll> mae = AB[0];
	int p = 0;
	int kA = 0;
	rep(i, ka) {
		ll a = AB[i].first;
		ll b = AB[i].second;
		if (mae != AB[i]) {
			int tmp = 0;

			pair<ll, ll> mae2 = BA[p];
			int kB = 0;
			while (p < kb && BA[p] <= mae) {
				if (mae2 != BA[p]) {
					kotae = kotae * modpow(2, kB) % mod;
					mae2 = BA[p];
					kB = 1;
				}
				else kB++;
				p++;
			}

			if (mae == mae2) {
				tmp = kB;
			}
			else {
				kotae = kotae * modpow(2, kB) % mod;
			}

			if (tmp) {
				kotae = kotae * (modpow(2, kA) + modpow(2, kB) - 1) % mod;
			}
			else {
				kotae = kotae * modpow(2, kA) % mod;
			}

			mae = AB[i];
			kA = 1;
		}
		else kA++;
	}

	int tmp = 0;
	pair<ll, ll> mae2 = BA[p];
	int kB = 0;
	while (p < kb) {
		if (mae2 != BA[p]) {
			if (AB[ka - 1] == mae2) {
				tmp = kB;
			}
			else {
				kotae = kotae * modpow(2, kB) % mod;
			}
			mae2 = BA[p];
			kB = 1;
		}
		else kB++;
		p++;
	}

	if (AB[ka - 1] == mae2) {
		tmp = kB;
	}
	else {
		kotae = kotae * modpow(2, kB) % mod;
	}

	if (tmp) {
		kotae = kotae * (modpow(2, kA) + modpow(2, kB) - 1) % mod;
	}
	else {
		kotae = kotae * modpow(2, kA) % mod;
	}

	kotae = kotae * (modpow(2, a0) + modpow(2, b0) - 1) % mod;

	co((kotae - 1 + ab00 + 2 * mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 9920
//
//  main.cpp
//  abc专用
//
//  Created by 张伟 on 2018/9/23.
//  Copyright © 2018年 张恺. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argc, const char * argv[]) {
    int a,b,c;
    cin>>a>>b>>c;
    if(a>=b&&a>=c){
        printf("%d",a*10+b+c);
    }else if(b>=a&&b>=c){
        printf("%d",b*10+a+c);
    }else{
        printf("%d",a+b+10*c);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a,b,ans=0;
    cin>>a>>b;
    if(a>b)swap(a,b);
    ans+=b;
    b--;
    if(a>b)swap(a,b);
    ans+=b;
    cout<<ans;
    return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;




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

    int n;
    cin>>n;

    int cur=0;
    while (n--) {
	int x,y;
	cin>>x>>y;
	if (x==y) {
	    ++cur;
	    if (cur>=3) out("Yes");
	} else {
	    cur=0;
	}
    }

    out("No");
    
    
    return 0;
}


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


int main() {
    int a, b, k;
    cin >> a >> b >> k;

    vector<int> x;
    for (int i = 1; i <= a; i++) {
        if (a%i == 0 && b%i == 0) {
            x.push_back(i);
        }
    }

    reverse(x.begin(), x.end());
    cout << x[k-1] << endl;
    return 0;
}

Measured memory_bytes: 3568
# AtCoder Grand Contest 026 A
SLIME_NUMBER = int(input())
SLIMES = tuple([int(s) for s in input().split()])

magic = 0

def is_repetitive(index):
    if index == SLIME_NUMBER - 1:
        return False
    return SLIMES[index] == SLIMES[index + 1]

index = 0
while index < SLIME_NUMBER - 1:
    if not is_repetitive(index):
        index += 1
        continue
    magic += 1
    additional_index = 1
    while is_repetitive(index + additional_index):
        if additional_index % 2 == 0:
            magic += 1
        additional_index += 1
    index += additional_index + 1
print(magic)

Measured memory_bytes: 3064
x=input()
a=[0]
d={}
d[0]=0
for i in range(1,1000):
	a+=[i**5]
	a+=[-i**5]
	d[i**5]=i
	d[-i**5]=-i

a.sort()
for i in range(len(a)):
    if x+a[i] in a:
        print d[a[i]+x],d[a[i]]
        break

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

#define INF (2e9)
#define FOR(i, a, b) for (ll (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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

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

using ll = long long;
using ld = long double;

#define ALL(x) (x).begin(), (x).end()
template<class T>
using vc = vector<T>;
using vi = vc<ll>;
using vvi = vc<vi>;

template<class T>
using va = valarray<T>;
using vad = va<ld>;
using vai = va<ll>;

vi Read(ll n) {
    auto      v = vi(n);
    for (auto i = std::size_t(0); i < n; ++i) {
        cin >> v[i];
    }
    return v;
}

template<class T>
void Dump(const T& A) {
    for (const auto& value : A)
        cout << value << "\n";
}

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

    ll n, p;
    cin >> n >> p;

    list<int> ls[n];

    REP(i, p) {
        int query;
        cin >> query;
        if (query == 0) {
            int t, x;
            cin >> t >> x;
            ls[t].push_back(x);
        } else if (query == 1) {
            int t;
            cin >> t;
            auto      isFirst = true;
            for (auto x : ls[t]) {
                if (isFirst) {
                    cout << x;
                    isFirst = false;
                } else cout << " " << x;
            }
            cout << endl;
        } else if (query == 2) {
            int s, t;
            cin >> s >> t;
            ls[t].splice(ls[t].end(), move(ls[s]));
        } else cout << "Error: query is not correct\n";
    }

    return 0;
}



Measured memory_bytes: 18784
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner (System.in);
    String s = sc.next();
    char a[] = new char[3];
    int count = 0;
    for(int i=0 ; i<3 ; i++){
      a[i] = s.charAt(i);
    }
    Arrays.sort(a);
    for(int i=0 ; i<3 ; i++){
      if(a[i]=='1'){
        count++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21716
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        char ch[] = str.toCharArray();
        for(int i = 0; i < str.length(); i++){
            if(Character.isUpperCase(ch[i])){
                ch[i] = Character.toLowerCase(ch[i]);
            }
            else if(Character.isLowerCase(ch[i])){
                ch[i] = Character.toUpperCase(ch[i]);
            }
        }
        System.out.println(ch);
    }
}

Measured memory_bytes: 26128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;


public class Main{

	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner s = new Scanner(System.in);
		int cnt = new Integer(br.readLine()).intValue();
		String[] strArray = br.readLine().split(" ");
		int[] array = new int[cnt];
		for(int i=0 ; i<strArray.length ; i++) {
			array[i] = new Integer(strArray[i]).intValue();
		}
		sort(array);
	}

	public static void sort(int[] array) {
		int[] cntArray = new int[10001];
		int[] resultArray = new int[array.length];
		for(int i=0 ; i<array.length ; i++) {
			cntArray[array[i]]++;
		}
		for(int i=1 ; i<cntArray.length ; i++) {
			cntArray[i] = cntArray[i] + cntArray[i-1];
		}
		for(int i=array.length-1 ; i>=0 ; i--) {
			resultArray[cntArray[array[i]]-1] = array[i];
			cntArray[array[i]]--;
		}
		StringBuffer b = new StringBuffer();
		for(int i=0 ; i<resultArray.length ; i++) {
			b.append(resultArray[i]).append(" ");
		}
		System.out.println(b.toString().trim());
	}

}

Measured memory_bytes: 256648
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var s = next();
	var t = next();
	var map = {};
	var list = "abcdefghijklmnopqrstuvwxyz";
	for(var i = 0; i < list.length; i++){
		map[list[i]] = new Set();
	}
	for(var i = 0; i < s.length; i++){
		map[s[i]].add(i);
	}
	for(var i = 0; i < s.length; i++){
		for(var j = 0; j < list.length; j++){
			if(map[list[j]].has(i) && list[j] != t[i]){
				var tmp = map[list[j]];
				map[list[j]] = map[t[i]];
				map[t[i]] = tmp;
			}
		}
	}
	var output = new Array(s.length);
	var keys = Object.keys(map);
	for(var i = 0; i < keys.length; i++){
		var indexes = Array.from(map[keys[i]]);
		for(var j = 0; j < indexes.length; j++){
			output[indexes[j]] = keys[i];
		}
	}
	output = myconv(output,0);
	myerr(t);
	myerr(output);
	if(output == t){
		myout("Yes");
	}else{
		myout("No");
	}
}

Measured memory_bytes: 35572
s = input()[::-1]
s += "0"
n = len(s)

dp = [[1001001001]*2 for _ in range(n+1)]

dp[0][0] = 0

for i in range(n):
    for j in range(2):
        x = int(s[i]) + j

        if x < 10:
            dp[i+1][0] = min(dp[i][j] + x,dp[i+1][0])
        if x > 0:
            dp[i+1][1] = min(dp[i][j] + (10 - x),dp[i+1][1])


print(dp[n][0])

Measured memory_bytes: 139756
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	int cnt = 0;
	rep(i, n) {
		int x;
		cin >> x;
		if (i + 1 != x) ++cnt;
	}
	if (cnt > 2) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define lim 100010
#define mod 1e9 + 7
#define INF 1e9
#define REP(i, n) for (int i = 0; i < n; i++)

ll GCD(int x, int y) { return x % y == 0 ? y : GCD(y, x % y); }

int main() {
  int N;
  scanf("%d", &N);
  ll X[N];
  REP(i, N) scanf("%lld", &X[i]);
  ll ans = INF;
  sort(X, X + N);
  for (ll i = X[0]; i <= X[N - 1]; i++) {
    ll tmp = 0;
    for (int j = 0; j < N; j++) {
      tmp += (X[j] - i) * (X[j] - i);
    }
    ans = tmp < ans ? tmp : ans;
  }
  printf("%lld", ans);

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using P = std::pair<int, int>;

int N, D1, D2;
std::vector<int> G1[360001], G2[360001];
int col[2][360001];
int cnt[4];
std::vector<P> ps;

void mkG( std::vector<int> *G, int D )
{
  rep( i, 2*N ) rep( j, 2*N )
    G[i*2*N+j].clear();

  ps.clear();

  rep( i, 2*N ) rep( j, 2*N ) if( i*i+j*j == D )
    ps.push_back( P( i, j ) );

  rep( i, 2*N ) rep( j, 2*N ) for( auto p : ps ) rep( s1, 2 ) rep( s2, 2 )
  {
    int k = i+pow(-1,s1)*p.first, l = j+pow(-1,s2)*p.second;
    
    if( k >= 0 && k < 2*N && l >= 0 && l < 2*N )
    {
      G[i*2*N+j].push_back( k*2*N+l );
      G[k*2*N+l].push_back( i*2*N+j );
    }
  }

  return;
}

void bfs( int v, int idx, std::vector<int> *G )
{
  std::queue<P> que;
  col[idx][v] = 1;
  que.push( P( v, 1 ) );

  while( !que.empty() )
  {
    P u = que.front();
    que.pop();

    //printf( "(%d,%d)\n", u.first, u.second );

    for( auto t : G[u.first] ) if( !col[idx][t] )
    {
      que.push( P( t, -u.second ) );
      col[idx][t] = -u.second;
    }
  }

  return;
}

int main()
{
  scanf( "%d%d%d", &N, &D1, &D2 );

  mkG( G1, D1 );

  rep( i, 2*N ) rep( j, 2*N ) if( !col[0][i*2*N+j] )
    bfs( i*2*N+j, 0, G1 );

  //puts("1");

  mkG( G2, D2 );

  //rep( i, G2[58559].size() )
    //printf("{%d}\n", G2[58559][i] );

  rep( i, 2*N ) rep( j, 2*N ) if( !col[1][i*2*N+j] )
    bfs( i*2*N+j, 1, G2 );

  //puts("2");

  rep( i, 2*N ) rep( j, 2*N ) 
  {
    int v = i*2*N+j;
    int kind = 0;

    rep( k, 2 ) rep( l, 2 )
    {
      if( col[0][v] == pow( -1, k ) && col[1][v] == pow( -1, l ) )
        ++cnt[kind];

      ++kind;
    }
  }

  int mkind = std::max_element( cnt, cnt+4 )-cnt;

  int sum = 0;

  rep( i, 2*N ) rep( j, 2*N ) 
  {
    int v = i*2*N+j;
    int kind = 0;

    rep( k, 2 ) rep( l, 2 )
    {
      if( col[0][v] == pow( -1, k ) && col[1][v] == pow( -1, l ) && kind == mkind && sum < N*N )
        printf( "%d %d\n", i, j ), ++sum;

      if( sum >= N*N )
        return 0;

      ++kind;
    }
  }  
  
  return 0;
}

Measured memory_bytes: 163136
import itertools
n = int(input())
l = list(map(int,input().split()))
t = list(itertools.combinations(l,3))
ans = 0
for i in range(len(t)):
    x = t[i][0]
    y = t[i][1]
    z = t[i][2]
    if x != y and y != z and z != x:
        if x < y+z and y < z+x and z < x+y:
            ans+=1
print(ans)

Measured memory_bytes: 20612
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define repp(i,a,b) for(int i = a ; i < b ; i++)
#define rep(i,n) repp(i,0,n)
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define reppr(i,a,b) for(int i = a-1 ; i>=b ; i--)
#define repr(i,n) reppr(i,n,0)
#define ff first
#define ss second
#define all(n) n.begin(),n.end()
#define SORT(a) sort(all(a));
#define REVERSE(a) reverse(all(a));

int powmod(int x,int y) 
{ 
    if (y == 0) return 1; 
    int p = powmod(x, y/2) % mod; 
    p = (p * p) % mod;   
    return (y%2 == 0) ? p : (x * p) % mod; 
}
 
int inverse(int a) 
{ 
   return powmod(a,mod-2); 
}

void solve();
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int t = 1;
	// cin >> t;
	while(t--) solve();
}

void solve()
{
	int n;
	cin >> n;
	int a[n] , ans = 0;
	rep(i,n) cin >> a[i] , ans += (i%2==0)*(a[i]%2==1);
	cout << ans << endl;
}

Measured memory_bytes: 3572
#include<iostream>
using namespace std;
int main(){
    int a;
    cin>>a;
    for(int i=1;i<=3;i++){
    if(a%10==7){
    cout<<"Yes";return 0;
    }
  else a=a/10;
  }
  cout<<"No";//如果没有输出no
}

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

// constexpr long MOD = 998244353;
constexpr long MOD = 1000000007;
vector<long> fact, inv;

long mpow(long a, long b) {
  long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b /= 2;
  }
  return res;
}

void init(int n) {
  fact.push_back(1);
  inv.push_back(1);
  for (int i = 0; i < n; i++) {
    fact.push_back(fact.at(i) * (i + 1) % MOD);
    inv.push_back(mpow(fact.at(i + 1), MOD - 2));
  }
}

long qcom(long n, long r) {
  if (n - r < 0) return 0;
  return fact.at(n) * inv.at(r) % MOD * inv.at(n - r) % MOD;
}

long com(long n, long r) {
  long x = 1, y = 1;
  for (int i = 1; i <= r; i++) {
    x = x * (n - i + 1) % MOD;
    y = y * i % MOD;
  }
  return x * mpow(y, MOD - 2) % MOD;
}

int main() {
  init(100000);
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.begin(), A.end());
  long ans = 0;
  for (int i = 0; i + 1 < N; i++) {
    ans += (qcom(N, K) - qcom(i + 1, K) - qcom(N - i - 1, K)) * (A.at(i + 1) - A.at(i));
    ans %= MOD;
  }
  while (ans < 0) ans += MOD;
  cout << ans << "\n";
}

Measured memory_bytes: 2156
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int>> data(n+1, vector<int>(m+2));
    for(int i = 0; i < n; i++){
        cin >> data[i][0];
        for(int j = 1; j <= m; j++) cin >> data[i][j];
    }
    int minPrice = 1000000000;
    for(int i = 0; i < pow(2, n); i++){
        vector<int> binary(n);
        int tmp = i, k = 0;
        while(tmp != 0){
            binary[k] = tmp % 2;
            tmp /= 2;
            k++; 
        }
        vector<int> calc(n+1);
        rep(j,n){
            if(binary[j] == 1){
                for(int k = 0; k <= m; k++) calc[k] += data[j][k];
            }
        }
        for(int k = 1; k <= m; k++){
            if(calc[k] < x) break;
            if(k == m) minPrice = min(minPrice, calc[0]);
        } 
        cout << endl;
    }
    if(minPrice == 1000000000) cout << "-1" << endl;
    else cout << minPrice << endl;
}

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

int main() {
  string s;
  cin >> s;
  
  string week[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT" };

  int today;
  for(int i=0; i<7; i++){
    if(s==week[i]){
      today = i;
      break;
    }
  }

  cout << 7-today << endl;

  return 0;
}

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

int main() {
  long long s; 
  cin >> s;
  if (s % 1000000000 == 0) 
    cout << "0 0 1 1000000000 " << s / 1000000000 << " 0" << endl;
  else 
    cout << "0 0 1 1000000000 " << s / 1000000000  + 1 << " " << 1000000000 - (s % 1000000000) << endl;
  return 0;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
typedef long long ll;

using namespace std;

int N, Q;
ll A[200010], B[200010]; //[0, 2 * N) !!
multiset<ll> S;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> Q;
	rep(i, 0, 2 * N) cin >> A[i];
	rep(i, 0, 2 * N) cin >> B[i];

	ll ans = 0; bool odd = false;
	ans += A[0] + A[2 * N - 1];
	rep(i, 1, 2 * N - 1) {
		ans += max(A[i], B[i]);
		odd ^= (A[i] > B[i]);
		S.insert(abs(A[i] - B[i]));
	}
	while(Q--) {
		ll a, x, y;
		cin >> a >> x >> y; a--;
		if(a == 0 || a == 2 * N - 1) {
			ans += x - A[a];
			A[a] = x;
		}
		else {
			odd ^= (A[a] > B[a]);
			odd ^= (x > y);
			ans += max(x, y) - max(A[a], B[a]);
			S.erase(S.lower_bound(abs(A[a] - B[a])));
			S.insert(abs(x - y));
			A[a] = x; B[a] = y;
		}
		cout << (!odd ? ans : ans - (*S.begin())) << "\n";
	}
}


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

int main(){
    str s; cin >> s;
    if(s == "SUN"){
        cout << 7 << endl;
    }else if(s == "SAT"){
        cout << 1 << endl;
    }else if(s == "FRI"){
        cout << 2 << endl;
    }else if(s == "THU"){
        cout << 3 << endl;
    }else if(s == "WED"){
        cout << 4 << endl;
    }else if(s == "TUE"){
        cout << 5 << endl;
    }else if(s == "MON"){
        cout << 6 << endl;
    }
    return 0;
}

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

using namespace std;

# define ll long long

const ll N = 1e5 + 10;

ll n, a[N];

int main() {
    cin >> n;
    for(int i = 1;i <= n;i++) {
        cin >> a[i];
    }
    a[1]--;
    for(int i = 2;i <= n;i++) {
        if(a[i] > a[i - 1]) {
            a[i]--;
        }
    }
    for(int i = 1;i < n;i++) {
        if(a[i] > a[i + 1]) {
            cout << "No";
            exit(false);
        }
    }
    cout << "Yes";
}


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

int main() {
  int N;
  cin >> N;
  vector<int>A(N);
  for(int i=0; i<N; i++)cin >> A.at(i);
  
  vector<int>B(N);
  for(int i =0; i<N; i++){
    B.at(A.at(i)-1)=i+1;
  }
  
  for(int i=0; i<N-1; i++){
    cout << B.at(i) << " ";
  }
  
  cout << B.at(N-1) << endl;
}

Measured memory_bytes: 3988
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int l = 0, r = 1000000001;
	while (l + 1 < r) {
		int c = (l + r) / 2;
		int cut = 0;
		for (int i = 0; i < n; i++) {
			cut += (a[i] + c - 1) / c - 1;
		}

		if (cut > k) {
			l = c;
		} else {
			r = c;
		}
	}
	cout << l + 1<< endl;

    return 0;
}

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

typedef long long ll;
const int MAX_HW = 2000;

int main() {
  int H, W;
  std::cin >> H >> W;

  std::vector<std::string> S(H);
  for(int i = 0; i < H; ++i) {
    std::cin >> S[i];
  }

  std::vector<std::vector<int>> cnt(H, std::vector<int>(W, 0));
  for(int i = 0; i < H; ++i) {
    std::vector<bool> done(W);
    for(int j = 0; j < W; ++j) {
      if(S[i][j] == '#' or done[j]) continue;
      int l = 1;
      while(j + l < W and S[i][j + l] != '#') {
        done[j + l] = true;
        ++l;
      }
      for(int k = j; k < j + l; ++k) {
        cnt[i][k] += l;
      }
    }
  }
  for(int j = 0; j < W; ++j) {
    std::vector<bool> done(H);
    for(int i = 0; i < H; ++i) {
      if(S[i][j] == '#' or done[i]) continue;
      int l = 1;
      while(i + l < H and S[i + l][j] != '#') {
        done[i + l] = true;
        ++l;
      }
      for(int k = i; k < i + l; ++k) {
        cnt[k][j] += l - 1;
      }
    }
  }

  int ans = 0;
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      ans = std::max(ans, cnt[i][j]);
    }
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 20096
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

string S, T;
int DP[3001][3001];

int LCS(){
  int N = S.length(), M = T.length();
  for (int i = 1; i <= N; i++){
    for (int j = 1; j <= M; j++){
      DP[i][j] = max(DP[i-1][j], DP[i][j-1]);
      if (S[i-1] == T[j-1]) DP[i][j] = DP[i-1][j-1] + 1;   
    }
  }
  
  int i = N, j = M;
  stack <char> st;
  while (i>0 && j>0){
    if (DP[i][j] == DP[i-1][j]) i--;
    else if(DP[i][j] == DP[i][j-1]) j--;
    else{
      st.push(S[i-1]);
      i--;j--;
    }
  }
  
  while (!st.empty()){
    cout << st.top(); st.pop();
  }
  cout << endl;
  
  return 0;
}

int main(){
  cin >> S >> T;LCS();
  return 0;
}

Measured memory_bytes: 35456
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
constexpr int INF = 1e9;

int main(void) {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }
    int d[H*W][H*W];
    for (int a = 0; a < W*H; a++) {
        for (int b = 0; b < W*H; b++) {
            int ai = a/W;
            int aj = a%W;
            int bi = b/W;
            int bj = b%W;
            d[a][b] = INF;
            if (S[ai][aj] != '#' && S[bi][bj] != '#') {
                if (a == b) d[a][a] = 0;
                if (((ai == bi) && (abs(aj-bj) == 1)) || ((aj == bj) && (abs(ai-bi) == 1))) {
                    d[a][b] = 1;
                }
            }
        }
    }
    for (int k = 0; k < W*H; k++) {
        if (d[k][k] == INF) continue;
        for (int a = 0; a < W*H; a++) {
            if (d[a][a] == INF) continue;
            for (int b = 0; b < W*H; b++) {
                d[a][b] = min(d[a][b], d[a][k] + d[k][b]);
            }
        }
    }

    int max_d = 0;
    for (int a = 0; a < W*H; a++) {
        for (int b = 0; b < W*H; b++) {
            if (d[a][b] >= INF) continue;
            max_d = max(d[a][b], max_d);
        }
    }
    cout << max_d << endl;

    return 0;
}



Measured memory_bytes: 896
using System;
namespace beginnercon001
{
	public class Program
	{
       public static void Main(string[] args)
    	{
        	string[] nums = Console.ReadLine().Split(' ');
        	int a = int.Parse(nums[0]);
         	int b = int.Parse(nums[1]);

        	if(b % a == 0)
        	{
                Console.WriteLine(a + b);
        	}
        	else
           	{
                Console.WriteLine(b - a);
           	}
    	}
	}
}


Measured memory_bytes: 11092
#include <iostream>
using namespace std;
int main() {
    int c[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j ++) cin >> c[i][j];
    }

    for (int i = 0; i < 2; i++) {
        int diff = c[0][i] - c[0][i + 1];
        for (int j = 1; j < 3; j++) {
            if (diff != c[j][i] - c[j][i + 1]) {puts("No"); return 0;}
        }
    }

    for (int i = 0; i < 2; i++) {
        int diff = c[i][0] - c[i + 1][0];
        for (int j = 1; j < 3; j++) {
            if (diff != c[i][j] - c[i + 1][j]) {puts("No"); return 0;}
        }
    }
    
    puts("Yes");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int fin[1000010];
vector<vector <int> > node;
map<pair<int,int> ,int> val;
bool sudah[1000010];

void solve(int pos)
{
	int x;
	for(x=0;x<node[pos].size();x++)
	{
		if(sudah[node[pos][x]]==0)
		{
			fin[node[pos][x]]=(fin[pos]+val[make_pair(node[pos][x],pos)])%2;
			sudah[node[pos][x]]=1;
			solve(node[pos][x]);
		}
	}
}
int main()
{
	int n;
	cin>>n;
	node.resize(n+10);
	int temp=n;
	n--;
	while(n--)
	{
		int a,b,c;
		cin>>a>>b>>c;
		node[a].push_back(b);
		node[b].push_back(a);
		val[make_pair(a,b)]=c;
		val[make_pair(b,a)]=c;
	}
	sudah[1]=1;
	solve(1);
	int x;
	for(x=1;x<=temp;x++)
	{
		cout<<fin[x]<<endl;
	}
}

Measured memory_bytes: 23808
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);

int n;
int arr[21][21];
int dp[21][1<<21];

int func(int idx, int mask)
{
	if(idx==n)
		return (mask == (int)pow(2,n)-1);
	int & ans = dp[idx][mask];
	if(ans != -1)
		return ans;
    ans = 0;
	for(int j=0;j<n;j++)
	{
		if(arr[idx][j] && !(mask & (1<<j)))
			ans = (ans + func(idx+1,mask|(1<<j)))%mod;
	}
	return ans;
}

int main()
{
	fast;
	cin>>n;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			cin>>arr[i][j];
	memset(dp,-1,sizeof(dp));
	cout<<func(0,0);
	return 0;
}

Measured memory_bytes: 172416
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e10
typedef long long ll;
typedef long double ld;
int main(){
    ll n,x,t; cin>>n>>x>>t;
    ll time=0;
    while(n>0){
        n-=x;
        time+=t;
    }
    cout<<time<<endl;
    return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    if(S.length()%2){
        cout<<NO<<endl;return;
    }
    bool isGood = true;
    while(!S.empty()){
        if(!(S.back()=='i')) {
            cout<<NO<<endl;return;
        }
        S.pop_back();
        if(!(S.back()=='h')) {
            cout<<NO<<endl;return;
        }
        S.pop_back();
    }
    cout<<YES<<endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Dance Dance Revolution
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T--!=0){
			char[] s = sc.next().toCharArray();
			boolean f = false;
			for(int i=0;i+1<s.length;i++)f|=s[i]==s[i+1];
			System.out.println(f?"No":"Yes");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
using namespace std;
#include <iostream>
#include <algorithm>
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#include <queue>

int main(){
    
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    ll A[X], B[Y], C[Z];
    rep(i,X) cin >> A[i];
    rep(i,Y) cin >> B[i];
    rep(i,Z) cin >> C[i];
    sort(C, C + Z, greater<ll>());
    priority_queue<pair<ll,int>> pairs;
    
    rep(i,X){
        rep(j,Y){
            pairs.push(make_pair(A[i] + B[j] + C[0], 0));
        }
    }

    for(int i = 0; i < K; i++){
        auto top = pairs.top();
        pairs.pop();
        cout << top.first << endl;
        if(top.second == Z - 1){
            continue;
        }
        pairs.push({top.first - C[top.second] + C[top.second + 1], top.second + 1});
    }



    return 0;
}


Measured memory_bytes: 18664