akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int D = sc.nextInt();
		int x2000 = sc.nextInt();
		int next = x2000;

		for (int i = 1; i <= 10; i++) {
			next = r*next-D;
			System.out.println(next);
		}
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    int n;
    cin >> n;
    string s[n];
    rep(i, n) cin >> s[i];
    int c[4] = {};
    rep(i, n) {
        if(s[i] == "AC") c[0]++;
        if(s[i] == "WA") c[1]++;
        if(s[i] == "TLE") c[2]++;
        if(s[i] == "RE") c[3]++;
    }
    cout << "AC x " << c[0] << endl;
    cout << "WA x " << c[1] << endl;
    cout << "TLE x " << c[2] << endl;
    cout << "RE x " << c[3] << endl;
    return 0;
}

Measured memory_bytes: 6780
import math

r = 999999
sqrt = int(math.sqrt(r))
p = [1 for i in range(r)]
p[0] = 0
for i in range(1,sqrt):
    if p[i]:
        for j in range(2*(i+1)-1,r,i+1):
            p[j] = 0

while True:
    try:
        n = int(raw_input())
        print sum(p[:n])
    except:
        break

Measured memory_bytes: 43964
n = int(input())
s = input()
dp = [[0] * 7 for i in range(4001)]

for i in range(n):
    if s[i] == 'R':
        dp[i + 1][0] = dp[i][0] + 1
        dp[i + 1][1] = dp[i][1]
        dp[i + 1][2] = dp[i][2]
        dp[i + 1][3] = dp[i][1] + dp[i][3]
        dp[i + 1][4] = dp[i][4]
        dp[i + 1][5] = dp[i][2] + dp[i][5]
        dp[i + 1][6] = dp[i][6] + dp[i][4]
    elif s[i] == 'G':
        dp[i + 1][0] = dp[i][0]
        dp[i + 1][1] = dp[i][1] + 1
        dp[i + 1][2] = dp[i][2]
        dp[i + 1][3] = dp[i][0] + dp[i][3]
        dp[i + 1][4] = dp[i][2] + dp[i][4]
        dp[i + 1][5] = dp[i][5]
        dp[i + 1][6] = dp[i][6] + dp[i][5]
    else:
        dp[i + 1][0] = dp[i][0]
        dp[i + 1][1] = dp[i][1]
        dp[i + 1][2] = dp[i][2] + 1
        dp[i + 1][3] = dp[i][3]
        dp[i + 1][4] = dp[i][1] + dp[i][4]
        dp[i + 1][5] = dp[i][0] + dp[i][5]
        dp[i + 1][6] = dp[i][6] + dp[i][3]
    for j in range(1, i // 2 + 1):
        if s[i] != s[i - j] and s[i] != s[i - j * 2] and s[i - j] != s[i - 2 * j]:
            dp[i + 1][6] -= 1
print(dp[n][6])

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

int main(){

  int x1, x2, x3, x4, x5;
  cin >>x1 >> x2>> x3 >> x4>>x5;
  int ans = 0;

  if(x1 == 0) ans = 1;
  if(x2 == 0) ans = 2;
  if(x3 == 0) ans = 3;
  if(x4 == 0) ans = 4;
  if(x5 == 0) ans = 5;
  cout << ans << endl;
  return 0;
  

}


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


int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	
	ll a,b,ans;
	cin>>a>>b;
	ans=max(a+b,a-b);
	ans=max(ans, a*b);

	cout<<ans;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define max 1000000007
using namespace std ;
int main (){
long long int n ; cin >> n ;
	int a[n];
 long long int suff[n];
	for(int i = 0;i<n;i++){
		cin >> a[i];
	}
		for(long long int j = n -1, sufff = 0;j>=0;j--){
			sufff = (sufff+ a[j]) % max;
		suff[j] = sufff;
	}
	long long int sum = 0;
		for( int j = 0;j<n-1;j++){
	  sum = (sum + (a[j]*suff[j+1]) % max) % max;
	}
	cout <<  sum << endl;
}


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

int main(){
    ll  n ;
    cin >> n ;
    vector<ll> A(n) ;
    rep(i,n) cin >> A.at(i) ;
    ll ans = 0 ; 
    rep(i,n){
      if(A.at(i)%2 == 1 && (i+1)%2 == 1 )ans++ ;
    }
    cout << ans << endl ;
}


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

int main(){
  int n,c,k;
  cin >> n >> c >> k;
  vector<int> t(n);
  rep(i,n) cin >> t[i];
  sort(all(t));
  queue<int> q;
  rep(i,n) q.push(t[i]);
  int ans = 0;
  int bus = 0;
  int time = 0;
  while(!q.empty()){
    int now = q.front();
    q.pop();
    //cout << now << ",";
    if(bus == 0 || now > time+k){
      //cout << "new" << endl;
      bus = 1;
      ans ++;
      time = now;
    }else{
      if(bus < c){
        //cout << "ride" << endl;
        bus ++;
      }else{
        //cout << "over" << endl;
        ans ++;
        bus = 1;
        time = now;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4116
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

struct node{
    int city;
    int pref;
    long year;
    string code;
};

bool comp_year(const node& l, const node& r){
    if(l.pref == r.pref){
        return l.year < r.year;
    } else {
        return l.pref < r.pref;
    }
}

bool comp_city(const node& l, const node& r){
    return l.city < r.city;
}

string padding(int a){
    string str = to_string(a);
    if(str.size() != 6){
        while(true){
            str = "0" + str;
            if(str.size() == 6){
                break;
            }
        }
    }
    return str;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector< node > v;
    int p;
    long y;
    int prefs[n+1];
    for(int i = 1; i <= n; i++){
        prefs[i] = 0;
    }
    for(int i = 1; i <= m; i++){
        cin >> p >> y;
        node d = {i, p, y, ""};
        v.push_back(d);
    }
    sort(v.begin(), v.end(), comp_year);
    for(int i = 0; i < v.size(); i++){
        int city = v[i].city;
        int p = v[i].pref;
        prefs[p]++;
        v[i].code = padding(p) + padding(prefs[p]);
    }
    sort(v.begin(), v.end(), comp_city);
    for(int i = 0; i < v.size(); i++){
        cout << v[i].code << endl;
    }
    return 0;
}


Measured memory_bytes: 9968
#include <bits/stdc++.h>
using namespace std;
int main(){
 int n, y;
 cin >> n >> y;
 for(int i = 0; i <= n; i++){
   for(int j = 0; j <= n - i; j++){
     if(10000 * i + 5000 * j + 1000 * ( n - i - j) == y){cout << i << " " << j << " " << n - i - j << endl; return 0;}
   }
 }
 cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N,width;
int ruisekiwa[1001],memo[1001];
int case_num = 1;

int recursive(int index){

	if(memo[index] != -1)return memo[index];


	int calc_right = N;

	int minimum = BIG_NUM;

	for(int i = index; i <= calc_right; i++){
		if(i < N){
			minimum = min(minimum,abs((ruisekiwa[i]-ruisekiwa[index-1])-width)+recursive(i+1));
		}else{
			minimum = min(minimum,max(0,(ruisekiwa[i]-ruisekiwa[index-1])-width));
		}
	}

	return memo[index] = minimum;
}

void func(){

	ruisekiwa[0] = 0;
	for(int i = 1; i <= N; i++){
		scanf("%d",&ruisekiwa[i]);
		ruisekiwa[i] += ruisekiwa[i-1];
	}

	for(int i = 1; i <= N; i++)memo[i] = -1;

	printf("Case %d: %d\n",case_num++,recursive(1));
}

int main(){

	while(true){
		scanf("%d %d",&N,&width);
		if(N == 0 && width == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 3252
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <cstring>
#include <list>  
#include <cassert>
#include <climits>
#include <bitset>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;  
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=10000000;
const int MOD=998244353;
void inc(int &a,int b) { if((a+=b)>=MOD) a-=MOD; }

int n,xa,xb;

int inv[MAXN+1];
int fac[MAXN+1];
int ifac[MAXN+1];
int choose(int n,int k) { if(k<0||k>n) return 0; return (ll)fac[n]*ifac[k]%MOD*ifac[n-k]%MOD; }

int calc(int a,int b) { // number of ways to reorder a times +1 and b times -1 so that result never becomes less than or equal to zero after initial state
	assert(a>=0&&b>=0);
	if(a==0&&b==0) return 1;
	if(b>=a) return 0;
	return (ll)choose(a+b,a)*(a-b)%MOD*inv[a+b]%MOD;
}

int solve() {
	inv[1]=1; FORE(i,2,n) inv[i]=(ll)(MOD-MOD/i)*inv[MOD%i]%MOD;
	fac[0]=1; FORE(i,1,n) fac[i]=(ll)fac[i-1]*i%MOD;
	ifac[0]=1; FORE(i,1,n) ifac[i]=(ll)ifac[i-1]*inv[i]%MOD;
	
	// 1: (u,v)->(u+1,v+1), 2: (u,v)->(u,v-1) only if v>=2, 3: (u,v)->(u,0), start state=(0,0), final state=(xb,xb-xa)
	int n1=xb;
	int ret=0;
	REPE(n2,xa) {
		if(n1+n2>n) continue;
		int n3=n-n1-n2;
		// v starts at 0 and ends at n1-n2, we can only perform 3 the last time it has a certain value v and v<=(n1-n2)-(xb-xa)=xa-n2
		int opt3=xa-n2+1;
		int r3=n3; if(n2!=xa) { if(r3==0) continue; else --r3; }
		int cur=(ll)calc(n1,n2)*choose(r3+opt3-1,r3)%MOD;
		inc(ret,cur);
	}
	return ret;
}

void run() {
	scanf("%d%d%d",&n,&xa,&xb);
	printf("%d\n",solve());	
}

int main() {
	run();
	return 0;
}


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

int main()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
    int n;
    cin >> n;
    set <string> mySet;
    for(int i=0 ; i<n ; i++)
    {
        string s;
        cin >> s;
        mySet.insert(s);
    }
    cout << mySet.size();

    return 0;
}


Measured memory_bytes: 15644
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + end + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var output = new Array(N);
  for(var i = 0; i < N; i++){
    output[list[i] - 1] = i + 1;
  }
  myout(myconv(output, 8));
}

Measured memory_bytes: 46128
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
typedef long long int lli;

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

    lli ub = min(n, k);
    lli ans = 0;
    vector<lli> jewels;
    for(lli a = 0; a <= ub; ++a){
        lli sum = 0;
        for(lli b = 0; b <= ub - a; ++b){
            sum = 0;
            for(lli i = 0; i < a; ++i){
                jewels.push_back(value_vec[i]);
                sum += value_vec[i];
            }

            for(lli j = value_vec.size() - 1; j > value_vec.size() - 1 - b; --j){                
                jewels.push_back(value_vec[j]);
                sum += value_vec[j];
            }

            if(jewels.size() > 0){
                sort(jewels.begin(), jewels.end());
                /*cout << "-------------------\n";
                cout << "jewels = [";
                for(lli i = 0; i < jewels.size(); ++i){
                    cout << " " << jewels[i];
                }
                cout << " ]";*/
            }

            lli num_thrown = 0;
            for(lli i = 0; i < jewels.size(); ++i){
                if(num_thrown == k - (a + b)){
                    break;
                }

                if(jewels[i] >= 0){
                    break;
                }

                sum -= jewels[i];
                num_thrown++;
            }

            //cout << ", sum = " << sum;

            ans = max(sum, ans);
            //cout << ", ans = " << ans << endl;
            jewels.erase(jewels.begin(), jewels.end());
        }
    }

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

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),m=sc.nextInt();
        int[] l = new int[m];
        int[] r = new int[m];
        for(int i = 0;i<m;i++){
            l[i]=sc.nextInt();
            r[i]=sc.nextInt();
        }
        Arrays.sort(l);
        Arrays.sort(r);
        int count = 0;
        for(int i = 1;i<=n;i++){
            if(l[m-1]<=i&&r[0]>=i)count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 61640
#include <iostream>

using namespace std;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int x = 0;
  int mx = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') {
      x++;
      if (mx < x) {
        mx = x;
      }
    } else if (s[i] == 'D') {
      x--;
    }
  }
  cout<<mx<<endl;
  return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    double l; cin >> l;
    double x=(l*l*l/(double)27);
    cout << fixed << setprecision(10) << x << endl;
}


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

#define MAX_W 100
#define MAX_H 100

char room[MAX_W][MAX_H];
int W,H;

const int direc[4][2] = {
    {0, -1},
    {1, 0},
    {0, 1},
    {-1, 0},
};

void dfs(const int& row, const int& col, const char c);

int main() {
    while(cin>>H>>W, W > 0) {
        int step = 0;
        int col, row;
        for (row = 0; row < H; ++row) {
            for (col = 0; col < W; ++col) {
                cin >> room[row][col];
            }
        }
        for (row = 0; row < H; ++ row) {
            for(col = 0; col < W; ++ col) {
                if(room[row][col] != '!') {
                    dfs(row, col, room[row][col]);
                    ++ step;
                }
            }
        }
        cout<<step<<endl;
    }
    return 0;
}

void dfs(const int& row, const int& col, const char c) {
    room[row][col] = '!';
    for(int d = 0; d < 4; ++ d) {
        int curRow = row + direc[d][1];
        int curCol = col + direc[d][0];
        if(curRow >= 0 && curRow < H && curCol >= 0 && curCol < W && room[curRow][curCol] == c) {
            dfs(curRow, curCol, c);
        }
    }
}

Measured memory_bytes: 1788
#include <stdio.h>
int main(void){
    int N;
    scanf("%d",&N);
    int m = N/1000;
    if(N%1000 == 0){m = 1000*m;}
    else m = 1000*(m+1);
    int ans = m - N;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 1684
A, B = (int(x) for x in input().split())
c = A + B
d = A - B
e = A * B

if c <= d:
    if d <= e:
        print(e)
    if d > e:
        print(d)

if c > d:
    if c >= e:
        print(c)
    if c < e:
        print(e)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int k = sc.nextInt();
    List<Integer> list = new ArrayList<>();
    int count = 0;

    for(int i = 0; i < n ; i++){
        list.add(sc.nextInt());
    }

    for(int i = 0; i < n ; i++){
        if(list.get(i) >= k){
            count++;
        }
    }

    System.out.println(count);
    


    
    


    


    
    


    
	}
}

Measured memory_bytes: 59636
A, B, C = map(int,input().split())
K = int(input())

ans = 0
X = [0]*3 #X[0]:red X[1]:green X[2]:blue
for i in range(K + 1):
    for j in range(K + 1 - i):
        X[0] = A*2**i
        X[1] = B*2**j
        X[2] = C*2**(K - i - j)
        if X[1] > X[0] and X[2] > X[1]:
            ans = 1
print("Yes" if ans == 1 else "No")


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

using namespace std;
#define ll long long int
//ll s,n,a[100005];

int main()
{
   ll n;
   cin>>n;
   pair<ll,ll>a[n];
   for(ll i=0;i<n;i++)
   {
       cin>>a[i].first;
       a[i].second=i;
   }
   sort(a,a+n);
   for(ll i=0;i<n;i++)
   cout<<a[i].second+1<<" ";
 
}

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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 100010;

signed main() {
    IOS;

    string N;
    cin >> N;
    int sum = 0;
    REP(i, N.length()) {
        int num = N[i] - '0';
        sum += num;
    }
    Yes(sum % 9 == 0);

    return 0;
}


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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<62)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N, M, a;
  cin >> N >> M;
  rep (i, M) cin >> a;
  cout << N - M - 1 << endl;
  return 0; 
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m,x,y;
    cin >> n >> m >> x >> y;
    intl a[n],b[m];
    cin(i,a);
    cin(j,b);
    sort(a,a + n,greater<>());
    sort(b,b + m);
    fp(max(x,a[0]) >= min(y,b[0]),"War","No War");
    return 0;
}

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

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)         for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n)       for(int i=(int)m; i<(int)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define mpair(v1, v2)    make_pair(v1, v2);
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(var)      rep(i,var.size()){cout << var[i] << " ";} cout << "\n"

//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  arr(a,n);

  vec num(n+1);
  num[0]=0;
  rep(i,n){
    num[a[i]]++;
  }

  vecll pat(n+1);
  ll ans=0;
  rep(i,n+1){
    pat[i]=(ll) num[i]*(num[i]-1)/2;
    ans+=pat[i];
  }
  rep(i,n){
    prt(ans-num[a[i]]+1);
  }


}


