akhauriyash/Code-Regression huggingface dataset:
from math import factorial
S = raw_input()
lS = len(S)
d = [S.count(i) for i in set(list(S))]
dd = sum([i%2 for i in d])
if (lS%2 == 0 and dd != 0 ) or (lS%2 == 1 and dd != 1): 
		print 0
else:
	denomi = 1
	for i in d:
		denomi *= factorial(i/2)
	print factorial(lS/2)/denomi

Measured memory_bytes: 4348
#include<bits/stdc++.h>
using namespace std;
int main(){

    int n,dup=0;
    cin>>n;
    vector<int > v(n),c(n),diff(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    for(int j=0;j<n;j++){
        cin>>c[j];
    }
    for(int i=0;i<n;i++){
        if(v[i] - c[i] > 0)dup+=v[i]-c[i];
    }
    cout<<dup<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while (true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            char grade;

            if (m == -1 && f == -1 && r == -1) {
            break;
            }

            if(m == -1 || f == -1){
                grade = 'F';
            }else  if(m+f>=80){
                grade = 'A';
            }else  if(m+f>=65){
                grade = 'B';
            }else  if(m+f>=50){
                grade = 'C';
            }else  if(m+f>=30 && r>=50){
                grade = 'C';
            }else  if(m+f>=30){
                grade = 'D';
            }else{
                grade = 'F';
            }

            System.out.println(grade);
        }
        sc.close();
    }
}


Measured memory_bytes: 26236
#include<cstdio>
#include<cstring>

using int64=long long;
using uchar=unsigned char;

constexpr int maxn(3000);

char s[maxn];
char t[]="keyence";

int main(){
	scanf("%s",s);
	const int len=strlen(s);

	char*mat=t;
	int cnt1=0;
	for(;cnt1<=7&&cnt1<=len;++cnt1)
		if(t[cnt1]!=s[cnt1])break;
	int cnt2=0;
	for(;cnt2<=7&&cnt2<=len;++cnt2)
		if(t[6-cnt2]!=s[len-cnt2-1])break;


	puts(cnt1+cnt2>=7?"YES":"NO");

	return 0;
}


Measured memory_bytes: 128
S = input()

num=[0]*26

for i in range(len(S)):
    if S[i] == "a":
        num[0] +=1
    elif S[i] == "b":
        num[1] +=1
    elif S[i] == "c":
        num[2] +=1
    elif S[i] == "d":
        num[3] +=1
    elif S[i] == "e":
        num[4] +=1
    elif S[i] == "f":
        num[5] +=1
    elif S[i] == "g":
        num[6] +=1
    elif S[i] == "h":
        num[7] +=1
    elif S[i] == "i":
        num[8] +=1
    elif S[i] == "j":
        num[9] +=1
    elif S[i] == "k":
        num[10] +=1
    elif S[i] == "l":
        num[11] +=1
    elif S[i] == "m":
        num[12] +=1
    elif S[i] == "n":
        num[13] +=1
    elif S[i] == "o":
        num[14] +=1
    elif S[i] == "p":
        num[15] +=1
    elif S[i] == "q":
        num[16] +=1
    elif S[i] == "r":
        num[17] +=1
    elif S[i] == "s":
        num[18] +=1
    elif S[i] == "t":
        num[19] +=1
    elif S[i] == "u":
        num[20] +=1
    elif S[i] == "v":
        num[21] +=1
    elif S[i] == "w":
        num[22] +=1
    elif S[i] == "x":
        num[23] +=1
    elif S[i] == "y":
        num[24] +=1
    elif S[i] == "z":
        num[25] +=1
        
ans = num.count(0)

if ans == 0:
    print("None")
else:
    ans1 = num.index(0)
    if ans1 == 0:
        print("a")
    elif ans1 == 1:
        print("b")
    elif ans1 == 2:
        print("c")
    elif ans1 == 3:
        print("d")
    elif ans1 == 4:
        print("e")
    elif ans1 == 5:
        print("f")
    elif ans1 == 6:
        print("g")
    elif ans1 == 7:
        print("h")
    elif ans1 == 8:
        print("i")
    elif ans1 == 9:
        print("j")
    elif ans1 == 10:
        print("k")
    elif ans1 == 11:
        print("l")
    elif ans1 == 12:
        print("m")
    elif ans1 == 13:
        print("n")
    elif ans1 == 14:
        print("o")
    elif ans1 == 15:
        print("p")
    elif ans1 == 16:
        print("q")
    elif ans1 == 17:
        print("r")
    elif ans1 == 18:
        print("s")
    elif ans1 == 19:
        print("t")
    elif ans1 == 20:
        print("u")
    elif ans1 == 21:
        print("v")
    elif ans1 == 22:
        print("w")
    elif ans1 == 23:
        print("x")
    elif ans1 == 24:
        print("y")
    elif ans1 == 25:
        print("z")
        
        
        

