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

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long n = sc.nextLong();

		long max = Long.MIN_VALUE;
		long x = n;

		if(x/b==0||x%b == b-1) {
			System.out.println((a*x)/b - a *(x/b));
			sc.close();
			return;
		}

		if(x%b != b-1) {
			x = x - ((x%b)+1);
			System.out.println((a*x)/b - a *(x/b));
			sc.close();
			return;
		}

		sc.close();
	}


}

Measured memory_bytes: 35688
using System;
using System.Linq;
using System.Collections;
namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var count = parseIntList(Console.ReadLine().TrimEnd())[0];
            ArrayList fruits = new ArrayList();
            while(count>0){
                fruits.Add(Console.ReadLine().TrimEnd());
                count--;
            }
            Console.WriteLine(fruits.ToArray().Select(x=>x).Distinct().Count());
            Console.ReadLine();
        }
        static int[] parseIntList(string obj){
            return (int[])obj.Split(" ").Select(x=> int.Parse(x)).ToArray();
        }

    }
}


Measured memory_bytes: 44200
const BKRT = "\n";
const SPAC = " ";
const NOSP = "";

function Main(input){
	input = [].concat(...input.split(BKRT).map(a=>a.split(SPAC)));
  const strShift = ()=>input.shift();
  const intShift = ()=>~~input.shift();
  
  return ~~(intShift()-intShift())%intShift();
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
1234
150
100
`);

Measured memory_bytes: 7372
#include<iostream>
#define MAX 100
#define MINVAL (1LL<<32)
using namespace std;
typedef long long llong;

int V,E;
llong M[MAX+1][MAX+1];

void deal(){
    for(int k=0;k<V;k++){
        for(int i=0;i<V;i++){
            if(M[i][k]==MINVAL) continue;
            for(int j=0;j<V;j++){
                if(M[k][j]==MINVAL) continue;
                M[i][j]=min(M[i][j],M[i][k]+M[k][j]);
            }
        }
    }
}

int main(){
    cin>>V>>E;
    for(int i=0;i<V;i++){
        for(int j=0;j<V;j++){
            M[i][j]= i==j?0:MINVAL;
        }
    }
    for(int i=0;i<E;i++){
        int s,t,d;
        cin>>s>>t>>d;
        M[s][t]=d;
    }

    deal();

    bool flag=false;
    for(int i=0;i<V;i++){
        if(M[i][i]<0){
            flag=true;
            break;
        }
    }
    if(flag){
        cout<<"NEGATIVE CYCLE"<<endl;
    }else{
        for (int i=0;i<V;i++){
            for(int j=0;j<V;j++){
                if(j) cout<<" ";
                if(M[i][j]==MINVAL) cout<<"INF";
                else cout<<M[i][j];
            }
            cout<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3200
fun main(args:Array<String>?): Unit {
    val prime = primes(123456 * 2)
    while(true){
        val n = readLine()!!.trim().toInt()
        if (n == 0) return
        println(upperBound(prime, n * 2) - upperBound(prime, n))
    }
}
fun primes(upper: Int): IntArray {
    val isPrime = BooleanArray(upper + 1){true}
    for (p in 2 until Math.sqrt(upper.toDouble()).toInt()){
        if (isPrime[p]) for (i in p * p .. upper step p) {
            isPrime[i] = false
        }
    }
    return (2 .. upper).filter(isPrime::get).toIntArray()
}
fun upperBound(array: IntArray, target: Int): Int {
    var left = 0
    var right = array.size
    while(left < right){
        val mid = (left + right) / 2
        if (array[mid] <= target) left = mid + 1
        else right = mid
    }
    return right
}


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

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

  int r=1e9;
  int l=-1;
  rep(i, n) {
    if (s[i]=='A') {
      l=i;
      break;
    }
  }
  rep(i, n) if (s[i]=='Z') r=i;
  if (r!=1e9&&l!=-1&&l<=r) cout<<r-l+1<<endl;
  else cout<<0<<endl;
}


Measured memory_bytes: 640
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto N = readln.split[0].to!int;
	auto A = readln.split.to!(int[]);
	
	auto Amin = A.reduce!"min(a,b)";
	auto gcd = 1;
	_gcd: foreach_reverse(d; 1 .. Amin+1) {
		foreach (a; A) { if (a%d != 0) continue _gcd; }
		gcd = d;
	}
	writeln(A.sum - N*gcd);
}

Measured memory_bytes: 380
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int n; cin >> n;
    map<int, int> odd, even;
    rep(i, n){
        int v; cin >> v;
        if(i%2) even[v]++;
        else odd[v]++;
    }

    priority_queue<pii> que_odd, que_even; //first: 出現回数 second: 数
    que_odd.push(pii(0, -1)); que_even.push(pii(0, -1));
    for (auto iter = odd.begin(); iter != odd.end(); iter++) {
        int key = iter->first, num = iter->second;
        que_odd.push(pii(num, key));
    }
    for (auto iter = even.begin(); iter != even.end(); iter++) {
        int key = iter->first, num = iter->second;
        que_even.push(pii(num, key));
    }
    int x = 0, y = 0;
    pii mxOdd = que_odd.top(); que_odd.pop();
    pii mxEven = que_even.top(); que_even.pop();
    if(mxOdd.first == mxEven.first && mxOdd.second == mxEven.second){
        int num = max(que_odd.top().first, que_even.top().first);
        x = num, y = mxOdd.first;
    } else{
        x = mxOdd.first, y = mxEven.first;
    }
    int res = (n/2 - x) + (n/2 - y);
    cout << res << ln;
}

    

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

int main() {
  int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << (h2 * 60 + m2) - (h1 * 60 + m1) - k << endl;
 
  return 0;
}


Measured memory_bytes: 3652
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val P = Array.fill(N)(sc.nextDouble())

    val dp = Array.fill(N+1, N+1)(0d)

    dp(0)(0) = 1

    var i = 0
    while (i < N) {
      var j = 0
      while (j < N) {
        dp(i+1)(j+1) += dp(i)(j) * P(i)
        dp(i+1)(j)   += dp(i)(j) * (1 - P(i))
        j += 1
      }
      i += 1
    }

    println(dp(N).zipWithIndex.filter(_._2 > N / 2).map(_._1).sum)
  }

}

Measured memory_bytes: 123040
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = (a); i <= (b); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ii> vii;

const int MX = 100005, mod = 998244353, SQ = (1 << 9);
int n, m, inv2, f[MX];
ll a[3][SQ], res[SQ];
vi adj[MX];

ll pot (ll b, int p) {
	ll res = 1;
	while (p) {
		if (p & 1) (res *= b) %= mod;
		(b *= b) %= mod;
		p /= 2;
	}
	return res;
}

void dfs (int u) {
	if (f[u] != -1) return;

	set<int> st;
	for (int v : adj[u])
		if (v > u) {
			dfs(v);
			st.insert(f[v]);
		}

	for (int i = 0;; i++)
		if (!st.count(i)) {
			f[u] = i;
			break;
		}
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	inv2 = pot(2, mod - 2);

	cin >> n;
	forn (i, 3) {
		for (int j = 1; j <= n; j++)
			adj[j].clear();

		cin >> m;
		while (m--) {
			int a, b;
			cin >> a >> b;
			adj[a].pb(b);
			adj[b].pb(a);
		}

		memset(f, -1, sizeof(f));
		for (int j = 1; j<= n; j++) {
			dfs(j);
			(a[i][f[j]] += pot(10, 18 * j)) %= mod;
		}
	}

	for (int i = 0; i < SQ; i++)
		for (int j = 0; j < SQ; j++)
			for (int k = 0; k < SQ; k++)
				(res[i ^ j ^ k] += a[0][i] * a[1][j] % mod * a[2][k]) %= mod;

	cout << res[0] << endl;

	return 0;
}

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

int main() {
    int n, a;
    cin >> n;
    int cnt_four=0, cnt_two=0;
    for(int i=0; i<n; i++) {
        cin >> a;
        if(a%4==0) cnt_four++;
        else if(a%2==0) cnt_two++;
    }

    int ans;
    if(cnt_four>0 && cnt_two==0) ans=cnt_four*2+1;
    else ans = cnt_four*2 + cnt_two;
    
    if(ans>=n) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

int Count;
int w,h;
bool area[51][51]={};
int dx[8]={0,1,1,1,0,-1,-1,-1};
int dy[8]={1,1,0,-1,-1,-1,0,1};

void bfs(int x,int y){
  int X,Y;
  queue<pair<int,int> > Q;
  Q.push(make_pair(x,y));
  area[x][y]=0;
  while(!Q.empty()){
    pair<int,int> p1=Q.front();
    X=p1.first;
    Y=p1.second;
    Q.pop();
    for(int i=0;i<8;i++){
      if((X+dx[i]<=-1||Y+dy[i]<=-1)||(X+dx[i]>=w||Y+dy[i]>=h))continue;
      if(area[X+dx[i]][Y+dy[i]]==1){
        Q.push(make_pair(X+dx[i],Y+dy[i]));
        area[X+dx[i]][Y+dy[i]]=0;
      }
    }
  } 
  return;
}

int main(){
  int I;
  while(cin>>w>>h,w){
    Count=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin>>I;
        area[j][i]=I;
      }
    }

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(area[j][i]==1){
          bfs(j,i);
          Count++;
        }
      }
    }
    cout<<Count<<endl;
  }
  return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cassert>
#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jiglypuff
#define ld long double
#define itn int
#define pir pair<int, int> 
#define all(x) (x).begin(), (x).end()
#define str string
using namespace std;

lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x1, ld y1, ld x2, ld y2)
{
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
	return (a * (a + 1LL)) / 2;
}
char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, 1, -1, -1, 1, -1, 1 };


const int N = 8080;
const lli mod = 1e9 + 7;
const ld pi = acos(-1);
const int T = 238;
const ld e = 1e-6;

lli bp(lli a, lli b = mod - 2LL)
{
	lli ret = 1;
	while (b)
	{
		if (b & 1) ret *= a, ret %= mod;
		a *= a;
		a %= mod;
		b >>= 1;
	}
	return ret;
}
ostream& operator<<(ostream& c, pir a)
{
	c << a.fr << " " << a.sc;
	return c;
}



string s, t;
int main()
{
	fastio;
	cin >> s >> t;
	t.pop_back();
	if (s == t) cout << "Yes";
	else cout << "No";
	return 0;
}


/*


  __
*(><)*
  \/ /
  ||/
--||
  ||
  /\
 /  \
/    \
*/



Measured memory_bytes: 3596
import java.math.*;
import java.util.*;

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

    double ans = (double) (L * L * L) / (3d * 3d * 3d);
    System.out.println(BigDecimal.valueOf(ans).toPlainString());
  }
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb push_back
const int INF = 1e18;
const int MOD = INF+7;

signed main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    map<int,bool> mp;
    mp[A] = true;
    mp[B] = true; 
    mp[C] = true; 
    mp[D] = true;  

    if(mp[1] && mp[9] && mp[7] && mp[4]) cout << "YES\n";
    else cout << "NO\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int n;

	cin >> n;
	int ans = 0;
	vector<int> A(110000);
	for (int i=0; i<n; i++)
	{
		int in;
		cin >> in;
		A[in]++;
	}
	for (int i=0; i<110000; i++)
	{
		int sum = A[i] + A[i+1] + A[i+2];
		ans = max(ans, sum);
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    Block[] blocks = new Block[N];
    for (int i = 0; i < N; i++) {
      blocks[i] = new Block(scanner.nextInt(), scanner.nextInt(), scanner.nextInt());
    }

    Arrays.sort(blocks, Comparator.comparingInt(b -> b.s + b.w));

    final int MAX_W = 1000_000;
    long[] dp = new long[MAX_W + 1];
    for (int i = 1; i <= N; i++) {
      Block b = blocks[i - 1];
      for (int j = b.s; j >= 0; j--) {
        dp[j + b.w] = Math.max(dp[j] + b.v, dp[j + b.w]);
      }
    }

    long max = 0;
    for (int i = 0; i <= MAX_W; i++) {
      max = Math.max(max, dp[i]);
    }
    System.out.println(max);
  }

  private static class Block {
    public final int w;
    public final int s;
    public final int v;

    private Block(int w, int s, int v) {
      this.w = w;
      this.s = s;
      this.v = v;
    }
  }
}


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

using namespace std;


int main() {
    int N;
    cin >> N;
    vector<int> T(N);
    int total = 0;
    for (int i = 0; i < N; ++i){
        cin >> T[i];
        total += T[i];
    }
    int M;
    cin >> M;

    for (int i = 0; i < M; ++i) {
        int p,x;
        cin >> p >> x;
        p--;
        cout << total - (T[p] - x) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*


*/

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

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

#define endl '\n'
#define ld long double
#define ll long long
#define PI acos(-1.0)
#define OO 1e13
#define EPS 1e-12
#define MLOG 20
#define MAX 1* 100 * 1000+5
const int mod = 1e9 + 7;
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }


void fast(){
#ifndef ONLINE_JUDGE
	freopen("E:\\Competitve\\solving\\input.txt", "r", stdin);
	freopen("E:\\Competitve\\solving\\output.txt", "w", stdout);
#endif
}
int n;
double a[3000];
int vis[3000][3000];
double dp[3000][3000];
double rec(int idx, int H){
	if (idx == n){
		return (n - H < H);
	}
	if (vis[idx][H])
		return dp[idx][H];
	vis[idx][H] = 1;

	dp[idx][H] = rec(idx + 1, H + 1) * a[idx];
	dp[idx][H] += rec(idx + 1, H) * (1 - a[idx]);
	return dp[idx][H];
}
int main(){
	//fast();

	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	cout << fixed << setprecision(9);
	cout << rec(0, 0) << endl;
	return 0;

}

Measured memory_bytes: 104192
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

long long mod = 1000000007;

long long find_answer(int N, long long X) {
  if(X == 0) return 0;
  if(N == 0) return 1;  

  long long S = ((1LL << (N + 2)) - 3);
  if(S == X) return (1LL << (N+1)) - 1;

  if(X <= (S/2)) return find_answer(N-1, X-1);
  return (1LL << N) + find_answer(N-1, X - ((1LL << (N+1)) - 3 + 2));
}

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  int N = 0;
  long long X = 0;

  cin >> N >> X;
  cout << find_answer(N, X);

  return 0;
}


Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


ll N, K, A, B, C;
char arr[1000005];
vector<ll> V;
string S;
ll cases;
ll type;
char X;

int main() {
	IOS;
	cin >> S;
	ll ind = 550005;
	ll l = ind;
	for(int i = 0; i < S.size(); i++) {
		arr[ind] = S[i];
		ind++;
	}
	ll r = ind - 1;
	// cout << l << " " << r << " " << arr[l] << " ";

	// scanf("%lld", &cases);
	cin >> cases;
	ll mark = 0;
	while(cases--) {
		cin >> A;
		if(A == 2) {
			cin >> B;
			cin >> X;
			if(!mark) {
				if(B == 2) {
					r++;
					arr[r] = X;
				}
				else {
					l--;
					arr[l] = X;
				}
			}
			else {
				if(B == 2) {
					r--;
					arr[r] = X;
				}
				else {
					l++;
					arr[l] = X;
				}

			}
		}
		else {
			mark ^= 1;
			swap(r, l);
		}
	}
	string ans = "";
	if(mark) {
		for(int i = l; i >= r; i--) {
			ans.push_back(arr[i]);
		}
	}
	else {
		for(int i = l; i <= r; i++) {
			ans.push_back(arr[i]);
		}
	}
	cout << ans << " \n";

	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

import static java.lang.System.in;

class Main{
    static TreeMap<Long,Integer> tm = new TreeMap<>();
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i=0;i<n;i++) a[i]=sc.nextLong();
        long base = 1;
        for(int i=0;i<=31;i++){
            tm.put(base,i);
            base *= i<31?4:1;
        }
        long[] rev = new long[n];
        for(int i=0;i<n;i++) rev[i] = a[n-1-i];
        long[] right = help(a), left = help(rev);
        long ans = 2*right[0];
        for(int i=1;i<n;i++){
            long cur = 2*(right[i]+left[n-i])+i;
            ans = Math.min(ans,cur);
        }
        ans = Math.min(ans,2*left[0]+n);
        System.out.println(ans);

    }
    static long[] help(long[] A){
        int n = A.length;
        long[][] dp = new long[n][16];
        long[] ans = new long[n];
        Arrays.fill(ans,Long.MAX_VALUE);
        ans[n-1]=0;
        for(int j=0;j<16;j++) dp[n-1][j]=j;
        for(int i=n-2;i>=0;i--){
            for(int j=0;j<16;j++){
                long a = A[i]<<(2*j);
                int t = 0;
                while(a>(A[i+1]<<(2*t))) t++;
                if(t<=15) dp[i][j] = j+dp[i+1][t];
                else dp[i][j] = j+dp[i+1][15]+(t-15)*(n-i-1);
                ans [i] = Math.min(ans[i],dp[i][j]);
            }
        }
        return ans;
    }
}


Measured memory_bytes: 135156
def main():
    edges = dict()

    for _ in range(3):
        a, b = map(int, input().split())
        edges[a] = edges.get(a, 0) + 1
        edges[b] = edges.get(b, 0) + 1

    odds = 0
    for i, cnt in edges.items():
        if cnt % 2 == 1:
            odds += 1

    if odds <= 2:
        print('YES')
    else:
        print('NO')

main()


Measured memory_bytes: 3060
input_num= gets.to_i
anser = ""

9.downto(1){|n|
       if input_num % n == 0
        input_num = input_num / n
        break
       end
}
9.downto(1){|n|
        if (input_num / n == 1) && (input_num % n == 0)
        anser = "Yes"
        end
}
        if anser == "Yes"
            puts "Yes"
        else
            puts "No"
        end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

void solve(){
    int N;
    cin >> N;
    ll sum = 0;
    map<ll, ll> mp;
    mp[0]++;
    ll ans = 0;
    REP(i,N){
        ll A;
        cin >> A;
        sum += A;
        ans += mp[sum];
        mp[sum]++;
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

Measured memory_bytes: 15940
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();
        int N, W;
        {int[]a = r.ii(); N = a[0]; W = a[1];}
        int[] w = new int[N];
        int[] v = new int[N];
        ArrayList<Integer>[] things = new ArrayList[4];
        for(int i = 0; i < 4; i++)
            things[i] = new ArrayList<>();
        for(int i = 0; i < N; i++){
            int[] a = r.ii();
            w[i] = a[0];
            v[i] = a[1];
            things[w[i]-w[0]].add(v[i]);
        }
        for(int i = 0; i < 4; i++)
            things[i].sort((x, y) -> -x+y);

        int w0 = w[0];
        int w1 = w0+1;
        int w2 = w1+1;
        int w3 = w2+1;
        long max = 0;

        for(int i = 0, v0 = 0; i <= Math.min(W/w0, things[0].size()); i++){
            if(i > 0)
                v0 += things[0].get(i-1);
            for(int j = 0, v1 = 0; j <= Math.min((W-i*w0)/w1, things[1].size()); j++){
                if(j > 0)
                    v1 += things[1].get(j-1);
                for(int k = 0, v2 = 0; k <= Math.min((W-i*w0-j*w1)/w2, things[2].size()); k++){
                    if(k > 0)
                        v2 += things[2].get(k-1);
                    for(int l = 0, v3 = 0; l <= Math.min((W-i*w0-j*w1-k*w2)/w3, things[3].size()); l++){
                        if(l > 0)
                            v3 += things[3].get(l-1);
                        max = Math.max(max, v0+v1+v2+v3);
                    }
                }
            }
        }
        println(max);
    }
    static void print(Object o){
        System.out.print(o.toString());
    }

    static void println(Object o){
        System.out.println(o.toString());
    }

    static int Int(String s){
        return Integer.parseInt(s);
    }

    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }

        long l() throws IOException{
            return Long(s());
        }

        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n,p;

int main(){
    while(cin >> n >> p && n){
        vector<ll> cnt(n,0);
        int now = 0;
        while(1){
            if(p != 0){
                cnt[now]++;
                p--;
                if(p == 0){
                    bool f = true;
                    rep(i,n){
                        if(i != now)f &= (cnt[i] == 0);
                    }
                    if(f){
                        cout << now << endl;
                        break;
                    }
                }
            }
            else {
                p += cnt[now];
                cnt[now] = 0;
            }
            now = (now+1)%n;
        }
    }
}


Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <iomanip>
#include <cstdio>
#include <algorithm>
using namespace std ;
int main(){
    double a, b, x, y, e ;
    cin >> a >> b >> x >> y ;
    e = a * b ;
    if(a/2 == x && b/2 == y ){
        cout << fixed << setprecision(9) << e/2 << " " << 1 << endl ;       
    }
    else if(a != x/2 || b != y/x ){
        cout << fixed << setprecision(9) << e/2 << " " << 0 << endl ;
    } 

    return 0 ;

}

Measured memory_bytes: 256
(* O(n) *)
let find_fold_int f a n =
  let rec find a i =
    if i >= n then
      a, false
    else
      let (res, detected) as r = f a i in
        if detected then r else find res (i + 1)
  in
    find a 0

(* O(n^2) *)
let solve n y =
  find_fold_int
    (fun sofar_a a ->
      find_fold_int
        (fun sofar_b b ->
          let c = n - a - b in
          if 10000 * a + 5000 * b + 1000 * c = y then
            (a, b, c), true
          else
            sofar_b, false)
        sofar_a
        (n - a + 1))
    (-1, -1, -1)
    (n + 1) |> fst

let read_ints () = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let _ =
  match read_ints () with
  | [n; y] -> let (a, b, c) = solve n y in Printf.printf "%d %d %d\n" a b c
  | _ -> ()

Measured memory_bytes: 2560
#include<stdio.h>
#define true 1
#define false 0
typedef struct{ 
  char suit;
  char value;
} card;



void bubblesort(card A[], int N){
  int i, j;
  card temp;
  
  for( i = 0; i < N; i++){
    for(j = N -1; j >= i+1; j--){
      if(A[j].value < A[j-1].value){
      	temp = A[j];
      	A[j] = A[j-1];
      	A[j-1]=temp;
      }
    }
  }

}

void selectionsort(card A[], int N){
  int i,j,minj;
  card temp;
  for(i = 0; i < N; i++){
    minj = i;
    for(j = i; j < N; j++){
      if(A[j].value < A[minj].value) minj = j;
    }
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
 }
}

void Print(card A[], int N){
  int i;
    for(i = 0; i < N-1 ; i++){
      printf("%c%c ",A[i].suit,A[i].value);
    }
    printf("%c%c\n",A[N-1].suit,A[N-1].value);
  
 }

int isStable(card c1[], card c2[], int N){
  int i = 0;
  for (i = 0; i < N; i++){
    if(c1[i].suit != c2[i].suit){
      return false;
    }
  }
  return true;
}

int main(){
  card c1[100],c2[100];
  int N;
  char ch;
  int i;

  scanf("%d",&N);
  for(i=0; i < N; i++){
    scanf(" %c",&c1[i].suit);
    scanf("%c",&c1[i].value);
  }

  for(i=0; i < N; i++){
    c2[i] = c1[i];
  }
  /*
  for(i=0;i<N;i++){
    printf("c1:%c%c\n",c1[i].suit,c1[i].value);
    printf("c2:%c%c\n",c2[i].suit,c2[i].value);
  }
*/

  bubblesort(c1,N);
  selectionsort(c2,N);

  Print(c1,N);
  printf("Stable\n");

  Print(c2,N);
  if(isStable(c1,c2,N) == 1){
    printf("Stable\n");
  }
  else {
    printf("Not stable\n");
  }
  
  return 0;
}




Measured memory_bytes: 2072
process.stdin.resume();
process.stdin.setEncoding('utf8');

var sv = []

var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
    var n = line
    var s = Math.floor(Math.sqrt(n));
    for(;;s--){
        if((n % s)=== 0){
            console.log(s + (n / s) - 2);
            return
        }
    }
});

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

using namespace std;

int main(){
    string s; cin>>s;
    char cir[100001];
    vector<int> xnum(100001,0);
    int cnt=0,cnt2=0;
    int flag=0,ans=0;

    for(int i=0;i<s.size();i++){
        if(s[i]!='x'){
            cir[cnt++]=s[i];
            cnt2++;
        }else if(s[i]=='x'){
            xnum[cnt2]++;
        }
    }
    for(int i=0;i<=(cnt-1)/2;i++){
        if(cir[i]!=cir[cnt-1-i]){
            printf("-1");
            flag=1;
            break;
        }
    }

    if(flag==0){
        for(int i=0;i<=cnt/2;i++){
            if(xnum[i]>xnum[cnt-i]) ans+=(xnum[i]-xnum[cnt-i]);
            else if(xnum[i]<xnum[cnt-i]) ans+=(xnum[cnt-i]-xnum[i]);
        }

        printf("%d",ans);
    }

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,a,b;
    ll sum=0;
    cin>>h>>w>>a>>b;
    ll ans[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            ans[i][j]=1e3;
        }
    }
    for(int i=a-1;i<h;i+=a){
        for(int j=b-1;j<w;j+=b){
            ans[i][j]=-1e3*(a*b-1)-1;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            sum+=ans[i][j];
        }
    }
    if(sum<=0){
        cout <<"No"<<endl;
        return 0;
    }
    cout <<"Yes"<<endl;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}



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

int main() {
  int a, b;
  cin >> a >> b;
  if(a % 2 == 1 && b % 2 == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int selectionSort(int A[], int N)
{
  int sw = 0;
  for (int i = 0; i < N; i++)
  {
    int minj = i;
    for (int j = i; j < N; j++)
    {
      if (A[j] < A[minj])
      {
        minj = j;
      }
    }
    if (minj != i)
    {
      // swap(A[i], A[minj]);
      int v = A[i];
      A[i] = A[minj];
      A[minj] = v;
      sw++;
    }
  }
  return sw;
}

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

  int a[n];
  rep(i, n) cin >> a[i];

  int cnt = selectionSort(a, n);
  rep(i, n) {
    cout << a[i];
    if (i != n - 1)
    {
      cout << " ";
    } else {
      cout << endl;
    }
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3096
N=int(input())

s=input()
l=[]
l.append(s)
check=0
for i in range(N-1):
  t=input()
  if t not in l and t[0]==s[-1]:
    l.append(t)
    s=t[:]
  else:
    check=1
print("Yes" if check==0 else "No")

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

ans = 0
for i in range(N):
    ans += min(A[i], B[i])
    num = max(0, B[i] - A[i])
    battle_num = min(A[i + 1], num)
    ans += battle_num
    A[i + 1] -= battle_num

print(ans)


Measured memory_bytes: 19156
N,A,B = map(int,input().split())
K = N%(A+B)
L = N//(A+B)*A
if A == 0:
    print(0)
elif N<A:
    print(N)
elif A==N:
    print(A)
elif N<=(A+B):
    print(A)
else:
    if N%(A+B) > A:
        print(L+A)
    else:
        print(L+K)

Measured memory_bytes: 3060
deck = {}
%w(S H C D).each do |suit|
    deck[suit] = [*1..13]
end

_ = gets
ARGF.each_line do |line|
  suit, num = line.split
  deck[suit].delete(num.to_i)
end

deck.each do |suit, nums|
  nums.each do |num|
    puts "#{suit} #{num}"
  end
end

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

/*
最終的に, あるpartitionを境に左側全てR, 右側全てWになるようにすれば良い.
左端からのindexと右端からのindexをそれぞれR, Wが見つかるまで進め,
見つかったら両者の位置を交換する. これを繰り返すことでRRRRWWWWのような
二分割された形になる.
Quicksortのpartition algorithmとほぼ同じ動き.
*/

int main() {
  int N;
  cin >> N;
  
  char c[200010];
  for (int i = 0; i < N; i++) cin >> c[i];
  
  int i = 0, j = N - 1, result = 0;
  while (true) {
    while (i < N and c[i] != 'W') i++;  // 左端からRが見つかるまで進める
    while (j > 0 and c[j] != 'R') j--;  // 右端からWが見つかるまで進める
    if (i == N or j == -1 or i >= j) break;  // 終点に達するかすれ違ったら終了
    swap(c[i], c[j]);  // RとWの位置交換
    result++;
  }
  
  cout << result << endl;
}

Measured memory_bytes: 3812
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n,m;
    scanf("%d %d", &n, &m);
    if(n >= m){
        printf("%d", 0);
        return 0;
    }
    vector<int> viCoordinate(m);
    for(int i = 0; i < m; i++){
        scanf("%d", &viCoordinate[i]);
    }
    sort(viCoordinate.begin(), viCoordinate.end());

    int nAns = viCoordinate[m-1] - viCoordinate[0];
    vector<int> viDist;
    for(int i = 0; i < m-1; i++){
        int iDist = viCoordinate[i+1] - viCoordinate[i];
        viDist.push_back(iDist);
    }
    sort(viDist.begin(), viDist.end());
    
    for(int i = m-2; i > m-n-1; i--){
        nAns -= viDist[i];
    }
  
    printf("%d", nAns);
    return 0;
}


Measured memory_bytes: 1276
#include <iostream>
#include <cmath>
#define INF 1e+9
using namespace std;

int main(){
	int n,s,a[100000];
	cin >> n >> s;
	for(int i = 0;i < n;i++) cin >> a[i];
	int l = 0,r = 0,sum = 0,cnt = INF;
	while(1){
		while(sum < s && r < n){
			sum += a[r++];
		}
		if(sum < s) break;
		cnt = min(cnt,r - l);
		sum -= a[l++];
	}
	if(cnt != INF) cout << cnt << endl;
	else cout << 0 << endl;
	return 0;	
}

Measured memory_bytes: 3504
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    long long int a, b, c, k;
    cin >> a >> b >> c >> k;
    // int res = 0;
    if (a >= k)
    {
        cout << k << endl;
    }
    else if (a < k && k <= a + b)
    {
        cout << a << endl;
    }
    else if (a + b < k)
    {
        cout << a - (k - a - b) << endl;
    }
    return 0;
    // if (a <= k)
    // {
    //     res += a;
    // }
    // else
    // {
    //     cout << a << endl;
    //     return 0;
    // }
    // if (b <= k - a)
    // {
    //     cout << a - (k - a - b) << endl;
    //     return 0;
    // }
    // else
    // {
    //     cout << a << endl;
    //     return 0;
    // }

    return 0;
}

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



int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int N;
	cin >> N;
	int tot = 0;
	for (int i = 1 ; i <= N ; i++)
	{
		int nb = N / i;
		tot += (i + nb * i) * (nb ) / 2; 
	}
	cout<<tot<<endl;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin>>n;
	map<int, int> m;
	rep(i, n){
		int a;
		cin>>a;
		m[a]++;
	}
	vi v;
	set<int> st;
	for(auto& p : m){
		//cout<<" "<<p.fi<<" "<<p.se<<endl;
		if(p.se>2) {
			if(p.se&1) p.se = 1;
			else p.se = 2;
		}
		if(p.se == 1) v.pb(p.se);
		else {
			st.insert(v.size());
			v.pb(p.se);
		}
	}
	cout<<(v.size()- (st.size()%2))<<endl;
}


Measured memory_bytes: 5628
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
//const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
/*signed*/int main(void) {   
    int n;
    cin >> n;
    cout << n * n * n << endl;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL LINF=1LL<<62;
const LL mod=1e9+7;


int main(){
    int A,B;
    cin >> A >> B;
    cout << max({A+B,A-B,A*B}) << endl;
    return 0;
}

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

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORED(i, s, n) for (int i = (s); i >= (int)(n); i--)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define debugs(s) cerr << s << "\n"
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

#define fst first
#define snd second
#define pb push_back
#define mk(x,y) make_pair((x),(y))

// http://ehafib.hatenablog.com/entry/2015/12/23/164137
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qpm(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
// gcd : O(logN)
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; }

#define sz(v) int(v.size())

// x1, x2ライブラリとの被りを避ける
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789

// typo
#define itn int
#define reutrn return
#define reutnr return
#define srting string

#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;

int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}

#define uniq(v) (v).erase(unique(ALL((v))), (v).end());

// area of (0, 0)(a, b)(c, d)
double area(double a, double b, double c, double d){
    return abs(a * d - b * c) / 2.0;
}

const int PREC = 10;
#define coutf(val) cout << fixed << setprecision(PREC) << (val) << endl;

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

signed main() {
    make(int, N);

    // 1が2個、3が2個…
    vector<int> cnt(1000000, 0LL);
    int sum = 0;
    vector<int> As(N);
    REP(i, N) {
        make(int, A);
        As.at(i) = A;

        cnt.at(A)++;
        sum += A;
    }

    make(int, Q);

    // vector<int> Bs(Q);
    // vector<int> Cs(Q);
    REP(i, Q){
        make2(int, B, C);

        // BをCに変える。この時の変化は?
        sum += cnt.at(B) * (C-B);
        cnt.at(C) += cnt.at(B);
        cnt.at(B) = 0;

        cout << sum << endl;
    }


}


Measured memory_bytes: 11948
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
typedef  long long     ll ;
typedef  unsigned long long ull;
const double EPS= (1e-9);
using namespace std;
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=100000+9,mod=1000000000+7;
ll cnt[N],fres[N];
void go(int n){

   for(int i=1;i*i<=n;i++){

       if(n%i==0){
         cnt[i]++;
         if(n/i!=i) cnt[n/i]++;
       }

   }
}
ll power(ll b,ll p){

   if(p==0) return 1;
   if((p&(1ll))){
     return b%mod*power((b*b)%mod,p/2)%mod;
   }
   else{
    return  power((b*b)%mod,p/2);
   }
}
int main(){

    ll n,k;
    cin>>n>>k;
    for(int i=1;i<=k;i++){
        go(i);
    }
    ll ans=0;
    for(ll i=k;i>=1;i--){
        fres[i]=power(cnt[i],n);
         for(ll j=i*2;j<=k;j+=i){
            fres[i]=((fres[i]-fres[j])+mod)%mod;
         }
         ans+= (1ll*fres[i]*i)%mod;
         if(ans>=mod) ans-=mod;

    }
    cout<<ans<<"\n";
}



















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

int main() {
    string S, T;
    cin >> S;
    cin >> T;
    int size_T = T.size();
    stack<int> Stack;
    bool flag = false;
    for (int i = 0; i < S.size() - size_T+1; i++) {
        int cnt = 0;
        for (int j = 0; j < size_T; j++) {
            if (S[i+j] != '?') {
                if (S[i+j] == T[j]) cnt++;
                else break;
            }
            else cnt++;
        }
        if (cnt == size_T) {
            flag = true;
            Stack.push(i);
        }
        }
    if (flag) {
        int head = Stack.top();
        for (int i=0; i < T.size(); i++) {
            S[i+head] = T[i];
        }
        for (int i=0; i < S.size(); i++) {
            if (S[i] == '?') {
                S[i] = 'a';
            }
        }
        cout << S << '\n';
    }
    else
        cout << "UNRESTORABLE" << '\n';
}



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

// editorialを見た人間から言わせてもらうと、
// 自由に並び替えていいということは、最初の並びは関係なくて、
// 'a','b','c'の数だけ関係しそう
// 2文字以上の回文ということは
// 3文字の回文は両端(間1文字挟んだ)の文字が同じ、
// 4文字の回文は両端の文字が同じで、間の2文字が回文
// 5文字の回文は両端の文字が同じで、間の3文字が回文
// 6文字の回文は両端の文字が同じで、間の4文字が回文
// ......
// と展開していくと、2文字の回文と3文字の回文が存在しなければ
// それ以上の長さの回文は含まれないことがわかる
// よって、間1つ挟んだ2つの文字が違い、かつ
// 隣の文字が異なるように'a','b','c'を並べたい
// abcabcabc....のようにならべる
// つまりa,b,cの数の差が1以内であればよい
int main()
{
    string S;
    cin >> S;
    vector<int> num(3);
    for(auto &p : S) {
        ++num[p-'a'];
    }
    int res = *(max_element(num.begin(),num.end())) - *(min_element(num.begin(),num.end()));
    if(res > 1) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(N);
  map<int, int> list;
  FOR(i, N) {
    GI(D);
    list[D]++;
  }
  GI(M);
  FOR(i, M) {
    GI(T);
    if (list[T] < 1) {
      print("NO");
      return 0;
    }
    list[T]--;
  }
  print("YES");
  return 0;
}

Measured memory_bytes: 9600
import sys
h, w = list(map(int, input().split()))
maze = []
for i in range(h):
    maze.append(input())

dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
for i in range(h):
    for j in range(w):
        if maze[i][j] == '#':
            flag = False
            for k in range(4):
                nx = i + dx[k]
                ny = j + dy[k]
                if nx >= 0 and nx < h and ny >= 0 and ny < w and maze[nx][ny] == '#':
                    flag = True
                    break
            if not flag:
                print('No')
                sys.exit()
print('Yes')

Measured memory_bytes: 9228
#include<stdio.h>
int main(){
	int g,m,aizuC,C,max,i,j,n1,n2,sum;
	for(;scanf("%d %d %d %d %d",&g,&m,&aizuC,&C,&max)&&g;){
		n1=0;n2=0;
		for(i=1;i<=max;i++){
			for(j=g-i;;j++){
				sum=0;
				if(i>=0)sum+=aizuC*i;
				if(j>=0)sum+=C*j;
				if(sum>m)break;
				if(i>=0)n1=i;
				if(j>=0)n2=j;
				else n2=j;
			}
		}
		if(!n1&&!n2)printf("NA\n");
		else printf("%d %d\n",n1,n2);
	}
	return 0;
}

Measured memory_bytes: 0