akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 3005;
const int MOD = (int)1e9 + 7;
const int IV2 = (MOD + 1) / 2;

int n, nq, ans, pw;
int a[N], dp[N][N], tmp[N][N];

int Add(int a, int b) { return (a += b) >= MOD? a - MOD : a; }
int Mul(int a, int b) { return (long long)a * b % MOD; }

int main() {
  scanf("%d%d", &n, &nq);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (a[i] > a[j]) {
        dp[i][j] = 1;
      }
    }
  }
  pw = 1;
  for (int x, y; nq--; ) {
    pw = Mul(pw, 2);
    scanf("%d%d", &x, &y);
    if (x == y) {
      continue;
    }
    tmp[x][y] = dp[x][y];
    tmp[y][x] = dp[y][x];
    for (int i = 1; i <= n; ++i) {
      tmp[i][x] = dp[i][x];
      tmp[x][i] = dp[x][i];
      tmp[i][y] = dp[i][y];
      tmp[y][i] = dp[y][i];
    }
    dp[x][y] = Add(Mul(tmp[y][x], IV2), Mul(tmp[x][y], IV2));
    dp[y][x] = Add(Mul(tmp[x][y], IV2), Mul(tmp[y][x], IV2));
    for (int i = 1; i <= n; ++i) {
      if (i == x || i == y) continue;
      dp[i][x] = Add(Mul(tmp[i][x], IV2), Mul(tmp[i][y], IV2));
      dp[x][i] = Add(Mul(tmp[x][i], IV2), Mul(tmp[y][i], IV2));
      dp[i][y] = Add(Mul(tmp[i][y], IV2), Mul(tmp[i][x], IV2));
      dp[y][i] = Add(Mul(tmp[y][i], IV2), Mul(tmp[x][i], IV2));
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      ans = Add(ans, dp[i][j]);
    }
  }
  printf("%d\n", Mul(ans, pw));
  return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 100005
#define m 1000000007
#define dd double
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
int32_t main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a>=k)
		cout<<k;
	else if(a+b>=k)
		cout<<a;
	else cout<<a-(k-(a+b));
}

Measured memory_bytes: 3636
from itertools import accumulate

N, M, V, P, *A = map(int, open(0).read().split())

A.sort(reverse=True)

S = list(accumulate(A)) + [0]

def is_ok(md):
    return (A[md] + M < A[P - 1]) or (A[md] + M) * (md - P + 1) - (S[md - 1] - S[P - 2]) < M * (V - (P - 1) - (N - md))

ng, ok = P - 1, N
while ok - ng > 1:
    md = (ok + ng) // 2
    if is_ok(md):
        ok = md
    else:
        ng = md

print(ok)

Measured memory_bytes: 14436
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int num = scan.nextInt();
        String a = scan.next();
        int b = a.length();
        if(b <= num){
            System.out.println(a);
        }else{
            System.out.println(a.substring(0,num) + "...");
        }


        
    }
}

Measured memory_bytes: 38648
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int answer = 0;

    for(int i = 0; i < N - 2; i++){
        if(S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C'){
            answer++;
        }
    }

    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans;
