akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;


public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		boolean[] red = new boolean[N + 1];
		int[] num = new int[N + 1];
		Arrays.fill(num, 1);
		red[1] = true;

		for (int i = 0; i < M; i ++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			num[x] --;
			num[y] ++;

			if (red[x]) {
				if (num[x] == 0) {
					red[x] = false;
				}
				red[y] = true;
			}
		}

		int count = 0;
		for (int i = 1; i <= N; i ++) {
			if (red[i])
				count ++;
		}
		System.out.println(count);
	}
}



class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		return (int) nextLong();
	}

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

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

int main() {
    string s;
    cin >> s;
    int a = 0;
    for (int i = 0; i < s.size(); i++) {
        a += (s[i] == '+' ? 1 : -1);
    }
    cout << a << endl;
}


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

int main()
{
    int a,M=-1,m=200;
    for (int i=0; i<3; ++i)
    {
        cin>>a;
        if (a>M) M=a;
        if (a<m) m=a;
    }
    cout<<(M-m)<<endl;
    return 0;
}


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

using namespace std;

map<char, char> ms {
    { 'A', 'T' },
    { 'T', 'A' },
    { 'C', 'G' },
    { 'G', 'C' },
};

int main()
{
    ios::sync_with_stdio(false);

    char c;
    cin >> c;

    cout << ms[c] << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define PI 3.1415926535897932
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  long long L,R;
  cin>>L>>R;
  
  long long ans=2018;
  
  
  if(R-L>=2019){
    ans=0;
  }
  else{
    for(long long i=L;i<R;i++){
      for(long long j=i+1;j<=R;j++){
        ans=min(ans,((i%2019)*(j%2019))%2019);
      }
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include<iostream>
#include<vector>
using namespace std;
long long a;
int main(){
	vector<char> b;
	int i=0,c[30];
	cin>>a;
	while(true){
		if(a==a/2*2){
			b.push_back('0');
		}else if(a-a/2*2==-1){
			b.push_back('1');
			a+=-1;
		}else{
			b.push_back('1');
		}
		a/=-2;
		if(a==0){
			break;
		}
	}
	for(i=b.size()-1;i>=0;i--){
		cout<<b[i];
	}
	return 0;
}

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

int main(){
  //テ、ツクツ凝」ツ?ォテ」ツ?ッテ」ツ?ソテ・ツ?コテ」ツ?淌」ツ?ィテ」ツ?催」ツ?ッ, flgテ・ツ?・テ」ツつ古ヲツ崢ソテ」ツ?? テ・ツ渉ウテ」ツ?ォ2, テ、ツクツ甘」ツ?ォ1.
  //テ・ツキツヲテ」ツ?ォテ」ツ?ッテ」ツ?ソテ・ツ?コテ」ツ?淌」ツ?ィテ」ツ?催」ツ?ッ, flgテ・ツ?・テ」ツつ古ヲツ崢ソテ」ツ?? テ・ツ渉ウテ」ツ?ォ1.
  //テ・ツ渉ウテ」ツ?ォテ」ツ?ッテ」ツ?ソテ・ツ?コテ」ツ?淌」ツ?ィテ」ツ?催」ツ?ッ, flgテ・ツ?・テ」ツつ古ヲツ崢ソテ」ツ?? テ、ツクツ凝」ツ?ォ2, テ・ツキツヲテ」ツ?ォ1.
  //テ、ツクツ甘」ツ?ォテ」ツ?ッテ」ツ?ソテ・ツ?コテ」ツ?淌」ツ?ィテ」ツ?催」ツ?ッ, flgテ・ツ?・テ」ツつ古ヲツ崢ソテ」ツ?? テ、ツクツ凝」ツ?ォ1.

  int n;
  int t[12][12];
  int dx[] = {-1, 1};
  int dy[] = {1, -1};

  for(int SET = 1; cin >> n, n; SET++){
    int flg = true; //テ・ツキツヲテヲツ鳴愿」ツつ?、ツクツ甘」ツ?ォテゥツ?イテ」ツつ禿」ツ?ァテ」ツ??」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ??
    int x = 0, y = 0;
    int cnt = 0;

    while(cnt < n * n){
      if(n <= y){
        flg = !flg;
        x += 2;
        y--;
      }
      else if(x < 0){
        flg = !flg;
        x++;
      }
      else if(n <= x){
        flg = !flg;
        y += 2;
        x--;
      }
      else if(y < 0){
        flg = !flg;
        y++;
      }

      t[y][x] = ++cnt;
      x += dx[flg];
      y += dy[flg];
    }

    printf("Case %d:\n", SET);

    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        printf("%3d", t[i][j]);
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 1192
#include <iostream>

using namespace std;
int main (){

	char S[100000];
	int n,a,b,a1,b1;
	a1 = 0;
	b1 = 0;
	
	cin >> n >> a >>b;
	cin >>S;
	for(int i = 0;i < n;i++){
		if(S[i]== 'a'){	
			if(a1+b1 < a+b){
				cout << "Yes" << endl;
				a1++;
			}else{
				cout << "No" << endl;
			}

		}else if(S[i]== 'b'){
			if(a1+b1 < a+b && b1 < b){
				cout << "Yes" << endl;
				b1++;				
			}else{
				cout << "No" << endl;
			}
		}else if(S[i]== 'c'){
			cout << "No" << endl;
		}		
		
	}
		
// cout << cnt << endl;
return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(b / a, c) << endl;

  return 0;
}


Measured memory_bytes: 256
K, = map(int, input().split())
D, = map(int, input().split())
N = len(str(K))
M = 10**9+7
dp = [[0]*D for _ in range(N+1)]
dp2 = [[0]*D for _ in range(N+1)]
dp[0][0] = 1
dp2[0][0] = 1
for i in range(1, N+1):
    Ki = K%10
    K //= 10
    for j in range(D):
        for k in range(10):
            dp[i][(j+k)%D] += dp[i-1][j]
            dp[i][(j+k)%D] %= M
        for k in range(Ki):
            dp2[i][(j+k)%D] += dp[i-1][j]
            dp2[i][(j+k)%D] %= M
        dp2[i][(j+Ki)%D] += dp2[i-1][j]
        dp2[i][(j+Ki)%D] %= M
print((dp2[N][0]-1)%M)


Measured memory_bytes: 61020
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var x = o.m(m);
  var map = xArray("[]",n);
  for(var i = 0; i < m; i++){
    var s = x[i][0]-1, t = x[i][1]-1;
    map[s].push(t);
  }
  var dp = xArray(0,n);
  for(var i = n-1; i--;){
    var c = 1/map[i].length;
    for(var j = map[i].length; j--;){
      dp[i] += (dp[map[i][j]]+1) * c;
    }
  }
  var ans = dp[0];
  var dp2 = dp.concat();
  for(var i = n-2; i--;){
    dp[i+1] = dp2[i+1];
    if(map[i].length === 1)continue;
    dp[i] = 0;
    var mx = 0, id;
    var c = 1/(map[i].length-1);
    for(var j = map[i].length; j--;){
      if(dp[map[i][j]] > mx)mx = dp[map[i][j]], id = j;
    }
    for(var j = map[i].length; j--;){
      if(j === id)continue;
      dp[i] += (dp[map[i][j]]+1) * c;
    }
    for(var k = i; k--;){
      var c = 1/map[k].length;
      dp[k] = 0;
      for(var j = map[k].length; j--;){
        dp[k] += (dp[map[k][j]]+1) * c;
      }
    }
    if(dp[0] < ans)ans = dp[0];
  }
  return ans;
}

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

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

    int ans = 1000;
    for(int i = 0; i+2 < s.length(); i++){
        int num = (s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        if(abs(753-num) < ans) ans = abs(753-num);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define pub(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define getl(s) getline(cin,s);



int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n,k;
  cin>>n>>k;
  ll dp[n+1]={mod};
  for(int i=1;i<=n;i++){
      dp[i] =mod;
  }
  ll h[n+1];
  for(ll i=1;i<=n;i++){
    cin>>h[i];
  }
  dp[1] =0;
  for(ll i=1;i<=n;i++){
      for(ll j = i+1;j<=i+k;j++){
          if(j<=n){
              dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]));
          }
      }
  }
  cout<<dp[n];
  return 0;
}


Measured memory_bytes: 5180
function Main(input) {
  input = input.replace(/\n/g, ' ');
  input = input.split(" ");
  var A = input[0];
  input.shift();
  var a = 0;
  var b = 0;
  var c = 0;
  var ans = "No";
  for (var i = 0; i < A; i++) {
    var p = Number(input[i]);
    if (p % 4 == 0) {
      a++;
    } else if (p % 2 == 0) {
      b++;
    } else {
      c++;
    }
  }

  if (c <= a) {
    ans = "Yes";
  } else if (a + 1 == c && b == 0) {
    ans = "Yes";
  }

  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 18380
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <bitset>

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> a(n);
    for (int i = 0; i < n; ++i) {
        int s;
        cin >> s;
        a[i].resize(s);
        for (int j = 0; j < s; ++j) {
            cin >> a[i][j].first >> a[i][j].second;
            --a[i][j].first;
        }
    }
    int res = 0;
    for (int pattern = 0; pattern < (1 << n); ++pattern) {
        bool ok = true;
        for (int i = 0; i < n && ok; ++i) {
            if (1 & (pattern >> i)) {
                for (auto test : a[i]) {
                    if ((1 & (pattern >> test.first)) != test.second) {
                        ok = false;
                        break;
                    }
                }
            }
        }
        if (ok) {
            res = max(res, (int)bitset<32>(pattern).count());
        }
    }
    cout << res << "\n";
    return 0;
}


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


vector<int> v;
int n,a,b;
int o[1111111];
int f(int n)
{
    int k=0;
    for(;n;n/=2)
        k+=n%2;
    return k;
}

int main()
{
	scanf("%d %d %d",&n,&a,&b);
	if(f(a^b)%2==0)
    {
        puts("NO");
        return 0;
    }
	v.push_back(0);
	for(int i=0;i<=n-f(a^b);i++)
    {
        vector<int> v1;
        v1=v;
        for(int j=0;j<v1.size();j++)
            v1[j]*=2;
        for(int j=1;j<=v.size();j++)
            v1.push_back((v[v.size()-j]*2)^1);
        v=v1;
    }
    for(int i=0;i<f(a^b)/2;i++)
    {
        vector<int> v1;
        v1.push_back(v[0]*4);
        v1.push_back(v[0]*4+1);
        v1.push_back(v[0]*4+3);
        v1.push_back(v[0]*4+2);
        for(int i=1;i<v.size()-1;i+=2)
        {
            v1.push_back(v[i]*4+2);
            v1.push_back(v[i]*4+3);
            v1.push_back(v[i]*4+1);
            v1.push_back(v[i]*4+0);
            v1.push_back(v[i+1]*4+0);
            v1.push_back(v[i+1]*4+1);
            v1.push_back(v[i+1]*4+3);
            v1.push_back(v[i+1]*4+2);
        }
        v1.push_back(v[v.size()-1]*4+2);
        v1.push_back(v[v.size()-1]*4+0);
        v1.push_back(v[v.size()-1]*4+1);
        v1.push_back(v[v.size()-1]*4+3);
        v=v1;
    }
    vector<int> v1;
    for(int p=0;p<n;p++)
        if((a^b)&(1<<p)) v1.push_back(p);
    for(int i=v1.size()-1;i>=0;i--)
    {
        
        for(int j=0;j<v.size();j++)
        {
            int n=(v[j]>>v1[i])&1,m=(v[j]>>i)&1;
            v[j]^=(n<<v1[i]);
            v[j]^=(m<<i);
            v[j]^=(n<<i);
            v[j]^=(m<<v1[i]);
        }
    }
    if((v[0]^v[v.size()-1])!=(a^b)) a=1/0;
    puts("YES");
    for(int j=1;j<v.size();j++)
        if(f(v[j]^v[j-1])!=1) a/0;//puts("@");
    for(int j=0;j<v.size();j++)
    {
        v[j]^=a;
        if(o[v[j]]) a=1/0;//puts("#");
        o[v[j]]++;
    }
    if(f(v[v.size()-1]^v[0])!=f(a^b)) a=1/0;
    //if(b!=v[v.size()-1]) a=1/0;
    for(int j=0;j<v.size();j++)
        printf("%d ",v[j]);
        //printf("%d %d",v[0],v[v.size()-1]);
}


Measured memory_bytes: 2292
#include <stdio.h>
#include <string.h>
int main()
{
  char S[1000];
  scanf("%s",S);
  int nCnt=0,sCnt=0,eCnt=0,wCnt=0;
  int i=0;
  for(i=0;i<strlen(S);i++){
	  if(S[i]=='N')++nCnt;
	  else if(S[i]=='S')++sCnt;
	  else if(S[i]=='E')++eCnt;
	  else if(S[i]=='W')++wCnt;

  }

  if(nCnt>0 && sCnt>0 && eCnt>0 && wCnt>0) printf("Yes\n");
  else if(nCnt>0 && sCnt>0 && eCnt==0 && wCnt==0) printf("Yes\n");
  else if(nCnt==0 && sCnt==0 && eCnt>0 && wCnt>0) printf("Yes\n");
  else printf("No\n");
}

Measured memory_bytes: 128
import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.util.*;
class Main {
	
	static int[][] map;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] S = sc.next().toCharArray();
		char[] T = Arrays.copyOf(S, S.length);
		
		
		
		for(int i = 0; i < S.length-7; i++) {
			int[] check = new int[8];
			for(int j = 0; j < 8; j++) {
				switch(S[i + j]) {
				case 'A':check[0]++; break;
				case 'I':check[1]++; break;
				case 'D':check[2]++; break;
				case 'U':check[3]++; break;
				case 'N':check[4]++; break;
				case 'Y':check[5]++; break;
				}
			}
			if(check[0] == 2 && check[1] == 1 && check[2] == 1 && check[3] == 1 && check[4] == 2 && check[5] == 1) {
				T[i] = 'A';
				T[i+1] = 'I';
				T[i+2] = 'Z';
				T[i+3] = 'U';
				T[i+4] = 'N';
				T[i+5] = 'Y';
				T[i+6] = 'A';
				T[i+7] = 'N';
			}
		}
		
		System.out.println(String.valueOf(T));
		
		
		
	}
 	
}

Measured memory_bytes: 17364
import java.util.Arrays;
import java.util.Scanner;

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

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int l = scan.nextInt();
        String a[] = new String[n];

        for(int i = 0; i < n ;i++){
            a[i] = scan.next();
        }

        Arrays.sort(a);

        String res = "";

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

        System.out.println(res);


    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;

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


int main(){
    int K;
    cin >> K;
    int ans = 0;


for(int a = 1; a <= K; a++){
    for(int b = 1; b <= K; b++){
        for(int c = 1; c <= K; c++){

            ans += gcd(a, gcd(b, c));
        
        }
    
    }

}

cout << ans << endl;


}

Measured memory_bytes: 3636
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  attr_accessor :seen

  def initialize
    @n, @m = gets.to_s.split.map { |v| v.to_i }
    @h = gets.to_s.split.map { |v| v.to_i }
    @g = Array.new(n) { [] }
    m.times do
      a, b = gets.to_s.split.map { |v| v.to_i }
      a -= 1
      b -= 1
      g[a] << h[b]
      g[b] << h[a]
    end
    @seen = Array.new(n, false)
  end

  def solve
    ans = 0
    n.times do |v|
      ans += 1 if g[v].empty? || g[v].max < h[v]
    end
    ans
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end


Measured memory_bytes: 27416
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=map(int, input().split())
    l=[int(input()) for i in range(n)]
    l.sort()
    ans=10**18
    for i in range(0,n-k+1):
        ans=min(ans,l[i+k-1]-l[i])
    print(ans)
resolve()

Measured memory_bytes: 7384
n, k = map(int, input().split())
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

#print(Base_10_to_n(n, k))
x = Base_10_to_n(n, k)
print(len(str(x)))

Measured memory_bytes: 3060
x,k,d = list(map(int, input().split(' ')))

if k*d<=x:
    print(abs(x-k*d))
elif -k*d>=x:
    print(abs(x+k*d))
else:
    rem = x%(d)
    div = x//d
    if (k-div)%2==0:
        print(rem)
    else:
        print(d-rem)

Measured memory_bytes: 9096
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[330000];
main(){
  ll n,ans=0,tmp,tmp2;
  cin>>n;
  rep(i,0,n)cin>>a[i];
  rep(i,0,61){
    tmp=0,tmp2=0;
    ll f=powl((ll)2,i);
    f%=mod;
    rep(j,0,n){
      if((a[j]>>i)&1)tmp++;
    }
    tmp=(tmp*(n-tmp))%mod;
    ans=(ans+f*tmp)%mod;
  }
  cout<<ans%mod;
}

Measured memory_bytes: 2560
#include <stdio.h>
int N;
int parent[100001];
char isLeaf[100001];
int child[100001], sibing[100001];
int tail[100001];

int calcDepth(int i) {
  if(parent[i] == -1) return 0;
  return calcDepth(parent[i]) + 1;
}

void addChild(int x, int c) {
  int p;
  if(child[x] == -1) {
    child[x] = c;
  } else {
    sibing[tail[x]] = c;
  }
  tail[x] = c;
}

int main() {
  int i,j,k;
  scanf("%d", &N);
  for(i = 0; i < N; ++i) {
    parent[i] = -1;
    isLeaf[i] = 1;
    child[i] = -1;
    sibing[i] = -1;
    tail[i] = i;
  }
  for(i = 0; i < N; ++i) {
    int id, k;
    scanf("%d %d", &id, &k);
    while(k--) {
      int c;
      scanf("%d", &c);
      parent[c] = id;
      addChild(id, c);
      isLeaf[id] = 0;
    }
  }
  for(i = 0; i < N; ++i) {
    int depth = calcDepth(i);

    printf("node %d: parent = %d, depth = %d, ", i, parent[i], depth);
    if(depth == 0) {
      printf("root, ");
    } else if(isLeaf[i]) {
      printf("leaf, ");
    } else {
      printf("internal node, ");
    }
    printf("[");
    for(j = child[i]; j != -1; j = sibing[j]) {
      if(j != child[i]) printf(", ");
      printf("%d", j);
    }
    printf("]\n");
  }
  return 0;
}

Measured memory_bytes: 2080
s = list(input())
pee = ""
for i in range(1,len(s)):
    if s[i-1] == "P" and s[i] == "?":
        s[i] = "D"
    if s[i-1] == "?" and s[i] == "D":
        s[i-1] = "P"
    if s[i-1] == "?" and s[i] == "?":
        s[i-1]="P"
        s[i]="D"
for i in range(len(s)):
    if s[i] == "?":
        s[i] = "D"
for i in s:
    pee+=i
print(pee)


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

int main() {
    int n, x, y, z, w, a[3000], i, j;
    int dp[2001][2];
    cin >> n >> x >> y;
    z = 0;
    w = 0;
    for (i = 0; i < n; ++i) {
        cin >> a[i];
        if (a[i] > a[z])
            z = i;
        if (a[i] <= a[w])
            w = i;
    }
    for (i = 0; i < n/2; ++i)
        swap(a[i], a[n - i - 1]);
    a[n] = y;
    for (i = 0; i < n; ++i) {
        dp[i][0] = abs(a[0] - a[i + 1]);
        for (j = 0; j < i; ++j)
            dp[i][0] = min(dp[i][0], dp[j][1]);
        dp[i][1] = abs(a[0] - a[i + 1]);
        for (j = 0; j < i; ++j)
            dp[i][1] = max(dp[i][1], dp[j][0]);
    }
    cout << dp[n - 1][1];
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static List<int> pattern = new List<int>();
        static int N;
        static int[] A;

        static void Main(string[] args)
        {
            N = int.Parse(Console.ReadLine());
            A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var q = int.Parse(Console.ReadLine());
            var m = Console.ReadLine().Split().Select(int.Parse).ToArray();

            Dfs(0, 0);

            for (var i = 0; i < q; i++)
            {
                Console.WriteLine(pattern.Contains(m[i]) ? "yes" : "no");
            }

        }

        static void Dfs(int n, int total)
        {
            if (n == N)
            {
                pattern.Add(total);
                return;
            }

            Dfs(n + 1, total + A[n]);
            Dfs(n + 1, total);
        }
    }
}