Measured memory_bytes: 3556
//我是菜鸡
#include<bits/stdc++.h>
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
#define debug(x) cout<<x<<endl
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 2e3;
void deprint() {
	//ofstream cout("E:\\acm dream\\debug.txt");
	return;
}
int main() {
	//ifstream cin("E:\\acm dream\\in.txt");
	//ofstream cout("E:\\acm dream\\out.txt");
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int a, n, x;
	while (cin >> a >> n) {
		ll ans = 0;
		_for(i, 0, n) {
			cin >> x;
			ans += x;
		}
		if (ans >= a)cout << "Yes\n";
		else cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 256
n = int(input())
S = list(input())
dic = {}

for d in S:
    if d not in dic:
        dic[d] = 1
    else:
        dic[d] += 1
tot = 1
for d in dic:
    i = dic[d] + 1
    tot = tot*i % (10**9 + 7)

print((tot-1) % (10**9+7))


Measured memory_bytes: 3956
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値取得
		BigDecimal K = scan.nextBigDecimal();

		//演算
		BigDecimal SEVEN = new BigDecimal(7);
		BigDecimal num = SEVEN;
		int digit = 1;

		if (!K.remainder(new BigDecimal(2)).equals(BigDecimal.ZERO)
				&& !K.remainder(new BigDecimal(5)).equals(BigDecimal.ZERO)) {

			BigDecimal wk = SEVEN.remainder(K);

			while (!num.remainder(K).equals(BigDecimal.ZERO)) {
				wk = wk.multiply(BigDecimal.TEN).remainder(K);
				num = num.add(wk);
				digit++;
			}
		} else {
			digit = -1;
		}

		//結果出力
		System.out.println(digit);
	}
}


Measured memory_bytes: 65324
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** 判定用大きい数 */
	private static final int INF = Integer.MAX_VALUE >> 1;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			Room[] rooms = new Room[n + 1];
			IntStream.range(0, n + 1).forEach(i -> rooms[i] = new Room(i));
			IntStream.range(0, m).forEach(i -> {
				int a = scanner.nextInt(), b = scanner.nextInt();
				rooms[a].children.add(b);
				rooms[b].children.add(a);
			});
			rooms[1].depth = 0;
			Queue<Room> queue = new PriorityQueue<>();
			queue.add(rooms[1]);
			while (!queue.isEmpty()) {
				Room parent = queue.poll();
				for (Integer child : parent.children) {
					if (rooms[child].depth == INF) {
						rooms[child].depth = parent.depth + 1;
						rooms[child].parent = parent.no;
						queue.add(rooms[child]);
					}
				}
			}
			for (int i = 1; i < n + 1; i++) {
				if (rooms[i].depth >= INF) {
					System.out.println("No");
					return;
				}
			}
			System.out.println("Yes");
			IntStream.range(2, n + 1).map(i -> rooms[i].parent).forEach(System.out::println);
		}
	}

	/**
	 * 各部屋を表すクラス
	 */
	private static class Room implements Comparable<Room> {
		/** 自分の番号 */
		int no;
		/** 深さ */
		int depth = INF;
		/** 親 */
		int parent = 0;
		/** 子供のリスト */
		List<Integer> children = new ArrayList<>();

		/**
		 * コンストラクター
		 * 
		 * @param no 番号
		 */
		Room(int no) {
			super();
			this.no = no;
		}

		@Override
		public int compareTo(Room o) {
			return this.depth - o.depth;
		}
	}
}


Measured memory_bytes: 80924
fun main(args: Array<String>) {
    agc020a()
}

fun agc020a() {
    val (n, a, b) = readLine()!!.split(' ').map { it.toInt() }

    val answer = if ((b - a) % 2 == 0) "Alice" else "Borys"

    println(answer)
}


Measured memory_bytes: 38208
Edge = Struct.new(:id, :to)
N = gets.to_i
G = Array.new(N + 1){ [] }
E = (1 ... N).map { gets.split.map(&:to_i) }
C = Array.new(N - 1, 0)
E.each_with_index do |(a,b),e|
  G[a] << Edge.new(e, b)
  G[b] << Edge.new(e, a)
end
d = (1 .. N).map{|i| G[i].size }.max

q = [[1, N, 0]] # node, parent_edge, parent_edge_color
until q.empty?
  v, pe, pec = q.shift
  c = 1
  G[v].inject(1) do |c, e|
    if e.id == pe
      c
    elsif c == pec
      C[e.id] = c + 1
      q.push([e.to, e.id, c + 1])
      c + 2
    else
      C[e.id] = c
      q.push([e.to, e.id, c])
      c + 1
    end
  end
end
puts d
puts C


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