Measured memory_bytes: 5760
import sys
import math


N_MAX = 200000 + 5
INF = 10**9 + 7
sys.setrecursionlimit(N_MAX)
MOD = 10**9 + 7


def main():
    N = int(sys.stdin.readline().rstrip())
    A = [int(x) for x in sys.stdin.readline().rstrip().split()]

    maxA = max(A)

    # 1 <= a <= maxA までの、要素の登場回数
    C = [0] * (maxA + 1)
    for a in A:
        C[a] += 1

    pc = True

    # p の倍数である個数をカウントする
    for p in range(2, maxA + 1):
        cnt = 0
        for k in range(maxA // p + 1):
            cnt += C[k * p]

        # k*p となるような要素が2個以上あったら、pairwise coprime ではない
        if cnt > 1:
            pc = False

    if pc:
        print("pairwise coprime")
        return

    GCD = A[0]
    for i in range(1, N):
        GCD = math.gcd(GCD, A[i])

    if GCD == 1:
        print("setwise coprime")
        return

    print("not coprime")


main()


Measured memory_bytes: 134560
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll ;
typedef double db;
const double pi = 3.141592654;
#define pb         push_back
#define forab(i,a,b)       for(int i=(a);i<=(b);i++)
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define pcase(z,x)     printf("Case %ld: %lld\n",z,x)
#define nw	 "\n"
#define mod 1000000007

ll w,e;
int main(void)
{
	CIN;
	ll tc,l,k=0,sum=0,x=0,y,z=0,m=1,n=0,ans=0,cnt=0;
	cin>>n;
	ans=1;
	for(ll i=2;i<n;i++)
		for(ll j=i*i;j<=n;j*=i)
			ans=max(j,ans);
	cout<<ans;
}

Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  int n, d[60], sum = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> d[i];
  for (int i = 0; i < n - 1; ++i)
  {
    for (int j = i + 1; j < n; ++j)
    {
      sum += d[i] * d[j];
    }
  }
  cout << sum;
}


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