Measured memory_bytes: 24116
<?php
fscanf(STDIN,"%d %d",$N,$K);
 
$input = array();
 
for($i=1;$i<=$K;++$i){
    $a=intval(trim(fgets(STDIN)));
    $have=explode(' ',trim(fgets(STDIN)));
    $input=array_merge($input, $have);
}
 
$man = array();
for($i=1;$i<=$N;++$i){
    array_push($man, $i);
}
 
$result = array_diff($man, $input);
echo count($result);
?>

Measured memory_bytes: 17216
def main():
    mod = 1000000007
    N = int(input())
    A = list(map(int, input().split()))

    exist = True
    res = 0
    if N % 2 == 0:
        check = [2] * (N // 2)
        for a in A:
            if a % 2 == 1:
                if check[(a-1)//2] > 0:
                    check[(a-1)//2] -= 1
                else:
                    exist = False
            else:
                exist = False
        if exist:
            res = 1
            for i in range(N//2):
                res *= 2
                res %= mod
    else:
        check = [2] * ((N+1) // 2)
        check[0] = 1
        for a in A:
            if a % 2 == 0:
                if check[a//2] > 0:
                    check[a//2] -= 1
                else:
                    exist = False
            else:
                exist = False
        if exist:
            res = 1
            for i in range((N-1)//2):
                res *= 2
                res %= mod

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 84400
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define F first
#define S second

int32_t main(){
	int h,a;
	cin>>h>>a;
	cout<<(h-1)/a+1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

ll N;

int main () {
        cin >> N;
        for (ll i = 1; i <= N; i++) {
                if (i * (i+1) / 2 >= N) {
                        ll m = i * (i+1) / 2 - N;
                        assert(m <= i);
                        for (ll j = 1; j <= i; j++) if (j != m) {
                                cout << j << '\n';
                        }
                        return 0;
                }
        }
        return 0;
}


Measured memory_bytes: 256
def c_cat_snuke_and_a_voyage():
    N, M = [int(i) for i in input().split()]
    Ships = [[int(i) for i in input().split()] for j in range(M)]

    node_1 = set()  # 島 1 から定期便で行き来できる島
    node_n = set()  # 島 N から定期便で行き来できる島
    for a, b in Ships:
        if a == 1:
            node_1.add(b)
        if b == N:
            node_n.add(a)
    return 'POSSIBLE' if [1 for i in node_1 if i in node_n] else 'IMPOSSIBLE'
print(c_cat_snuke_and_a_voyage())

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

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

        //初期処理
        //Scanner sc=new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            int n= Integer.parseInt(br.readLine());
            String[] sElementArray = br.readLine().split(" ");
            int[] elementArray = Arrays.stream(sElementArray).mapToInt(Integer::parseInt).toArray();
            int q = Integer.parseInt(br.readLine());
            String[] sTargetArray = br.readLine().split(" ");
            int[] targetArray = Arrays.stream(sTargetArray).mapToInt(Integer::parseInt).toArray();
        
        for (int var : targetArray) {
            boolean ans=solve(0,var,n,elementArray);
            if (ans){System.out.println("yes");}else{System.out.println("no");}
        }
        }catch(IOException e){e.printStackTrace();}
    }

    public static boolean solve (int i, int m, int n, int[] elementArray){
        if (m==0){
            return true;
        } else if (i==n){
            return false;
        } else{
            return (solve(i+1,m-elementArray[i],n,elementArray)|| solve(i+1,m,n,elementArray));
        }
    }
}



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

int main(){
  int N;
  int counter = 0;
  int counter_0 = 0;
  long long sum = 0;
  cin >> N;
  vector<long> A(N);
  for(int i = 0;i < N;i++){
    cin >> A[i];
    if(A[i] < 0)counter++;
    if(A[i] == 0)counter_0++;
  }
  if(counter % 2 == 0 || counter_0 > 0){
    for(int i = 0;i < N;i++){
      if(A[i] < 0)A[i] = -A[i];
      sum += A[i];
    }
  }else{
    for(int i = 0;i < N;i++){
      if(A[i] < 0)A[i] = -A[i];
      sum += A[i];
    }
    sort(A.begin(),A.end());
    sum -= A[0] * 2;
  }
  cout << sum << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <string>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

int main() {


    int a, b, c;
    cin >> a >> b >> c;
    int max_ = max(a, b);
    int min_ = min(a, b);

    int cnt_ma = max_;
    int cnt_mi = min_;
    int cnt = 0;
    while (c > 0 and cnt_ma > 0) {
        c -= max_;
        cnt_ma--;
        cnt++;
    }
    // cout << cnt << '\n';
    while (c > 0 and cnt_mi > 0) {
        c -= min_;
        cnt_mi--;
        cnt++;
    }

    cout << cnt << '\n';

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

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

	if (a > b) {
		cout << 0 << endl;
		return 0;
	}

	if (n == 1) {
		if (a != b) {
			cout << 0 << endl;
		}
		else {
			cout << 1 << endl;
		}
		return 0;
	}

	cout << (ll)(n - 2) * (b - a) + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=100100100100;
const int Inf=1001001001;
const int mod=1000000007;
const double pi=3.141592653589793;

int main(){
    ll a,b,c,d,e,x,y;cin>>a>>b>>c>>x>>y;
    c*=2;
    ll ans=inf;
    rep(i,100001){
        ll k=0;
        k+=c*i;
        d=x-min(i,x);
        e=y-min(i,y);
        k+=d*a+e*b;
        chmin(ans,k);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int x,n,flag=0,min=0,max=101;
  cin>>x>>n;
  int p[n];
  for(int i=0;i<n;i++)
  cin>>p[i];
 for(int i=x;i>0;i--){
   for(int j=0;j<n;j++){
	if(p[j]==i)
      flag=1;
	}
   if(flag==0){
     min=i;
     break;
   }
   flag=0;
 }
  for(int i=x;i<=100;i++){
   for(int j=0;j<n;j++){
	if(p[j]==i)
      flag=1;
	}
   if(flag==0){
     max=i;
     break;
   }
   flag=0;

 }
  if(x-min>max-x)
    cout<<max;
  else
    cout<<min;
}

Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//ワーシャルフロイト法のテンプレ.graphに最短経路が格納される.
//負の重みがある場合inf + const = inf に気を付けること.
//graphは隣接行列.
void WF(vector<vector<int>> &graph){
	int n = graph.size();
	for (int k = 0; k < n; k++){
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
			}
		}
	}
}

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * b, c * d) << endl;

	return 0;
}

Measured memory_bytes: 3644
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    b = deque()
    A.sort()
    for i in range(N//2):
        if i % 2 == 0:
            b.appendleft(A[i])
            b.append(A[N-i-1])
        else:
            b.append(A[i])
            b.appendleft(A[N-i-1])
    if N % 2 !=  0:
        a = A[N//2]
        l = b[0]
        r = b[-1]
        if abs(a-l) > abs(a-r):
            b.appendleft(a)
        else:
            b.append(a)
    
    ans = 0
    for i in range(N-1):
        ans += abs(b[i]-b[i+1])
        
    return ans


def main():
    N = read_int()
    A = [read_int() for _ in range(N)]
    print(slv(N, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 12188
n = int(input())
x,num = [],0
for i in range(n):
	a,b = (int(j) for j in input().split())
	x.append((num+a)%86400)
	num = (num+a+b)%86400
x,ans = sorted(x),0
from bisect import bisect
for i in range(n):
	ans = max(ans,bisect(x,x[i]+10800)-i)
	if x[i]<=10800: x.append(x[i]+86400)
print(ans)

Measured memory_bytes: 8276
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,X = ilint()
L = [(i,X[i]) for i in range(N)]
L.sort(key=lambda x:x[1])
B1,B2 = L[N//2-1][1],L[N//2][1]
ans = [B1]*N
for i in range(N//2):
    ans[L[i][0]] = B2
lprint(ans)

Measured memory_bytes: 115640
#include <stdio.h>

main(){
        int i,j;

        int p[10];

        for(i=0;i<10;i++)
                scanf("%d",&p[i]);

        for(i=0;i<9;i++)
                for(j=0;j<9-i;j++)
                        if(p[j]<p[j+1]){
                                p[j]+=p[j+1];
                                p[j+1]=p[j]-p[j+1];
                                p[j]-=p[j+1];
                        }

        printf("%d\n",p[0]);
        printf("%d\n",p[1]);
        printf("%d\n",p[2]);

        return 0;
}

Measured memory_bytes: 600
import java.util.*;

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

        long[] x = new long[n];
        long[] y = new long[m];

        for(int i = 0; i < n; i++) {
            x[i] = sc.nextLong();
        }
        for(int j = 0; j < m; j++) {
            y[j] = sc.nextLong();
        }

        long widthSum = 0, heightSum = 0;
        for(int i = 0; i < n; i++) {
            widthSum += i * x[i] - (n - 1 - i) * x[i]; //why????
            widthSum %= (1000000000 + 7);
        }
        for(int j = 0; j < m; j++) {
            heightSum += j * y[j] - (m - 1 - j) * y[j];
            heightSum %= (1000000000 + 7);
        }

        long res = (widthSum * heightSum) % (1000000000 + 7);
        System.out.println(res);
    }
}


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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

struct node {
    ll w, from, to;
};

int main() {
    ll n, m, i, j, k;
    cin >> n;
    ll g[n][n], result_g[n][n];
    vector<node> v;
    for(i = 0; i < n; i++) {
        for(j = 0; j < n; j++) {
            cin >> g[i][j];
            if(i < j) {
                node x = {g[i][j], i, j};
                v.push_back(x);
            }
            if(i == j)
                result_g[i][j] = 0;
            else {
                result_g[i][j] = INF;
            }
        }
    }
    ll ret = 0;
    sort(v.begin(), v.end(), [](const node &a, const node &b) { return a.w < b.w; });
    for(node x : v) {
        bool flag = false;
        for(i = 0; i < n; i++) {
            if(x.w > result_g[x.from][i] + result_g[i][x.to]) {
                cout << -1 << endl;
                return 0;
            } else if(x.w == result_g[x.from][i] + result_g[i][x.to]) {
                flag = true;
                break;
            }
        }
        result_g[x.from][x.to] = x.w;
        result_g[x.to][x.from] = x.w;
        if(!flag) {
            ret += x.w;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 2804
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillDouble(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%lf", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;
const int MAX_V = 305;

struct road {
  int from;
  int to;
  long dist;

  bool operator>(road other) const {
    return dist > other.dist;
  }
};

long d[MAX_V][MAX_V];
long mind[MAX_V][MAX_V];

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

  long n, l;
  cin >> n >> l;

  vector<long> a(n);
  fillLong(a, n);

  int lastIdx = -1;
  rep(i, n-1) {
    if (a[i] + a[i+1] >= l) {
      lastIdx = i;
    }
  }

  if (lastIdx == -1) {
    cout << "Impossible" << endl;
  } else {
    cout << "Possible" << endl;
    rep(i, lastIdx) {
      cout << i+1 << endl;
    }
    for (int i = n-2; i> lastIdx; i--) {
      cout << i+1 << endl;
    }
    cout << lastIdx+1 << endl;
  }
}


Measured memory_bytes: 1664
N = int(input())
s=[]
for i in range(0,N):
    s.append(input())

answer=0
a=0
b=0
q=1
que=1
for t in s:
    for i in range(0,len(t)-1):
        if t[i]=="A" and t[i+1]=="B":
            answer+=1
    if t[0]=="B":
        b+=1
        que=0
    if t[-1]=="A":
        a+=1
        que=0
    if (t[0]=="B" and t[-1]!="A") or (t[0]!="B" and t[-1]=="A"):
        q=0
if que==1:
    q=0
if a>b:
    print(answer+b-q)
else:
    print(answer+a-q)
        



Measured memory_bytes: 3828
#include <iostream>


using namespace std;

int main() {
    int a, b, c, d;
    long long  M = 998244353;
    cin >> a >> b >> c >> d;
    long long r[c + 1][d + 1];
    for (int i = 0; i < c + 1; i++) {
        for (int j = 0; j < d + 1; j++) {
            r[i][j] = 0;
        }
    }
    for (int i = 0; i < c + 1; i++) {
        for (int j = 0; j < d + 1; j++) {
            if (i < a || j < b) {
                r[i][j] = 0;
            } else if (i == a && j == b) {
                r[i][j] = 1;
            } else {
                r[i][j] =( (i * r[i][j - 1] )%M+  (j * r[i - 1][j])%M - (((r[i - 1][j - 1] * (i - 1) )%M)* (j - 1)) % M)%M;
            }
        }
    }

    /*for (int i = 0; i < c + 1; i++) {
        for (int j = 0; j < d + 1; j++) {
            cout << r[i][j] << " ";
        }
        cout << "\n";
    }*/
    if (r[c][d] < 0) {
        r[c][d] +=M;
    }
    cout << r[c][d] << endl;
}

Measured memory_bytes: 73988
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn solve() {
    input! {
        a: usize
    };

    let res = a + a.pow(2) + a.pow(3);
    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .name("big stack size".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(|| {
            solve();
        })
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 2240
#include <iostream>

using namespace std;

const int MAX = 100000;
const int MOD = 1000000007;

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

  int c[3] = {0};

  long long ans = 1;
  for (int i = 0; i < N; i++) {
    int a; cin >> a;

    int res = 0;
    bool updated = false;
    for (int j = 0; j < 3; j++) {
      if (c[j] == a) {
        res++;
        if (!updated) {
          c[j]++;
          updated = true;
        }
      }
    }
    ans = ans * res % MOD;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3656
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define pb push_back
#define INF 1000000000
#define all(x) (x).begin(),(x).end()
int s,n,m;
int x[2010],t[2010],p[2010];
vector<int> v;
int dp[2010][2010],imos[2010],rest[2010][2010];
int minima[2010];
int dist(int a,int b)
{
	return imos[b]-imos[a];
}
int sum_dist(int a,int b)
{
	if(a==b)return 0;
	return rest[b][b-a-1];
}
int F(int j,int i,int k)
{
	if(k>i)return INF;
	return dp[k][j]+sum_dist(k,i);
}
void update(int j)
{
	for(int i=0;i<n;i++)dp[i][j]=F(j-1,i,minima[i]);
	return;
}
void culc(int x,int ib,int ie,int jb,int je)//[ib,ie],[jb,je]
{
	if(ib>ie)return;
	int mid = (ib+ie)/2;
	int val=INF+1,id,v;
	for(int i=jb;i<=je;i++)
	{
		if((v=F(x,mid,i))<val)
		{
			val=v;
			id=i;
		}
	}
	minima[mid]=id;
	culc(x,ib,mid-1,jb,minima[mid]);
	culc(x,mid+1,ie,minima[mid],je);
	return;
}
int main()
{
	scanf("%d %d %d",&s,&n,&m);
	for(int i=0;i<s;i++)scanf("%d",&x[i]);
	for(int i=0;i<n;i++)scanf("%d %d",&t[i],&p[i]);
	for(int i=0;i<n;i++)v.pb(t[i]-x[p[i]-1]);
	sort(all(v));
	for(int i=1;i<n;i++)imos[i]=v[i]-v[i-1];
	for(int i=1;i<n;i++)imos[i]+=imos[i-1];
	for(int i=0;i<n;i++)for(int j=1;j<=i;j++)rest[i][j]=rest[i][j-1]+dist(i-j,i);
	for(int i=0;i<=n;i++)for(int j=0;j<=m;j++)dp[i][j]=INF;
	for(int i=0;i<n;i++)dp[i][1]=rest[i][i];
	for(int j=1;j<m;j++)
	{
		culc(j,0,n-1,0,n-1);
		update(j+1);
	}
	printf("%d\n",dp[n-1][m]);
	return 0;
}

Measured memory_bytes: 31720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod_;
        a = a * a % mod_;
        n >>= 1;
    }
    return res;
}

//const ll mod = 998244353;
const ll mod = 1e9 + 7;
const ll MAX_SIZE = 1000005;
array<ll,MAX_SIZE> fac, inv, finv;
ll fac_init() {
    // combination init
    fac[0] = 1;
    for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % mod;
    finv[0] = modpow(fac[MAX_SIZE - 1], mod - 2, mod);
    repe(i, 1, MAX_SIZE) finv[i] = finv[i - 1] * (MAX_SIZE - i) % mod;
    reverse(all(finv));

    //inv init
    repe(i, 1, MAX_SIZE) inv[i] = modpow(i, mod - 2, mod);
}

ll perm(ll a, ll b) { return fac[a] * finv[a - b] % mod; }

ll comb(ll a, ll b) { return fac[a] * finv[b] % mod * finv[a - b] % mod; }

int main() {
    init();
    ll N, M, K;
    cin >> N >> M >> K;
    ll S = N * M;
    fac_init();
    ll ans = 0;
    vl sum(S + 1, 0);
    rep(i,S)
        sum[i + 1] = sum[i] + i + 1;

    ll C = comb(S - 2, K - 2);
    rep(i,N)rep(j,M){
        ll tmp = 0;
        ll l, r;
        // 探索点の右で縦にわって２つの四角形の累積和を考える, l=探索点を含む列のマンハッタン距離, r=探索点の右隣
        l = sum[i] + sum[N - i - 1];
        r = l + N;
        l = (j + 1) * l % mod + N * (j + 1) * j % mod * inv[2] % mod;
        r = (M - j - 1) * r % mod + N * (M - j - 1) * (M - j - 2) % mod * inv[2] % mod;
        ans = (ans + l * C % mod + r * C % mod) % mod;
    }
    ans = ans * inv[2] % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 25216
N, K = map(int, input().split())
H = [int(input()) for i in range(N)]
H.sort()
min_diff = 10 ** 9 
for i in range(N-K+1):
    low = H[i]
    high = H[i+K-1]
    min_diff = min(min_diff, high - low)
print(min_diff)

Measured memory_bytes: 7436
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    Set<Integer> set = new HashSet<Integer>();
    for(int i = 0; i < N; i++){
        int A = sc.nextInt();
        if(set.contains(A)){
            set.remove(A);
        }else{
            set.add(A);
        }
    }
    System.out.println(set.size());
    
  }
}


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

using namespace std;

typedef long long int lli;

#define INF (1e9)


int solv(int a, int b) {
	int tmp = a;
	int c = 0;
	while(tmp > 0) {
		c += tmp % b;
		tmp /= b;
	}
	return c;
}

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

	int ans = INF;
	for(int i=0; i<=N ; i++) {
		int c = solv(i, 6) + solv(N-i, 9);
		ans = min(c, ans);
	}

	cout << ans << endl;
}


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

int main(void)
{
	long long int n,m,i,ans,m2=1,m3;
	scanf("%lld %lld",&n,&m);
	
	if(n-m>=2||m-n>=2){
		printf("0\n");
	} else if(n-m==0){
		for(i=m;i>=2;i--){
			m2*=i;
			m2=m2%(10*10*10*10*10*10*10*10*10+7);
		}
		m3=(2*m2*m2)%(10*10*10*10*10*10*10*10*10+7);
		printf("%lld\n",m3);
	} else if(n-m==1||m-n==1){
		for(i=m;i>=2;i--){
			m*=(i-1);
			m=m%(10*10*10*10*10*10*10*10*10+7);
		}
		for(i=n;i>=2;i--){
			n*=(i-1);
			n=n%(10*10*10*10*10*10*10*10*10+7);
		}
		ans=(n*m)%(10*10*10*10*10*10*10*10*10+7);
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 128