signed main() {
	int n, x;
	cin >> n >> x;
	vector<int> l(n);
	rep(i, n) cin >> l[i];
	int cou = 1;
	int sum = 0;
	rep(i, n) {
		sum += l[i];
		if(sum <= x) {
			cou++;
		}
	}
	cout << cou << endl;
	return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>

typedef long long ll;

using namespace std;

int main() {
	ll k, n;
	cin >> k >> n;
	ll* A = new ll[n];

	ll maxDistance = 0;

	cin >> A[0];

	for (int i = 1; i < n; i++) {
		cin >> A[i];

		if (A[i] - A[i - 1] > maxDistance) {
			maxDistance = A[i] - A[i - 1];
		}
	}

	if (k - A[n - 1] + A[0] > maxDistance) {
		maxDistance = k - A[n - 1] + A[0];
	}

	cout << k - maxDistance;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int INF=INT_MAX;
const ld PI=3.1415926535838797323;
const ld E=2.71828183;
const int MOD=1e9+7;
vi bfs(vector<vi>adj,int src){
    //adjacency list, not-weighted, possibly directed ,src is 1-indexed, adj[0].size()=0!!!
    //for n vertices, adj.size()=n+1. (constructed via push_back() ).

    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return dst;
}
vi bfsParents(vector<vi>adj,int src){
    vi parents=vi(adj.size(),INF);
    parents[src]=-1;
    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                parents[nbr]=c;
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return parents;
}
int powMod(int base,int exp,int mod){
    //base^exp %mod
    int ans=1;
    for(int i=0; i<exp; i++)
        ans=((ans%mod)*(base%mod))%mod;
    return ans;
}
vi divisorsOf(int n){
    //vector of divisors of n (inc. 1 , excl.n)
    vi ans;
    for(int i=1; i*i<=n; i++){
        if(n%i==0)
            ans.push_back(i);
        if(i*i!=n && i!=1)
            ans.push_back(n/i);
    }
    return ans;
}

void solve();

int main() {
    //  int t;
    //cin >> t;
    //while(t--)
    solve();
}
void solve(){
    double m,n;
    cin >> n >> m;
    vi vals;
    int sum=0,mx=-1;
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        sum+=x;
        vals.push_back(x);
    }
    sort(vals.begin(),vals.end(),greater<int>());
    for(int i=0; i<m; i++)
        if(vals[i]<sum/(4*m)){
            cout << "No\n";
            return;
        }
    cout << "Yes\n";


}

Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

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

    int a; cin >> a;

    cout.precision(10);
    cout << fixed <<  1 - 1. * (a / 2) / a << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

int main(int argc, char **argv) {
  int A, B;
  scanf("%d %d", &A, &B);;
  bool b = (A % 3) == 0
           || (B % 3 == 0)
           || ((A + B) % 3 == 0);
  printf("%s\n", b ? "Possible" : "Impossible");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}
struct UnionFind{
    vector<int> pare;
    vector<int> rank;
    UnionFind(int N):pare(N),rank(N){
        rep(i,N){
            pare[i]=i;
            rank[i]=0;
        }
    }
    int root(int x){
        if(pare[x]==x)return x;
        return pare[x]=root(pare[x]);
    }
    void unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx==ry)return ;
        if(rank[rx]>rank[ry]){
            pare[rx]=ry;
        }else {
            pare[ry] = rx;
            if (rank[rx] == rank[ry])rank[rx]++;
        }
    }

    bool same(int x,int y){
        return root(x)==root(y);
    }
};
int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n);
    rep(i,m){
        int x,y,z;
        cin>>x>>y>>z;
        x--;y--;
        uf.unite(x,y);
    }
    int ans = 0;
    rep(i,n){
        if(uf.root(i)==i)ans++;
    }
    cout<<ans<<endl;


return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int Abs(int x){
	return x<0?-x:x;
}
int main(){
//	freopen("A.in","r",stdin);
	int n;
	scanf("%d",&n);
	int x=0,y=0,xx,yy;
	int t=0,tt;
	for(int i=1;i<=n;i++){
		scanf("%d%d%d",&tt,&xx,&yy);
		if((Abs(xx-x)+Abs(yy-y))%2==(tt-t)%2&&(Abs(xx-x)+Abs(yy-y)<=tt-t));
		else{
			printf("No\n");
			return 0;
		}
		t=tt,x=xx,y=yy;
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>


using namespace std;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const double PI = acos(-1.0);
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define all(v) v.begin(), v.end()

inline void finish() {
	cout << -1 << endl;
	exit(0);
}

template <typename T>
inline void debug(vector<T> v) {
	cout << "[";
	for (ll i = 0; i < v.size() - 1; ++i) {
		cout << v[i] << ", ";
	}
	cout << v[v.size() - 1] << "]" << endl;
}

void Main();
inline void DebugMain() {
	while (true) {
		Main();
	}
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	bool debug = false;
	if (debug) {
		cout << "\x1b[41m" << "Debug Mode " << endl;
	}
	(debug) ? DebugMain() : Main();
	return 0;
}

inline void Main() {
	int X,Y,N;
	int ans;
	string S;
	
	char alfa[] = { 'A','B' ,'C','D' ,'E' ,'F' ,'G' ,'H' ,'I' ,'J' ,'K' ,'L' ,'M' ,'N' ,'O' ,'P' ,'Q' ,'R' ,'S' ,'T' ,'U' ,'V' ,'W' ,'X' ,'Y','Z' };

	cin >> N >> S;

	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < 26; j++) {
			if (S[i] == alfa[j]) {
				S[i] = alfa[(j + N) % 26];
				break;
			}
		}
	}
	
	cout << S;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int b[100000];
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b+c || b==a+c || c==a+b){
    cout<<"Yes\n";
  }
  else{
    cout<<"No\n";
  }
  return(0);
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)

	sn := 0
	for _, r := range strconv.Itoa(n) {
		x, _ := strconv.Atoi(string(r))
		sn += x
	}

	if n%sn == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