int main(){
  string s; cin >> s;
  string m = "";
  for(ll i=0; i<s.size(); ++i){
    if(s[i] == '/'){
      for(ll j=1; s[i+j] != '/'; ++j){
        m += s[i+j];
      }
      break;
    }
  }
  string res = "Heisei";
  if(stoll(m) >= 5) res = "TBD";
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main() {
	int i, j, k, f = 0, n;
	double x, y, t;
	t = 0;
	char u[5];
	scanf( "%d", &n);
	for (i = 0;i < n;i++) {
		scanf("%lf %s", &x, u);
		if (u[0] == 'J') {
			t = t + x;
		}
		else {
			y = x * 380000.0;
			t = t + y;
		}
	}
	printf("%lf", t);
	return 0;
}

Measured memory_bytes: 128
while True:
    count=0
    n, x = map(int, input().split())
    if n==0 and x==0:
        break
    for i in range(1, n+1):
        for j in range(1, i):
            for k in range(1, j):
                if i+j+k==x:
                    count+=1
    print(count)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
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 long double EPS = 1e-11;

#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--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
    init();
    vc<ll> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
    ll H, W;
    cin >> H >> W;
    vc<string> G(H);
    rep(i, H) cin >> G[i];
    vvc<ll> ok(H, vc<ll>(W, INF));
    ll ans = 0;
    queue<pair<ll, ll>> q;
    rep(i, H) rep(j, W) {
        if (G[i][j] == '#') continue;
        vvc<ll> dist;
        dist = ok;
        dist[i][j] = 0;
        q.emplace(i, j);

        while (!q.empty()) {
            ll h, w;
            tie(h, w) = q.front();
            q.pop();
            rep(d, 4) {
                ll hh = h + dx[d], ww = w + dy[d];
                if (hh < 0 || hh > H - 1 || ww < 0 || ww > W - 1) continue;
                if (G[hh][ww] == '#') continue;
                if (dist[hh][ww] > dist[h][w] + 1) {
                    dist[hh][ww] = dist[h][w] + 1;
                    q.emplace(hh, ww);
                }
            }

            ll tmp = 0;
            rep(s, H) rep(t, W) if (dist[s][t] != INF) tmp = max(tmp, dist[s][t]);
            ans = max(ans, tmp);
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)

const int inf = 1001001000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    int n;
    cin >> n;
    char c;
    while(n--){ 
        cin >> c; 
        if(c == 'Y'){ 
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}




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

int main(){
	int s, a, b;
	string ans;

    cin >> s;
	

	a = s/100;
	b = s - a*100;

	if (a == 0 && b == 0)
	{
		ans = "NA";
	}
	else if (a == 0 && b > 12){
		ans = "NA";
	}
	else if (b == 0 && a > 12){
		ans = "NA";
	}
	else if (a > 12 && b > 12){
		ans = "NA";
	}
	else if (a > 12 || a == 0){
		ans = "YYMM";
	}
	else if (b > 12 || b == 0){
		ans = "MMYY";
	}
	else {
		ans = "AMBIGUOUS";
	}


	// cout << s << endl;
	// cout << a << endl;
	// cout << b << endl;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define REP(i, n) for(int i = 0;i < n;i++)
const long long INF = 1LL << 60;

int MOD = 1000000007;



int main(){
    std::ios_base::sync_with_stdio(false);

    int n,k; cin >> n >> k;

    std::vector<pair<int, int>> sushi;
    std::vector<bool> used(101010, false);

    REP(i,n){
        int t; int d; cin >> t >> d;
        sushi.push_back(make_pair(d, t));
    }


    ll base = 0LL, cnt = 0LL;
    sort(sushi.begin(), sushi.end());
    reverse(sushi.begin(), sushi.end());


    priority_queue<int, vector<int>, greater<int>> que;
    REP(i, k){
        base += sushi[i].first;

        if(!used[sushi[i].second]){
            used[sushi[i].second] = true;
            cnt++;
        }
        else que.push(sushi[i].first);
    }

    ll ans = base + cnt*cnt;

    for(int i=k;i<n;++i){
        if(cnt>=k) break;
        if(used[sushi[i].second]) continue;

        used[sushi[i].second] = true;
        cnt++;
        int m = que.top(); que.pop();
        base -= m;
        base += sushi[i].first;

        ans = max(ans, base+cnt*cnt);
    }

    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 1524
class Dice:
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def toN(self):
        tmp = self.top
        self.top = self.south
        self.south = self.bottom
        self.bottom = self.north
        self.north = tmp

    def toE(self):
        tmp = self.top
        self.top = self.west
        self.west = self.bottom
        self.bottom = self.east
        self.east = tmp

    def toS(self):
        tmp = self.top
        self.top = self.north
        self.north = self.bottom
        self.bottom = self.south
        self.south = tmp

    def toW(self):
        tmp = self.top
        self.top = self.east
        self.east = self.bottom
        self.bottom = self.west
        self.west = tmp

    def printTop(self):
        print(self.top)

    def printWest(self):
        print(self.west)

    def printEast(self):
        print(self.east)

    def getTop(self, target):
        if self.top == target:
            return
        for i in range(3):
            self.toN()
            if self.top == target:
                return
        for i in range(3):
            self.toE()
            if self.top == target:
                return

        if self.top != target:
            print("Error")

    def getSouth(self, target):
        if self.south == target:
            return
        for i in range(3):
            self.lotate()
            if self.south == target:
                return
    
    def lotate(self):
        tmp = self.north
        self.north = self.east
        self.east = self.south
        self.south = self.west
        self.west = tmp

    def isSame(self, other):
        if self.top == other.top and \
           self.north == other.north and \
           self.east == other.east and \
           self.south == other.south and \
           self.west == other.west and \
           self.bottom == other.bottom:
            return True
        else:
            return False

    def compare(self, other):
        for i in range(4):
            for j in range(4):
                if self.isSame(other) == True:
                    return True
                self.lotate()
            self.toN()

        for i in range(4):
            for j in range(4):
                if self.isSame(other) == True:
                    return True
                self.lotate()
            self.toE()
        return False

n = int(input())
dice = []
for i in range(n):
    buf = input().split()
    a = int(buf[0])
    b = int(buf[1])
    c = int(buf[2])
    d = int(buf[3])
    e = int(buf[4])
    f = int(buf[5])
    dice.append(Dice(a, b, c, d, e, f))

same = False
for i in range(n-1):
    for j in range(i+1, n):
        if dice[i].compare(dice[j]) == True:
            print("No")
            same = True
            break
    if same == True:
        break

if same == False:
    print("Yes")
            




Measured memory_bytes: 5624
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;

int main(int argc, char *argv[])
{
    int N;
    std::cin >> N;

    std::vector<int> T(N);
    for (int i = 0; i < N; i++) {
        std::cin >> T[i];
    }

    int M;
    std::cin >> M;

    std::vector<int> P(M), X(M);
    for (int i = 0; i < M; i++) {
        std::cin >> P[i] >> X[i];
    }

    //std::vector<int> ans;
    int sum = 0;
    for (int i = 0; i < N; i++) {
        sum += T[i];
    }

    for (int i = 0; i < M; i++) {
        int temp = sum;
        temp -= T[P[i] - 1];
        temp += X[i];
        //ans.push_back(temp);
        std::cout << temp << std::endl;
    }

    /*
    for (int i = 0; i < M; i++) {
        std::cout << ans[i] << std::endl;
    }
    */
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int cnt = 0;
  REP(i, a+1) {
    REP(j, b+1) {
      REP(k, c+1) {
	if (500*i+100*j+50*k == x) {
	  cnt++;
	}
      }
    }
  }
  dump(cnt);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 2000010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

void init() {
    fact[0] = invfact[0] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        fact[i] = (i*fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;

    init();
    
    ll ans = 0;
    exrep(i, r1, r2) {
        ans += (Comb(i+c2+1, i+1) + mod - Comb(i+c1, i+1))%mod;
        ans %= mod;
    }
    
    out(ans);
    re0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    int ans = 10000;

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

    for(int i = 1; i < n; i++) {
      int sum1 = 0;
      int sum2 = 0;

      for(int j = 0; j < i; j++) {
        sum1 += a[j];
      }
      for(int k = i; k < n; k++) {
        sum2 += a[k];
      }
      ans = min(ans, abs(sum1 - sum2));
    }

    cout << ans;
}

Measured memory_bytes: 256
mod = 10**9+7

N, K = map(int, input().split())
A = list(map(int, input().split()))

A.sort(reverse=True)

ans = 1
left = 0
right = len(A)-1

# 全部負のとき
if A[0] < 0 and K % 2 == 1:
    for i in range(K):
        ans = (ans * A[i]) % mod
elif K % 2 == 0:
    while K > 0:
        r = A[right] * A[right-1]
        l = A[left] * A[left + 1]
        if l > r:
            ans = (ans * l) % mod
            left += 2
        else:
            ans = (ans * r) % mod
            right -= 2
        K -= 2
else:
    p = A.pop(0)
    K -= 1
    right -= 1
    while K > 0:
        r = A[right] * A[right-1]
        l = A[left] * A[left + 1]
        if l > r:
            ans = (ans * l) % mod
            left += 2
        else:
            ans = (ans * r) % mod
            right -= 2
        K -= 2
    ans = (ans * p) % mod
while ans < 0:
    ans = ans + mod

print(ans)


Measured memory_bytes: 93892
/*---------------Go Code GO---------------*/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using Order_Set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define     PI              acos(-1.0)
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define     precision(a)    fixed<<setprecision(a)
#define     endl            '\n'
#define     Flush           cout<<flush
#define     LLMX            0x3fffffffffffffff




int main()
{
    long long i,j,k,l,tst=0,ans=0, csno=0;
    char c;
    cin>>c;
    c++;
    cout<<c<<endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int N=505;
int s[N],t[N];
bool visr[N],visc[N];
ull a[N][N],u[N],v[N],b[N],c[N];
int n;
int main()
{
    ull one=1;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&s[i]);
    for(int i=1;i<=n;i++) scanf("%d",&t[i]);
    for(int i=1;i<=n;i++) scanf("%llu",&u[i]);
    for(int i=1;i<=n;i++) scanf("%llu",&v[i]);
    for(ull k=0;k<64;k++)
    {
        memset(visr,false,sizeof(visr));
        memset(visc,false,sizeof(visc));
        vector<int>r,c;
        for(int i=1;i<=n;i++)
        {
            if(s[i]==0) r.push_back(i);
            if(t[i]==0) c.push_back(i);
        }
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
        {
            if(s[i]==0&&(u[i]>>k&1)||t[j]==0&&(v[j]>>k&1)||s[i]==1&&(u[i]>>k&1)&&t[j]==1&&(v[j]>>k&1)&&!(visr[i]&&visc[j]))
                a[i][j]|=one<<k,visr[i]=visc[j]=true;
        }
        bool f1=false,f2=false;
        int p1=0,p2=0;
        for(int i=1;i<=n;i++)
            if((u[i]>>k&1)&&s[i]==1&&!visr[i])
        {
            f1=true;
            a[i][c[p2]]|=one<<k;
            p2++;if(p2==c.size()) p2=0;
        }
        for(int i=1;i<=n;i++)
            if((v[i]>>k&1)&&t[i]==1&&!visc[i])
        {
            f2=true;
            a[r[p1]][i]|=one<<k;
            p1++;if(p1==r.size()) p1=0;
        }
        assert(!(f1&&f2));
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
    {
        if(s[i]) b[i]|=a[i][j];
        else b[i]&=a[i][j];
        if(t[j]) c[j]|=a[i][j];
        else c[j]&=a[i][j];
        if(j==1) b[i]=a[i][j];
        if(i==1) c[j]=a[i][j];
    }
    for(int i=1;i<=n;i++)
        if(u[i]!=b[i]||v[i]!=c[i])
    {
        printf("-1\n");return 0;
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        printf(j==n?"%llu\n":"%llu ",a[i][j]);
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
using ll = long long;
using ull = unsigned long long;

int main() {
  int n; cin >> n;
  vector<int> v(n);
  int sum = 0;
  bool imp = true;
  rep(i, n) {
    cin >> v[i];
    if (v[i] % 10 != 0) imp = false;
    sum += v[i];
  }
  if (imp) cout << 0;
  else if (sum % 10 != 0) cout << sum;
  else {
    sort(v.begin(), v.end());
    rep(i, n) {
      if (v[i] % 10 != 0) {
        cout << sum - v[i];
        return 0;
      }
    }
  }
}


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

using Comp = complex<double>;
using ll = long long;
const double PI = acos(-1.0);
const Comp I(0,1);

void fft(int n,vector<Comp> &a,bool inv=false){
    double zeta=(inv?-1:1)*2*PI/n;
    for(int m=n;m>=2;m>>=1){
        int mh=m>>1;
        rep(i,mh){
            Comp w=exp((double)i*zeta*I);
            for(int j=i;j<n;j+=m){
                int k=j+mh;
                Comp x=a[j]-a[k];
                a[j]+=a[k];
                a[k]=w*x;
            }
        }
        zeta*=2;
    }
    int i=0;
    rng(j,1,n-1){
        for(int k=n>>1;k>(i^=k);k>>=1);
        if(j<i) swap(a[i],a[j]);
    }
    if(inv) rep(i,n) a[i]/=n;
}
void conv(vector<Comp> &v,vector<Comp> &w){
    int n=1,deg=v.size()+w.size()-1;
    while(n<deg) n<<=1;
    v.resize(n),w.resize(n);
    fft(n,v);fft(n,w);
    rep(i,n) v[i]*=w[i];
    fft(n,v,true);
}

int main(){
    ll n, m;
    cin >> n >> m;
    vector<Comp> a(200200,0),b(200200,0);
    rep(i,n) {
        int v; cin >> v;
        a[v] += 1; b[v] += 1;
    }
    conv(a,b);
    ll ans = 0, ind = 200000;
    while (m > 0) {
        ll num = min(m, (ll)(a[ind].real()+0.5));
        ans += ind * num;
        m -= num;
        ind--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 19780
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main(){
	ll n,k,tmp;
  	cin>>n>>k;
  	vector<ll> v;
  	for(int i=0;i<n;i++){
    	cin>>tmp;
      	v.pb(tmp);
    }
    v.pb(0);
  	vector<ll> dp(n+1);
  	dp[n-1]=0;
  	for(int i=n-2;i>=0;i--){
        dp[i]=INT_MAX;
    	for(int j=i+1;j<min(n,i+k+1);j++){
        	int sum = abs(v[i]-v[j]);
          	dp[i]=min(dp[i],dp[j]+sum);
        }
    }
  	cout<<dp[0]<<endl;
  	return 0;
}


Measured memory_bytes: 4844
#include <iostream>
#include <vector>
using namespace std;
const long long nin = 1e9 + 7;

int main()
{
	int n, k;
	cin >> n >> k;
	long long a[n + 1], ans[k + 1];
	vector <long long> sum (k + 1, 1);
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	
	sum[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= k; j++)
			if (j > a[i]) 
			{
				ans[j] = (sum[j] - sum[j - a[i] - 1]) % nin;
				if (ans[j] < 0) ans[j] += nin;
			}
			else ans[j] = sum[j];
		
		for (int j = 1; j <= k; j++)
			sum[j] = (sum[j - 1] + ans[j]) % nin;
	}
	
	cout << ans[k];
}

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

const int N = 305;
const long long mod = 1000000007ll;

template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}

template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

int n, m = 0, a[N << 1], mark[N << 1];
long long f[N << 1][N][N], ans;

int main () {
	read(n);
	for (int i = 1; i <= (n << 1); i++) read(a[i]);

	for (int i = 1; i <= (n << 1); i++) mark[i] = 2;
	for (int i = 1; i <= n; i++) {
		if (~a[2 * i] && ~a[2 * i - 1]) mark[a[2 * i]] = mark[a[2 * i - 1]] = 0;
		else if (~a[2 * i]) mark[a[2 * i]] = 1;
		else if (~a[2 * i - 1]) mark[a[2 * i - 1]] = 1;
		else m++;
	}

	for (int i = 0; i <= n + 1; i++) {
		for (int j = 0; j <= n + 1; j++) f[n << 1 | 1][i][j] = 0ll;
	}
	f[n << 1 | 1][0][0] = 1ll;
	for (int i = n << 1; i; i--) {
		for (int j = 0; j <= n + 1; j++) {
			for (int k = 0; k <= n + 1; k++) {
				f[i][j][k] = 0ll;
				if (j > n || k > n) continue;
				if (!mark[i]) f[i][j][k] = f[i + 1][j][k];
				else if (mark[i] == 1) {
					if (j) f[i][j][k] = (f[i][j][k] + f[i + 1][j - 1][k]) % mod;
					f[i][j][k] = (f[i][j][k] + f[i + 1][j][k + 1]) % mod;
				}
				else {
					if (k) f[i][j][k] = (f[i][j][k] + f[i + 1][j][k - 1]) % mod;
					f[i][j][k] = (f[i][j][k] + f[i + 1][j + 1][k] * (j + 1)) % mod;
					f[i][j][k] = (f[i][j][k] + f[i + 1][j][k + 1]) % mod;
				}
			}
		}
	}

	ans = f[1][0][0];
	for (int i = 1; i <= m; i++) ans = ans * i % mod;
	write(ans), putchar('\n');
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)

#define GU 0
#define PA 1

signed main()
{
    string s; cin >> s;
    int l = s.size();

    int myCard = GU;
    int ans = 0;
    rep(i,l){
        char c = s[i];
        if (c == 'g'){
            if (myCard == PA) ++ans;
        } else {
            if (myCard == GU) --ans;
        }
        if (myCard == GU) myCard = PA;
        else myCard = GU;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  ll x,k,d;
  cin >> x >> k>> d;
  ll res;
  ll r;
  if(abs(x)/d >= k){
    res = abs(x) -k*d;
  }else{
    r = abs(x)/d;
    x = abs(x);
    if(x%d == 0){
      r = r;
    }else{
      r = r+1;
    }
    if((k-r)%2 == 0){
      //cout << "a";
      res = abs(x-d*r);
    }else{
      //cout << "b";
      res = d - abs(x-d*r);
    }
    
  }
  
  cout << res;
}

Measured memory_bytes: 3624