struct A{int a,b;}a[100050];
bool cmp(A a,A b){return a.b<b.b;}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].b);
		a[i].a=i;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		ans+=abs(a[i].a-i)&1;
	}
	printf("%d",ans>>1);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int ans = 0;
  vector<int> a(3);

  cin >> a[0] >> a[1] >> a[2];

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

  cout << a[2]*10 + a[1] + a[0] << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	string str;

	cin >> str;

	for (int i = 0; i < str.size(); i++) {
		if (str[i] != str[str.size() - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	for (int i = 0; i < (str.size() - 1) / 2; i++)
	{
		if (str[i] != str[(str.size() - 1) / 2 - 1 - i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	for (int i = (str.size() - 1) / 2 + 1; i < str.size(); i++)
	{
		if (str[i] != str[str.size() - 1 - (i - (str.size() - 1) / 2 - 1)]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
/*
 push yourself until you succed
*/
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define set_zero(a) memset(a,0,sizeof(a));
#define ll long long int
#define PI 2 * acos(0.0)
#define MAX 1000000000000000000
#define in(a) scanf("%d",&a);
#define out(a) printf("%d",a);
#define INF 1000000 
#define M 1000000007
#define pi 3.14159265 
using namespace std; 
int main(){ 
   fast_io
   ll a,b,c,d;
   cin>>a>>b>>c>>d;
   ll y = a*c;
   ll x = a*d;
   ll o = b*c;
   ll p = b*d;
   ll ans =max(y,x);
   ans = max(ans,o);
   cout<<max(p,ans)<<endl;
   return 0;
} 

Measured memory_bytes: 3648
#define _USE_MATH_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>
using namespace std;

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

    if(s[1] == s[2] && (s[0] == s[1] || s[2] == s[3]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
int n,t,d;

int main()
{
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d",&n,&d);
		int ans = 0;
		int tmp = d;
		for(int i = 1; i < n; ++i)
		{
			ans += 127;
			tmp = (127 ^ tmp) % 1000;
			//cout << tmp << endl;
		}
		ans += tmp;
		cout << ans << endl;
	}



	return 0;
}


Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  map<string, int> m;
  while (n--) {
    string s;
    int x;
    cin >> s >> x;
    m[s] += x;
  }
  vector<pair<string, int>> v;
  v.reserve(m.size());
  for (auto &p : m) v.pb(p);
  sort(all(v), [](auto &a, auto &b) {
    if (a.fi.size() != b.fi.size()) return a.fi.size() < b.fi.size();
    return a.fi < b.fi;
  });
  for (auto &p : v) cout << p.fi << ' ' << p.se << endl;
}

Measured memory_bytes: 3192
N,u,v = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int, input().split())
    E[a-1].append(b-1)
    E[b-1].append(a-1)
    

import heapq

def dijkstra(s):
    d = [10**6]*N
    used = [True]*N
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in E[s]:
        heapq.heappush(edgelist, [1, e])
    while edgelist:
        t = heapq.heappop(edgelist)
        if not used[t[1]]:
            continue
        used[t[1]] = False
        d[t[1]] = t[0]
        for e in E[t[1]]:
            if used[e]:
                heapq.heappush(edgelist, [t[0]+1, e])
                
    return d

T = dijkstra(u-1)
A = dijkstra(v-1)

ans = 0
for i in range(N):
    if T[i] < A[i]:
        ans = max(ans, A[i])
        idx = i
        
print(ans-1)

Measured memory_bytes: 87072
import java.util.*;
import java.awt.geom.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int[] r = new int[n];
			Point2D.Double[] p = new Point2D.Double[n];
			for(int i=0;i<n;i++){
				p[i] = new Point2D.Double(sc.nextInt(),sc.nextInt());
				r[i] = sc.nextInt();
			}
			
			int m = sc.nextInt();
			
			Point2D.Double t, s;
			Line2D.Double b;
			boolean flag;
			for(int i=0;i<m;i++){
				t = new Point2D.Double(sc.nextInt(),sc.nextInt());
				s = new Point2D.Double(sc.nextInt(),sc.nextInt());
				b = new Line2D.Double(s,t);
				flag = false;
				for(int j=0;j<n;j++){
					if(s.distance(p[j])<r[j] && t.distance(p[j])<r[j]);
					else if(s.distance(p[j])>r[j] && s.distance(p[j])>r[j] && b.ptSegDist(p[j])>r[j]);
					else{
						flag = true;
						break;
					}
				}
				if(flag==false) System.out.println("Danger");
				else System.out.println("Safe");
			}
		}	
	}	
}

Measured memory_bytes: 27000
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<functional>
#include<map>
using namespace std;
#pragma warning(disable: 4996)
vector<long long>X, Y; long long N, K, x[1000], y[1000], minx = (1LL << 62);
int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) { cin >> x[i] >> y[i]; X.push_back(x[i]); Y.push_back(y[i]); }
	sort(X.begin(), X.end()); sort(Y.begin(), Y.end());
	for (int i = 0; i < X.size(); i++) {
		for (int j = i + 1; j < X.size(); j++) {
			vector<long long>Z;
			for (int k = 0; k < N; k++) {
				if (X[i] <= x[k] && x[k] <= X[j])Z.push_back(y[k]);
			}
			sort(Z.begin(), Z.end());
			for (int k = 0; k <= (int)Z.size() - K; k++) {
				minx = min(minx, (X[j] - X[i])*(Z[k + K - 1] - Z[k]));
			}
		}
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
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 cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 12 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

ll E[200001];
const ll m = (1 << 20) - 1;
int he[100001], kotae[100001], C;
char d[100001];
void sagasu(int P, int D) {
	if (!kotae[P]) kotae[P] = C;
	if (d[P] < D) {
		d[P] = D;
		for (int p = he[P]; p; p = E[p] & m) {
			sagasu(E[p] >> 20, D - 1);
		}
	}
}

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


	int N, M, Q;
	N = getint();
	M = getint();
	int k = 1;
	rep(i, M) {
		int a = getint(), b = getint();
		E[k] = (ll(a) << 20) + he[b];
		he[b] = k++;
		E[k] = (ll(b) << 20) + he[a];
		he[a] = k++;
	}
	Q = getint();
	int v[100000], d[100000], c[100000];
	rep(i, Q) {
		v[i] = getint();
		d[i] = getint();
		c[i] = getint();
	}
	for (int i = Q - 1; i >= 0; i--) {
		C = c[i];
		sagasu(v[i], d[i]);
	}
	rep1(i, N) putint(kotae[i]);

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 4736
using System;
using System.Linq;

class ContestWithDrinksEasy {
    static void Main() {
        string input = Console.ReadLine();

        int problem_count = int.Parse(input);

        input = Console.ReadLine();

        int[] answer_times_of_problem = input.Split(' ')
                                             .Select(s => int.Parse(s))
                                             .ToArray();

        input = Console.ReadLine();

        int drink_count = int.Parse(input);

        for(int i = 0; i < drink_count; i++) {
            input = Console.ReadLine();
            int problem_number = int.Parse(input.Split(' ')[0]);
            int answer_time    = int.Parse(input.Split(' ')[1]);


            int sum_time = GetSumAnswerTime(answer_times_of_problem
                                          , problem_number
                                          , answer_time);

            Console.WriteLine(sum_time);
        }
    }

    // ドリンクを飲んだ場合の合計解答時間を求めるのメソッド
    private static int GetSumAnswerTime(int[] answer_times_of_problem
                                      , int problem_number
                                      , int answer_time) {
        int sum = 0;
        for (int i = 0; i < answer_times_of_problem.Length; i++) {
            if (i == problem_number - 1) {
                sum += answer_time;
            } else {
                sum += answer_times_of_problem[i];
            }
            
        }
        return sum;
    }
}

Measured memory_bytes: 2904
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double 
ld dp[3000][3000];
int main() {
	ll n;
	cin>>n;
	ld a;
	for(ll i=1;i<=n;i++)
	{
	    cin>>a;
	    if(i==1)
	    {
	        dp[i][0]=1-a;
	        dp[i][1]=a;
	    }
	    else{
	        for(ll j=0;j<=i;j++)
	        {
	            if(j==0)
	            dp[i][j]=(1-a)*dp[i-1][j];
	            else dp[i][j]=(1-a)*dp[i-1][j]+a*dp[i-1][j-1];
	        }
	        
	    }
	}
	

	
	
	ld sum=0;
	for(ll i=(n+1)/2;i<=n;i++)
	sum+=dp[n][i];
	
	printf("%0.10Lf",sum);

	
	return 0;
}


Measured memory_bytes: 139008
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using llong = long long;

vector<int> g[205];
int visit[205];
int circle[205];

int dfs(llong p) {
	if (visit[p]) {
		cout << 1 << endl;
		exit(0);
	}
	if (circle[p] != -1) return circle[p];
	
	visit[p] = true;
	int f = 0;
	for (llong i = 0; i < g[p].size(); i++) {
		f |= dfs(g[p][i]);
	}
	visit[p] = false;
	
	return circle[p] = f;
}

int main() {
	for (int i = 0; i <= 200; i++) circle[i] = -1;
	
	int n;
	int u, d;
	string s;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> s >> d;
		
		d += 100;
		
		if (s == "lock") g[d].push_back(u);
		else if (s == "wait") g[u].push_back(d);
	}
	
	for (int i = 0; i < 205; i++) {
		dfs(i);
	}
	
	cout << 0 << endl;
	
	return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	ll x[m],y[n];
	for(int i = 0; i<n; i++)
		cin>>y[i];
	for(int i = 0; i<m; i++)
		cin>>x[i];
	ll ans = 0, ans2 = 0;
	for(int i= 0; i<n; i++)
		ans = (ans + i*y[i]-(n-i-1)*y[i])%mod;
	for(int i= 0; i<m; i++)
		ans2 = (ans2 + i*x[i]-(m-i-1)*x[i])%mod;
	cout<<ans*ans2%mod<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a,b,c,res;
int main(){
  scanf("%d %d %d",&a,&b,&c);
  if((a+b+1)>=c)printf("%d\n", b+c);
  else printf("%d\n", a+b+b+1);
  return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <numeric>
#include <cassert>

using namespace std;

class TaskD {
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        vector<int> a(3*N);
        for (int i = 0; i < 3*N; ++i) {
            in >> a[i];
        }
        
        vector<long long> mx(3*N, -1), mn(3*N, -1);
        multiset<int> s;
        long long cur_sum = 0;
        for (int i = 0; i < 3*N; ++i) {
            if ((int)s.size() < N) {
                s.insert(a[i]);
                cur_sum += a[i];
            } else {
                if (a[i] > *s.begin()) {
                    cur_sum -= *s.begin();
                    cur_sum += a[i];
                    s.erase(s.begin());
                    s.insert(a[i]);
                }
            }
            mx[i] = cur_sum;
        }
        cur_sum = 0;
        s.clear();
        for (int i = 3*N-1; i >= 0; --i) {
            if ((int)s.size() < N) {
                s.insert(a[i]);
                cur_sum += a[i];
            } else {
                if (a[i] < *s.rbegin()) {
                    cur_sum -= *s.rbegin();
                    cur_sum += a[i];
                    s.erase(--s.end());
                    s.insert(a[i]);
                }
            }
            mn[i] = cur_sum;
        }
        
        long long res = -1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
        for (int i = N-1; i < 2*N; ++i) {
            //cout << "cut after " << i << endl;
            //cout << mx[i] << " " << mn[i + 1] << endl;
            res = max(res, mx[i] - mn[i + 1]);
        }
        
        out << res << "\n";
    }
};


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

	TaskD solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    string str;
    int q;
    cin >> str >> q;
    for(int i=0;i<q;i++){
        string queue;
        int a,b;
        string p;
        cin >> queue;
        if(queue=="print"){
            cin >> a >> b;
            for(int i=a;i<=b;i++) cout << str[i];
            cout << endl;
        }
        if(queue=="reverse"){
            cin >> a >> b;
            string ss=str;
            for(int i=a;i<=b;i++) str[i]=ss[b-i+a];
        }
        if(queue=="replace"){
            cin >> a >> b;
            cin >> p;
            for(int i=a;i<=b;i++) str[i]=p[i-a];
        }
    }
    
    return 0;
}


Measured memory_bytes: 3176
//080-b

#include <utility>
#include <vector>
#include <iostream>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

int main() {
    long long int n,cp;
    int fx=0,i=1;
    cin >> n;
    cp = n;
    while(n > 0){
        fx += n%10;
        n -= n%10;
        n /= 10;
    }
    if(cp % fx == 0)cout << "Yes" << endl;
    else    cout << "No" << endl;
}


Measured memory_bytes: 256
N, K = [int(nk) for nk in input().split()]
x = [int(xx) for xx in input().split()]

T = []
for i in range(0, N-K+1):
  j = i + (K-1)
  # 座標x[i]から座標x[j]までのろうそくに火をつける
  if x[i] >= 0:
    T.append(abs(x[j]))
  elif x[j] <= 0:
    T.append(abs(x[i]))
  else: # x[i] < 0 < x[j]:
    T.append(abs(x[i]) + abs(x[j]) + min(abs(x[i]), abs(x[j])))

ans = min(T)
print(ans)

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

const int maxn = 300005, mod = 1e9 + 7;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

char s[maxn];
int f[maxn][3][3], n, ans;

inline void add(int &a, int b) {a += b; if (a >= mod) a -= mod;}

int main()
{
	scanf("%s", s + 1); n = strlen(s + 1);
	f[0][0][0] = 1;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j <= 2; ++j)
			for (int k = 0; k <= 2; ++k) {
				if (!f[i][j][k]) continue;
				if (s[i + 1] != '1') { //0
					if (k == 2) add(f[i + 1][j][1], f[i][j][k]);
					else add(f[i + 1][j][k + 1], f[i][j][k]);
				}
				if (s[i + 1] != '0') { //1
					if (k) add(f[i + 1][j][k - 1], f[i][j][k]);
					else add(f[i + 1][min(2, j + 1)][k], f[i][j][k]);
				}
			}
	int ans = 0;
	for (int j = 0; j <= 2; ++j)
		for (int k = 0; k <= j; ++k)
			add(ans, f[n][j][k]);
	printf("%d\n", ans);
	
	return 0;
}



Measured memory_bytes: 11136
#include <stdio.h>

int main (){
	int L, R, d;
	int sum = 0;

	scanf ("%d %d %d", &L, &R, &d);
	
	for (int i = L ; i <= R ; i++){
		if (i % d == 0){
			sum++;
		}
	}
	printf ("%d", sum);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> L(N + 1, 0);
  L.at(0) = 2;
  L.at(1) = 1;
  for (int i = 2; i < N + 1; i++) {
    L.at(i) = L.at(i - 1) + L.at(i - 2);
  }
  cout << L.at(N) << endl;
}

Measured memory_bytes: 256
n = int(input())
words = []
for i in range(n):
  words.append(input())
for i in words:
  i = "".join(sorted(i))
words = sorted(words)
word = ""
for i in words[0]:
  if i not in word:
    word+=i
result = ""
for i in word:
  minim = 51
  for j in words:
    if j.count(i)<minim:
      minim = j.count(i)
  result+=i*minim
result = "".join(sorted(result))
print(result)

Measured memory_bytes: 38512
#include <iostream>
#include <vector>

signed main() {
    intmax_t N, X, M;
    scanf("%jd%jd%jd", &N, &X, &M);

    const size_t L = 35;
    std::vector<std::vector<intmax_t>> nxt_num(L + 1, std::vector<intmax_t>(M, 0));
    std::vector<std::vector<intmax_t>> nxt_sum(L + 1, std::vector<intmax_t>(M, 0));
    for (intmax_t n = 0; n < M; ++n) {
        nxt_num[0][n] = (n * n) % M;
        nxt_sum[0][n] = n;
    }
    for (size_t i = 0; i < L; ++i) {
        for (intmax_t n = 0; n < M; ++n) {
            nxt_num[i + 1][n] = nxt_num[i][nxt_num[i][n]];
            nxt_sum[i + 1][n] = nxt_sum[i][n] + nxt_sum[i][nxt_num[i][n]];
        }
    }

    size_t i = 0;
    intmax_t cur = X;
    intmax_t res = 0;
    while (N > 0) {
        if (N & 1) {
            res += nxt_sum[i][cur];
            cur = nxt_num[i][cur];
        }
        N >>= 1;
        ++i;
    }

    printf("%jd\n", res);
    return 0;
}


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

using namespace std;

const int MOD=1e9+7;

//const int MOD=998244353;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    
    vector<int> v(2*n);
    for(int&i:v)cin>>i;
    
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0; i<n; i++){
        ans+=v[2*i];
    }
    cout<<ans;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
int x=0,y=0,z=INF;
std::cin >> x>>y;
std::vector<int> v(x);
rep(i,x)std::cin >> v[i];
sort(all(v));
rep(i,x-(y-1)){
z= min(z,v[i+y-1]-v[i]);
}
std::cout << z << '\n';
}