ans=0
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=ans+B[A[0]-1]
for i in range(1,N):
    ans=ans+B[A[i]-1]
    if A[i]==A[i-1]+1:
        ans=ans+C[A[i-1]-1]
print(ans)

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

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; i++){
        cin >> L[i];
    }
    
    sort(L.begin(), L.end());

    int count = 0;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            if(L[i] == L[j]) continue;
            for(int k = j + 1; k < N; k++){
                if(L[j] == L[k]) continue;
                if(L[i] + L[j] > L[k]) count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

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

int dp[2][1001][1001];
//dp[0]:white, dp[1]:black

int main(void){
    int n,k;
    cin>>n>>k;
    rep(i,n){
        int x,y;
        string c;
        cin>>x>>y>>c;
        bool isB = (c=="B")^((x/k + y/k)&1);
        dp[isB][y%k + 1][x%k + 1]++;
    }

    rep1(y,k)rep1(x,k)rep(i,2){
        dp[i][y][x] += dp[i][y-1][x] + dp[i][y][x-1] - dp[i][y-1][x-1];
    }

    int res = 0;
    rep1(y,k)rep1(x,k)rep(i,2){
        int cnt1 = dp[i][k][k] - dp[i][y][k] - dp[i][k][x] + 2*dp[i][y][x];
        int cnt2 = dp[!i][y][k] + dp[!i][k][x] - 2*dp[!i][y][x];
        res = max(res, cnt1+cnt2);
    }
    cout<<res<<endl;
    return 0;
}


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

ll gcd(ll a, ll b) {
  if (b == 0) return a;
  else return gcd(b,a%b);
}

ll a,b;

int main()
{
  fastio();

  cin >> a >> b;

  ll c = gcd(a,b);

  ll ans = 1;
  for (ll i = 2; i*i <= c; i++) {
    if (c % i == 0) ans++;
    while(c % i == 0) c /= i;
  }
  if (c != 1) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;
int main(){
  string s;
  cin >> s;
  int n = s.length();
  int a = INF, b = INF;
  if (s.length() == 2) {
    if(s[0] == s[1]) cout << 1 << ' ' << 2 << endl;
    else cout << -1 << ' ' << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n - 2; ++i) {
    string t = s.substr(i, 3);
    if(t[0] == t[1] || t[0] == t[2] || t[1] == t[2]) {
      a = i;
      b = i + 2;
    }
  }
  if(a != INF) cout << a + 1 << ' ' << b + 1 << endl;
  else cout << -1 << ' ' << -1 << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

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

        int h = sc.nextInt();
        int w = sc.nextInt();

        char[][] c = new char[h+2][w+2];
        for (int i = 0; i < h+2; i++) {
            if (i == 0 || i == h+1) {
                for (int j = 0; j < w+2; j++) {
                    c[i][j] = '#';
                }
            } else {
                String s = sc.next();
                c[i][0] = '#';
                c[i][w+1] = '#';
                for (int j = 1; j < w+1; j++) {
                    c[i][j] = s.charAt(j-1);
                }
            }
        }

        for (char[] i : c) {
            for (char j : i) {
                System.out.print(j);
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 23764
# include <bits/stdc++.h>
# define int      long long
# define all(vc)   vc.begin(),vc.end()
# define all2(vc)  vc.rbegin(),vc.rend()
# define pb        push_back
# define vec       vector
# define fi        first 
# pragma GCC optimize "-O3"
# define se        second
# define speed     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
# define time      cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

using namespace std; 
map <int, int> mp;
void solve(){
    int n = 0, m;
    cin >> n;
    vec <int> used(1000, 0);
    for (int i = -1000; i < 1000; ++i)
    {
        int A = i * i * i * i * i;
        for (int j = -1000; j < 1000; ++j)
        {
            int B = j * j * j * j * j;
            if( A - B == n){
                cout << i << ' ' << j;
                return;
            }
        }
    }

}
int32_t main(){
    speed;
    int T = 1;
    //cin >> T;
    while( T-- ){
         solve();
         cout<<'\n';
    }
    time;
}
 

Measured memory_bytes: 3768
N=int(input())
A=[[] for _ in range(N)]

for i in range(N):
    A[i]=list(map(int,input().split()))

NE=[0]*N#i番目の人が，次何番目の試合をするかのリスト
F=[0]*N#i番目の人が，該当する日に試合をしたか記憶しておく

#i+1日目の試合をする人はi日目に試合をした人なので，それを2つのqueueに記憶．
Q=[[],[]]

#初日
for i in range(N):
    opp=A[i][0]-1
    if A[opp][0]-1==i:
        NE[i]+=1
        Q[0].append(i)

ans=1
#d日目
for d in range(N*(N-1)//2):
    F=[0]*N
    a=d%2
    b=(d+1)%2
    while len(Q[a])!=0:
        i=Q[a].pop()
        if NE[i]==N-1:
            continue
        opp=A[i][NE[i]]-1
        if F[i]==1 or F[opp]==1:#その日に試合したことがある人はスルー,oppの重複防止
            continue
        if A[opp][NE[opp]]-1==i:
            NE[i]+=1
            NE[opp]+=1
            F[i]=1
            F[opp]=1
            if NE[i]!=N-1:
                Q[b].append(i)
            if NE[opp]!=N-1:
                Q[b].append(opp)
    ans+=1
    if len(Q[a])==0 and len(Q[b])==0:
        break

for i in range(N):
    if NE[i]!=N-1:
        ans=-1
print(ans)

Measured memory_bytes: 62044
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define inf 1e18
#define err(x) cout<<x<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);
#define sz 100005
using namespace std;

bool check(ll r)
{
  ll cnt = 0;
  while(r > 0)
  {
    r/=10;
    cnt++;
  }
  return cnt%2 == 1;
}

int main()
{

    FASTIO
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i=1;i<=n;i++)
    {
      if(check(i))
      ans++;
    }
    cout << ans;

return 0;
}


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

#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<"\n";
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define debug2(a,b) cout<<a<<" "<<b<<"\n";
#define debug4(a,b,c,d) cout<<a<<" "<< b <<" "<<c<<" "<<d<<"\n";

ll mod = 1000000007;

using namespace std;

int main()
{
	
	 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	 int n;
	 cin>>n;
	 int count =0;
	 while(n != 0)
	 {
	 	if(n%10 == 2)
	 	{
	 		count++;
	 	}

	 	n /= 10;
	 }

	 cout<<count<<"\n";
	return 0;
}

Measured memory_bytes: 892
//https://atcoder.jp/contests/abc125/tasks/abc125_a
#include <iostream>
using namespace std;

int main(){
    int A, B, T;
    cin >> A >> B >> T;
    int An=0;
    int co=-1;
    while(An<=T){
    co++;
    An += A;
    }
    cout << co*B << endl;
}

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

#define ll long long int
#define Mod 1000000007

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k; cin>>n>>k;
    int ans=0;
    for(int i=0;i<n;i++){
        int x; cin>>x;
        if(x>=k) ans++;
    }
    cout<<ans;
    return 0;
}


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

int main()
{
	string s;
	int n, q, m = 0;
	int a[100001];

	cin >> n >> q >> s;

	a[0] = 0;

	for (int j = 0; j < s.size(); j++) {
		if (s[j] == 'A' && s[j + 1] == 'C')
			m++;
		a[j + 1] = m;
	}

	for (int i = 0; i < q; i++) {
		int l, r;

		cin >> l >> r;

		cout << a[r - 1] - a[l - 1] << endl;
	}

	return 0;
}

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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;


void solve()
{
	int x, k, d;
	cin >> x >> k >> d;
	x = abs(x);

	int m = x / d, cur = x % d;
	//bug(m, cur, k);
	int ans;
	if (m > k)
	{
		cout << x - (k * d) << endl;
		return;
	}
	else if (m == k) ans = cur;
	else
	{
		if ( abs(d - cur) < cur )
		{
			m++;
			cur = d - cur;
		}
		else if (abs(d - cur) == cur and ((k - m) % 2 != 0)) m++;

		m = k - m;

		if (m % 2 != 0)
		{
			int r = abs(cur + d);
			int l = abs(cur - d);
			ans = min(l, r);
		}
		else ans = cur;

	}

	cout << ans << endl;
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt",  "r",  stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

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

int main()
{
    int H, W;
    cin >> H >> W;
    char board[H][W];
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            cin >> board[i][j];
    
    int dis[H][W];
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            dis[i][j] = (board[i][j] == '#')? 0 : H*W;
    
    int s;
    for(int i = 0; i < H; i++)
    {
        s = -1;
        for(int j = 0; j < W; j++)
        {
            if (board[i][j] == '#')
                s = j;
            else if(s >= 0) 
                dis[i][j] = min(dis[i][j], j - s);
            
        }
        s = -1;
        for(int j = W-1; j >= 0; j--)
        {
            if (board[i][j] == '#')
                s = j;
            else if(s >= 0) 
                dis[i][j] = min(dis[i][j], s - j);
        }
    }

    for(int j = 0; j < W; j++)
        for(int i = 1; i < H; i++)
            dis[i][j] = min(dis[i-1][j]+1, dis[i][j]); 
    for(int j = 0; j < W; j++)
        for(int i = H-2; i >=0; i--)
            dis[i][j] = min(dis[i+1][j]+1, dis[i][j]); 

    int ans = 0;
    for(int i = 0; i < H; i++)
        for(int j = 0; j < W; j++)
            ans = max(ans, dis[i][j]);
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 15005;
int n;char s[N],t[N];
int a[N],A,b[N],B,res=2e9;
void init(char *s, int *a, int &l){
	rep(i,1,n)a[++l]=0;
	rep(i,1,n-1)if(s[i]!=s[i+1])a[++l]=i;
	rep(i,1,n)a[++l]=n;
}
int Abs(int x){return x>0?x:-x;}
int main() {
	read(n);scanf("%s%s",s+1,t+1);
	init(s,a,A);init(t,b,B);
	for(int i=n+1-(s[1]!=t[1]);i>=1;i-=2){int pa=i,pb=n+1;
		int now=0;bool gg=0;
		while(pa<=A&&pb<=B&&a[pa]+b[pb]<n*2){now+=Abs(a[pa]-b[pb]);pa++;pb++;}
		gg|=(pa<=A&&a[pa]<n)|(pb<=B&&b[pb]<n);if(!gg)res=min(res,now);
	}
	for(int i=n+1-(s[1]!=t[1]);i>=1;i-=2){int pa=n+1,pb=i;
		int now=0;bool gg=0;
		while(pa<=A&&pb<=B&&a[pa]+b[pb]<n*2){now+=Abs(a[pa]-b[pb]);pa++;pb++;}
		gg|=(pa<=A&&a[pa]<n)|(pb<=B&&b[pb]<n);if(!gg)res=min(res,now);
	}
	cout<<res;return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
import java.awt.image.BandedSampleModel;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {


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

        int min = 2*x;
        int max= 4*x;
        if(y%2!=0)
        {
            System.out.println("No");
        }
        else if(y<min||y>max)
        {
            System.out.println("No");
        }
        else
        {
            System.out.println("Yes");
        }

    }
}


Measured memory_bytes: 35712
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef tuple<int, int, int, int> T;

int INF = 11451419;
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};
int w, h;
int s[30][30];
int c[4];
int dp[30][30][4];

int main() {
	int i, j, k;
	
	while (cin >> w >> h) {
		if (!w) break;
		rep(i, h) rep(j, w) cin >> s[i][j];
		rep(i, 4) cin >> c[i];
		
		rep(i, h) rep(j, w) rep(k, 4) dp[i][j][k] = INF;
		priority_queue<T, vector<T>, greater<T>> que;
		dp[0][0][1] = 0;
		que.push(T(0, 0, 0, 1));
		while (!que.empty()) {
			T now = que.top(); que.pop();
			int cst = get<0>(now);
			int y = get<1>(now);
			int x = get<2>(now);
			int dir = get<3>(now);
			
			rep(i, 4) {
				int ndir = (dir + i) % 4;
				int ny = y + dy[ndir];
				int nx = x + dx[ndir];
				if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
				int ncst = (s[y][x] != i) * c[i] + cst;
				if (dp[ny][nx][ndir] > ncst) {
					dp[ny][nx][ndir] = ncst;
					que.push(T(ncst, ny, nx, ndir));
				}
			}
		}
		
		int ans = INF;
		rep(i, 4) ans = min(ans, dp[h-1][w-1][i]);
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    string s,t;
    cin >> s >> t;
    string ans = "UNRESTORABLE";
    string temp;
    vector<string> ansli;
    string p;
    bool flag = false;
    int len = t.length();
    for(int i=s.length()-1;i>=len-1;i--){
            temp = s.substr(i-(len-1),t.length());
            for(int j=0;j<len;j++){
                if(t.substr(j,1)!=temp.substr(j,1)&&temp.substr(j,1)!="?"){
                    break;
                }
                if(j==t.length()-1){
                    p = s;
                    p.replace(i-(len-1),t.length(),t);
                    replace(p.begin(),p.end(),'?','a');
                    ansli.push_back(p);
                    flag = true;
                }
            }
    }
    
    if(flag == true){
    sort(ansli.begin(),ansli.end());
    ans = ansli[0];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
s = input()
l, r = 0, len(s) - 1
ans = 0
while l < r:
    if s[l] != s[r]:
        if s[l] == 'x':
            ans += 1
            r += 1
        elif s[r] == 'x':
            ans += 1
            l -= 1
        else:
            print(-1)
            exit(0)
    l += 1
    r -= 1
print(ans)

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

void fnInput(vector<int>& rvnNum)
{
  int nNumSiz;
  cin >> nNumSiz;
  rvnNum.resize(nNumSiz);

  for (int& rnNum : rvnNum)
    cin >> rnNum;
}

int fnGcdGet(int nNumA, int nNumB)
{
  int nDividend = max(nNumA, nNumB);
  int nDivisor  = min(nNumA, nNumB);

  while (nDividend % nDivisor != 0)
  {
    int nRemain = nDividend % nDivisor;
    nDividend = nDivisor;
    nDivisor  = nRemain;
  }
  return nDivisor;
}

int fnMaxGcd(const vector<int>& cnrvnNum)
{
  vector<int> vnLeftGcd(cnrvnNum.size());
  vector<int> vnRigtGcd(cnrvnNum.size());

  vnLeftGcd[0] = cnrvnNum[0];
  
  for (int i = 0; i < cnrvnNum.size() - 1; i++)
    vnLeftGcd[i + 1] = fnGcdGet(vnLeftGcd[i], cnrvnNum[i + 1]);
  
  vnRigtGcd[cnrvnNum.size() - 1] = cnrvnNum[cnrvnNum.size() - 1];

  for (int i = cnrvnNum.size() - 1; i > 0; i--)
    vnRigtGcd[i - 1] = fnGcdGet(vnRigtGcd[i], cnrvnNum[i - 1]);

  int nMaxGcd = 0;

  for (int i = 0; i < cnrvnNum.size(); i++)
    if (i == 0)
      nMaxGcd = max(nMaxGcd, vnRigtGcd[i + 1] );
    else if (i == cnrvnNum.size() - 1)
      nMaxGcd = max(nMaxGcd, vnLeftGcd[i - 1] );
    else
      nMaxGcd = max(nMaxGcd, fnGcdGet(vnLeftGcd[i - 1], vnRigtGcd[i + 1] ));
  
  return nMaxGcd;
}
 
int main()
{
  vector<int> vnNum;

  fnInput(vnNum);
  cout << fnMaxGcd(vnNum) << endl;

  return 0;
}

Measured memory_bytes: 4488
import random
import time

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum = sum + c[i]*(d-last_d[i])
        
    return int(score - sum)


def main():
    D = int(input())

    c = list(map(int, input().split()))

    s = [list(map(int, input().split())) for i in range(D)]

    start = time.time()
    
    last_d = [0 for i in range(26)]
    
    ans = []
    
    score1 = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
                max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
                idx = j
            elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2 and c[j] != 0:
                idx = j
            
        last_d[idx] = i+1
        score1 += s[i][idx]
        score1 = down_score(i+1,c,last_d,score1)
        
        ans.append(idx)

    while time.time() - start < 1.9:
        last_d = [0 for i in range(26)]
        score2 = 0  
        tmp1 = 0
        tmp2 = 1
        tmp3 = 2
        #2値入れ替え
        if random.randint(0,1):           
            d1 = random.randint(0,D-35) 
            d2 = random.randint(d1+1,d1+17)
            d3 = random.randint(d2+1,d2+17) 
            tmp1 = ans[d1]
            tmp2 = ans[d2]
            tmp3 = ans[d3]
            if random.randint(0,1):
                ans[d1] = tmp2
                ans[d2] = tmp1
                ans[d3] = tmp3
            else:
                ans[d1] = tmp1
                ans[d2] = tmp3
                ans[d3] = tmp2
        #3値入れ替え
        else:
            d1 = random.randint(0,D-17) 
            d2 = random.randint(d1+1,d1+8)
            d3 = random.randint(d2+1,d2+8) 
            tmp1 = ans[d1]
            tmp2 = ans[d2]
            tmp3 = ans[d3]
            if random.randint(0,1):
                ans[d1] = tmp2
                ans[d2] = tmp3
                ans[d3] = tmp1
            else:
                ans[d1] = tmp3
                ans[d2] = tmp1
                ans[d3] = tmp2
            
        for i in range(D):
            score2 += s[i][ans[i]]
            last_d[ans[i]] = i+1
            score2 = down_score(i+1, c, last_d, score2)
        
        if score1 > score2:
            ans[d1] = tmp1
            ans[d2] = tmp2
            ans[d3] = tmp3
        else:
            score1 = score2
    
    for i in range(D):
        print(ans[i]+1)  

if __name__ == "__main__":
    main()

"""
100762870

"""

Measured memory_bytes: 9672
n = int(input())
w_list = list(map(int, input().split()))

Sum=sum(w_list)
Sum2=0
T=Sum

for i in range(n):
    Sum2+=w_list[i]
    if (abs((Sum-Sum2)-Sum2)<T):
        T=abs((Sum-Sum2)-Sum2)

print(T)


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

using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define INF 2e9
#define MOD 1e9+7
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define bit(n) (1LL<<(n))

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

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

template <class InputIterator>
InputIterator adv(InputIterator x, typename std::iterator_traits<InputIterator>::difference_type n) {
    advance(x, n);
    return x;
}

int ni() {
    int i;
    cin >> i;
    return i;
}

int main() {
    int N = ni();
    map<int, ll> m;
    REP(i, N) {
        int a = ni();
        m[a]++;
    }

    ll ans = 0;
    int prev = m.begin()->first;
    for (auto itr=m.begin(); itr != m.end(); itr++) {
        ll sum = itr->second;
        if (itr != m.begin() && adv(itr, -1)->first == itr->first - 1) sum += adv(itr, -1)->second;
        if (itr != --m.end() && adv(itr, 1)->first == itr->first + 1) sum += adv(itr, 1)->second;
        ans = max(ans, sum);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
import java.math.BigInteger;
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0052
public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while (true) {
			long l = sc.nextLong();
			if (l == 0) break;
			
			int ans = 0;
			while (l > 0) {
				ans += l / 5;
				l /= 5;
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 a, b;
  cin >> a >> b;
  if (13 <= a)
    cout << b << endl;
  else if (6 <= a)
    cout << b / 2 << endl;
  else
    cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
<?php
$k_s = explode(" ", trim(fgets(STDIN)));

$result = 0;
for ($i = 0; $i <= $k_s[0]; $i++) {
    for ($j = 0; $j <= $k_s[0]; $j++) {
        $z = $k_s[1] - $i - $j;
        
        if($z >= 0 && $z <= $k_s[0]) {
            $result++;
        }
    } 
}

echo $result;

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-10;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, i;
    cin >> n >> i;
    cout << n-i+1 << endl;
    return 0;
}

Measured memory_bytes: 256
N,M,X=map(int,input().split())
L=[]
for i in range(N):
  L.append(list(map(int,input().split())))

ans=float("inf")
for i in range(2**N):
  bin=format(i, 'b')[::-1]
  #print(bin)
  l=0
  F=[0]*M
  for j,b in enumerate(bin):
    if b=="1":
      l+=L[j][0]
      for k in range(M):
        F[k]+=L[j][k+1]
  
  flag=1
  for k in range(M):
    if F[k]<X:
      flag=0
  if flag:
    ans=min(l,ans)
if ans==float("inf"):
  print(-1)
else:
  print(ans)

Measured memory_bytes: 68592
#include <iostream>
#include <stack>
#include <queue>

using namespace std;

int n,N,k;
int mou[200];

int main(void){

  cin >> n;
  queue<int> q;
  queue<int> ri;

  for( int i = 1 ; i <= 2*n ; i++ ){
    q.push(i);
  }

  cin >> N;
  while(N--){
    
    cin >> k;
    if( !k ){
      for( int j = 0 ; j < n ; j++ ){
	int t = q.front();
	ri.push(t);
	q.pop();
      }
      for( int j = 0 ; j < 2*n ; j++ ){
	int t = ri.front();
	mou[j] = t;
	ri.pop();
	j++;
	t = q.front();
	mou[j] = t;
	q.pop();
      }
      for( int j = 0 ; j < 2*n ; j++ ){
	int t = mou[j];
	q.push(t);
      }
    }
    
    else{
      for( int j = 0 ; j < k ; j++ ){
	int t = q.front();
	q.push(t);
	q.pop();
      }
    }
   }
  for( int i = 0 ; i < 2*n ; i++ ){
    cout << q.front() << endl;
    q.pop();
  }
  return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long  ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;

ll x;
struct st {
	ll b, l, r; ll sc;
	bool operator<(const st &s)const {
		if (sc != s.sc)return sc > s.sc;
		if (r != s.r)return r > s.r;
		if (l != s.l)return l > s.r;
		return b > s.b;
	}
};

void solve() {
	int n; cin >> n >> x;
	vector<st> v(n);
	ll sum = 0;
	rep(i, n) {
		cin >> v[i].b >> v[i].l >> v[i].r;
		sum -= v[i].l*v[i].b;
		v[i].sc = v[i].r * x - (v[i].r - v[i].l)*v[i].b;
	}
	sort(v.begin(), v.end());
	int num = 0;
	rep(i, v.size()) {
		sum += v[i].sc;
		if (sum >= 0) {
			num = i; break;
		}
	}
	sum = 0;
	rep(i, n) {
		sum -= v[i].l*v[i].b;
	}
	vector<ll> rr(n + 1);
	rep(i, n) {
		rr[i + 1] = rr[i] + v[i].sc;
	}
	ll ans = INF;
	rep(i, n) {
		if (i < num) {
			ll csum = rr[num + 1] - v[i].sc;
			ll dif = -csum - sum;
			ll dif1 = (dif + v[i].l - 1) / v[i].l;
			ll dif2 = (dif + v[i].b*(v[i].r - v[i].l) + v[i].r - 1) / v[i].r;
			ans = min(ans, x*num + min(dif1, dif2));
		}
		else {
			ll csum = rr[num];
			ll dif = -csum - sum;
			ll dif1 = (dif + v[i].l - 1) / v[i].l;
			ll dif2 = (dif + v[i].b*(v[i].r - v[i].l) + v[i].r - 1) / v[i].r;
			ans = min(ans, x*num + min(dif1, dif2));
		}
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> n)solve();
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 4224
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int N, M;
  int64 K;
  cin >> N >> M >> K;
  vector<int64> A(N), B(M);
  cin >> A >> B;
  vector<int64> sum_a(N + 1, 0), sum_b(M + 1, 0);
  for (int i = 1; i < N + 1; i++) {
    sum_a[i] = sum_a[i - 1] + A[i - 1];
  }
  for (int i = 1; i < M + 1; i++) {
    sum_b[i] = sum_b[i - 1] + B[i - 1];
  }
  debug(sum_a);
  debug(sum_b);
  int max_sassu = 0;
  for (int i = 0; i <= N; i++) {
    if (sum_a[i] > K) break;
    auto b_idx = upper_bound(sum_b.begin(), sum_b.end(), K - sum_a[i]);
    if (b_idx - sum_b.begin() == M + 1) {
      max_sassu = max(max_sassu, M + i);
      continue;
    }
    max_sassu = max(max_sassu, (int)(b_idx - sum_b.begin()) + i - 1);
  }
  cout << max_sassu << endl;
  return 0;
}

Measured memory_bytes: 9576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int inf = 1001001001;
 
int main(){

    int n,d;
    cin >> n >> d;
    vector<vector<int>> data(n,vector<int>(d));
    rep(i,n){
        rep(j,d){
            cin >> data.at(i).at(j);
        }
    }
    int ans=0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            int norm=0;
            for(int k=0; k<d; k++){
                int diff=abs(data.at(i).at(k)-data.at(j).at(k));
                norm+=(diff*diff);
            }

            bool flag=false;
            rep(k,norm+1){
                if(k*k == norm){
                    flag=true;
                    break;
                }
            }
            if(flag){
                ans++;
            }
        }
    }

    cout << ans << endl;
}


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

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

  int n;
  cin >> n;

  unordered_set<int> loop_start = {1, 2, 4};
  for (int i = 0; i < 1e6; i++) {
    if (loop_start.find(n) != loop_start.end()) {
      cout << i + 4 << '\n';
      return 0;
    }
    n = (n & 1) ? 3 * n + 1 : n / 2;
  }
  return 0;
}

Measured memory_bytes: 384