Measured memory_bytes: 1024
<?php

$N = trim( fgets(STDIN) );
$line = trim( fgets(STDIN) );

$RB = str_split($line);
$R_count = 0;
$B_count = 0;

for ( $i = 0; $i < $N; $i++ ) {
    if ( $RB[$i] == 'R' ) {
        $R++;
    } else {
        $B++;
    }
}

if ( $R > $B ) {
    echo 'Yes';
} else {
    echo 'No';
}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    ll a;
    for(int i=0;i<m;i++){
    	cin>>a;
    	n-=a;
    }
    if(n<0){
    	cout << -1<<endl;
    }else{
    	cout << n<<endl;
    }
    return 0;
}


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

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

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int f(int a){
  int count = 0;
  int flag = 0;
  for(int i = 1; i <= pow(a,0.5); ++i){
    if(a % i == 0) count ++;
    if(i*i == a)flag = 1;
  }
  count *= 2;
  if(flag == 1) --count;
  return count;
}


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: 2044
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int x;
	int zahyo[110] = {};
	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		++zahyo[x];
	}
	int minl = 1000000007;
	for (int i = 1; i <= 100; ++i)
	{
		int now = 0;
		for (int j = 1; j <= 100; ++j)
		{
			now += pow((j - i),2) * zahyo[j];
		}
		minl = min(minl, now);
	}
	cout << minl << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		String answer = "";

		for (int i = 0; i < N; i++) {
			answer += String.valueOf(S.charAt(i)) + String.valueOf(T.charAt(i));
		}

		System.out.println(answer);
	}
}

Measured memory_bytes: 23380
from collections import deque
N = int(input())
A = deque([])
for _ in range(N):
    A.append(int(input())-1)
b = 0
cnt = 0
for i in range(N):
    cnt += 1
    b = A[b]
    if b == 1:
        print(cnt)
        break
else:
    print(-1)

Measured memory_bytes: 7284
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(c) (c).begin(), (c).end()
#define REVERSE(c) reverse(ALL(c))
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort(ALL(c))
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


void dfs(LL u, vector<vector<PII>>& G, VI& col, vector<bool>& visited) {
    //dump(u);
    for (auto x : G[u]) {
        LL v = x.first, w = x.second;
        if (visited[v]) continue;
        visited[v] = true;
        //dump(v);
        //dump(w);
        if (w == 1) {
            col[v] = 1 - col[u];
        } else {
            col[v] = col[u];
        }
        dfs(v, G, col, visited);
    }
}


int main() {
    LL N;
    cin >> N;
    vector<vector<PII>> G(N + 1);
    VI col(N + 1);
    vector<bool> visited(N + 1);
    REP(i, N - 1) {
        LL u, v, w;
        cin >> u >> v >> w;
        G[u].PB(MP(v, w % 2));
        G[v].PB(MP(u, w % 2));
    }
    dfs(1, G, col, visited);
    FOR(i, 1, N + 1) {
        cout << col[i] << endl;
    }
	
    return 0;
}


Measured memory_bytes: 11648
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    ll res = 1;
    while(res*2 <= N){
        res *= 2;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,m;
void f(){
    for(int i=0;i<=2000;i++){
        for(int j=0;j+i<=2000&&i+j<=n;j++){
            if(i*10000+j*5000+(n-i-j)*1000==m)
            {
                cout<<i<<" "<<j<<" "<<n-i-j<<endl;
                return;
            }
        }
    }
     cout<<-1<<" "<<-1<<" "<<-1<<endl;
}
int main() {
    scanf("%d%d",&n,&m);
    f();
    // insert code here...
    //std::cout << "Hello, World!\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define REPA(x, v) for(auto&& c:v)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N,M;
    cin >> N >> M;
    vector<vector<pll>> cost(N);
    REP(i, M){
        int l,r,d;
        cin >> l >> r >> d;
        l--;r--;
        cost[l].pb({r,d});
        cost[r].pb({l,-d});
    }
    vector<ll> ok(N, MAXINF);
    REP(i, N){
        if(ok[i]!=MAXINF) continue;
        queue<int> q;
        q.push(i);
        ok[i] = 0;
        while(!q.empty()){
            auto f = q.front(); q.pop();
            REPA(c, cost[f]){
                if(ok[c.fi]==MAXINF){
                    ok[c.fi] = ok[f] + c.se;
                    q.push(c.fi);
                }else if(ok[c.fi] != ok[f]+c.se){
                    Yes(0);
                    return 0;
                }
            }
        }
    }
    Yes(1);
}

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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}
int n,g[100005],t,s,ma;
int main()
{
	n=read();
	for(int i=1;i<n;++i){
		t=i;s=0;
		while(t) {
			s+=t%10;
			t/=10;
		}
		g[i]=s;
	}
	ma=1e9;
	for(int i=1; i<n; ++i) ma=min(ma,g[i]+g[n-i]);
	cout<<ma;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<map>

using namespace std;

int main() {
	long long n, Min, Max = -999999999;
	cin >> n >> Min;
	for (int i = 1; i < n; i++) {
		long long a;
		cin >> a;
		Max = max(Max, a - Min);
		Min = min(Min, a);
	}
	cout << Max << endl;
}

Measured memory_bytes: 3104
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int gcd(int a, int b) {
	return b != 0 ? gcd(b, a % b) : a;
}



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

	vector<int> a(n);

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

	int ans = a[0];
	for (int i = 1; i < n; i++) {
		ans = gcd(ans, a[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
const ll mod = 1e9+7;
const ll INF = 1e18;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;
using V = vector<ll>;
using P = pair<ll,ll>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  string s;
  cin >> s;
  if (s[s.size()-1] != 's') cout << s << 's' << '\n';
  else {
    cout << s << "es" << '\n';
  }

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using ll = long long;
const int inf = 1e9; //1(1倍)e(指数)9(10^9)
int main() {
    int D;
    ll G;
    cin >> D >> G;
    
    vector<ll> p(D), c(D);
    rep(i, D) cin >> p[i] >> c[i];

    ll res = inf;
    for (int bit = 0; bit < (1 << D); ++bit) {
        ll sum = 0;
        ll num = 0;
        rep(i, D)  {
            if (bit & (1 << i)) {
                sum += c[i] + p[i] * 100 * (i + 1);
                num += p[i];
            }
        }
        if (sum >= G) {
            res = min(res, num);
        }
        
        else {
            for (int i = D - 1; i >= 0; --i) {
                if (bit & (1 << i)) continue;
                for (int j = 0; j < p[i]; ++j) {
                    if (sum >= G) break;
                    sum += 100 * (i + 1);
                    ++num;
                }
            }
            res = min(res, num);
        }
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;

map<vector<int > ,int > mp;
int main() {
    int n;
    vector<int > fr;
    cin>>n;
    for(int i=0;i<n;i++){
        string y;
        cin>>y;
        fr= vector<int>(26,0);
        for(int i=0;i<y.size();i++)fr[y[i]-'a']++;
        mp[fr]++;
    }
    long long an = 0;
    for(auto v:mp)
        an += v.second*1LL*(v.second-1)/2;
    cout<<an;
    return 0;
}


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var imp = Console.ReadLine().Split(' ');
            int N = int.Parse(imp[0]);
            int L = int.Parse(imp[1]);
            string[] strs = new string[N];
            for (int i = 0; i < N; ++i)
            {
                strs[i] = Console.ReadLine();
            }
            Array.Sort(strs);
            //Console.Write(strs[0]);
            
            for (int j = 0; j < N; ++j)
            {
                Console.Write(strs[j]);
            }

    
            System.Threading.Thread.Sleep(1000);
        }
    }
}


Measured memory_bytes: 13408
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;

int main(){

    int n;
    cin >> n;
    cout << 180 * (n - 2) << endl;

}

Measured memory_bytes: 256
# ABC129 D

H,W=map(int,input().split())
S=[input() for _ in [0]*H]
Lx=[[0]*W for _ in [0]*H]
Ly=[[0]*W for _ in [0]*H]

def search_x(x,y):
    i=x
    while 1:
        i+=1
        if i<W:
            if S[y][i]=='#':
                break
        else:
            break
    return i-x

def search_y(x,y):
    j=y
    while 1:
        j+=1
        if j<H:
            if S[j][x]=='#':
                break
        else:
            break
    return j-y

def set_x(x,y,p):
    i=x
    Lx[y][i]=p
    while 1:
        i+=1
        if i<W:
            if S[y][i]=='#':
                break
            else:
                Lx[y][i]=p
        else:
            break

def set_y(x,y,p):
    j=y
    Ly[j][x]=p
    while 1:
        j+=1
        if j<H:
            if S[j][x]=='#':
                break
            else:
                Ly[j][x]=p
        else:
            break

res=0
for y in range(H):
    for x in range(W):
        if S[y][x]=='.':
            if Lx[y][x]==0:
                w=search_x(x,y)
                set_x(x,y,w)
            if Ly[y][x]==0:
                Ly[y][x]==0
                h=search_y(x,y)
                set_y(x,y,h)
            res=max(Lx[y][x]+Ly[y][x]-1,res)
print(res)

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

int main()
{
    long long int n,d,ans=0;
    cin>>n>>d;
    while(n--)
    {
        long long int x,y;
        cin>>x>>y;
        if(d*d >= (x*x + y*y))
        ans++;
    }
    cout<<ans;
}


Measured memory_bytes: 3636
N = int(input())
A = list(map(int,input().split()))

n_num = 1
count = 0
for i in range(N):
  if(A[i] == n_num):
    count += 1
    n_num += 1

if(count == 0):
  ans = -1
else:
  ans = N - count
print(ans)

Measured memory_bytes: 26268
#include <iostream>
#include <map>
#include <cctype>
using namespace std;

char getResult(map<char, string> &s){
  char turn, next;
  for(turn = 'a'; s[turn].size() > 0; turn = next){
    next = s[turn][0];
    s[turn] = s[turn].erase(0,1);
  }
  return toupper(turn);
}

int main(){
  map<char, string> s;
  for(char c = 'a'; c <= 'c'; c++){
    cin >> s[c];
  }

  char result = getResult(s);
  cout << result << endl;
}

Measured memory_bytes: 3100
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>

using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  
  UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) par[i] = i;
  }
  
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }
  
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> from(m), to(m);
  for (int i = 0; i < m; i++) {
    cin >> from[i] >> to[i];
    from[i]--; to[i]--;
  }
  
  int ans = 0;
  for (int i = 0; i < m; i++) {
    UnionFind uf(n);
    for (int j = 0; j < m; j++) {
      // iを除く橋をかける
      if (i == j) {
        continue;
      }
      uf.unite(from[j], to[j]);
    }
    if (!uf.same(from[i], to[i])) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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



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

int main(){

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


    ll ans[n+1];
    memset(ans,0,sizeof(ans));
    
    for(ll i=1;i<n;i++)
    {
      	if(i==1)
          	ans[i] = abs(a[i]-a[i-1]);
      	else{
        ans[i] =min(abs(a[i]-a[i-1]) + ans[i-1],abs(a[i]-a[i-2])+ans[i-2]);
        }

    }

    cout<<ans[n-1];


}

Measured memory_bytes: 1920
a, b = map(int, input().split())

def func(n):
    if n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return n+1
    elif n % 4 == 3:
        return 0
    else:
        return n 

if a > 0:
    ans = func(a-1) ^ func(b)
else:
    ans = func(b)

print(ans) 

Measured memory_bytes: 3060
N, A, B, C, D = map(int, input().split())
S = input()

if "##" in S[A:max(C, D)]:
    print("No")
    exit()

if C > D:
    if "..." in S[B-2:D+1]:
        print("Yes")
    else:
        print("No")
else:
    print("Yes")

Measured memory_bytes: 3572
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

//Byakko Delivery Company
public class Main{

	int[] trans(String s){
		String[] t = s.split("-");
		int a = t[0].charAt(0)-'a';
		int b = Integer.parseInt(t[1])-1;
		return new int[]{a, b};
	}
	
	int INF = 1<<29;
	boolean[][][][] dist;
	int[][] move = {{-1,0},{0,1},{1,0},{0,-1}};
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int h = sc.nextInt(), w = sc.nextInt();
			if((h|w)==0)break;
			int D = sc.nextInt();
			int[][] e = new int[h*w][h*w];
			for(int[]a:e)Arrays.fill(a, D);
			int ns = sc.nextInt();
			int[] k = new int[h*w];
			while(ns--!=0){
				int[] t = trans(sc.next());
				k[t[0]*w+t[1]] = sc.nextInt();
			}
			int nc = sc.nextInt();
			while(nc--!=0){
				int[] t1 = trans(sc.next()), t2 = trans(sc.next());
				int s = t1[0]*w+t1[1], t = t2[0]*w+t2[1];
				e[s][t] = e[t][s] = INF;
			}
			int njj = sc.nextInt();
			while(njj--!=0){
				int[] t1 = trans(sc.next()), t2 = trans(sc.next());
				int d = sc.nextInt();
				int s = t1[0]*w+t1[1], t = t2[0]*w+t2[1];
				e[s][t] = e[t][s] = D+d;
			}
			int[] start = trans(sc.next()), goal = trans(sc.next());
			dist = new boolean[h][w][4][101];
			dist[start[0]][start[1]][1][0] = true;
			PriorityQueue<int[]> q = new PriorityQueue<int[]>(h, new Comparator<int[]>() {
				public int compare(int[] o1, int[] o2) {
					return o1[3]-o2[3];
				}
			});
			q.add(new int[]{start[0], start[1], 1, 0});
			while(!q.isEmpty()){
				int[] a = q.poll();
				int i = a[0], j = a[1], dir = a[2];
				if(i==goal[0]&&j==goal[1]){
					System.out.println(a[3]); break;
				}
				for(int m=3;m<=5;m++){
					int nd = (dir+m)%4;
					int ni = i+move[nd][0], nj = j+move[nd][1];
					if(0<=ni&&ni<h&&0<=nj&&nj<w&&e[i*w+j][ni*w+nj]!=INF){
						int nt = a[3] + e[i*w+j][ni*w+nj];
						if(k[ni*w+nj]==0){
							if(nt<=100&&!dist[ni][nj][nd][nt]){
								dist[ni][nj][nd][nt] = true;
								q.add(new int[]{ni, nj, nd, nt});
							}
						}
						else{
							boolean nsblue = (nt/k[ni*w+nj])%2==0;
							if(nd%2==0&&!nsblue||nd%2==1&&nsblue)continue;
							if(nt<=100&&!dist[ni][nj][nd][nt]){
								dist[ni][nj][nd][nt] = true;
								q.add(new int[]{ni, nj, nd, nt});
							}
						}
					}
				}
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 14000
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
		
const double eps = 1e-9;																							   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////

const int mod = 1e9 + 7;

///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main()																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	LL n, k;
	LL res = 0;
	cin >> n >> k;
	
	while(k <= n + 1){
		LL mini = k * (k - 1) / 2;
		LL maxi = k * n - k * (k-1) / 2;
		
		res += maxi - mini + 1;
		res %= mod;
		
		k++;
	}
	
	cout << res << endl;
	
	
	
	
	
	
	return 0;
 }


Measured memory_bytes: 3652