akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e14;
using Graph = vector<vector<int>>;

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

  int ans = 0;
  for( int i = 0; i < N; i++ ){
    for( int j = i+1; j < N; j++ ){
      for( int k = j+1; k < N; k++ ){
        if( L[i]+L[j] > L[k] && L[j]+L[k] > L[i] && L[i]+L[k] > L[j] && L[i] != L[j] && L[j] != L[k] && L[k] != L[i] ){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Integer.parseInt;

/**
 * Best Pizza
 * JOI 11th, Pre 3
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int N, A, B, C;
		int[] D;

		N = parseInt(br.readLine());
		line = br.readLine();
		A = parseInt(line.substring(0, line.indexOf(' ')));
		B = parseInt(line.substring(line.indexOf(' ') + 1));
		C = parseInt(br.readLine());

		D = new int[N];
		for (int i = 0; i < N; i++) D[i] = parseInt(br.readLine());
		Arrays.sort(D);

		int max = 0, _C = C, j = 0;
		for (int i = N - 1; i >= 0; i--) {
			_C += D[i];
			j++;
			max = Math.max(max, _C / (A + j * B));
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 24480
#include<stdio.h>
int main(){
	int a,b,H,W;
	
	while(1){
		scanf("%d%d",&H,&W);
		if(H==0&&W==0){
			break;
		}
		
		for(a=0;a<H;a++){
				for(b=0;b<W;b++){
					printf("#");
				}
			printf("\n");
		}
		printf("\n");
		
	}
	return 0;
}

Measured memory_bytes: 572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();


        string answer = a + b >= 10 ? "error" : (a + b).ToString();

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()
    Q = int(input())
    query = [None] * Q
    for i in range(Q):
        query[i] = input().split()

    prefix = []
    surfix = []
    prefix_append = prefix.append
    surfix_append = surfix.append
    is_reversed = False
    for q in query:
        if q[0] == "1":
            is_reversed = not is_reversed
        else:
            F, C = q[1], q[2]
            if F == "1":
                if is_reversed:
                    surfix_append(C)
                else:
                    prefix_append(C)
            else:
                if is_reversed:
                    prefix_append(C)
                else:
                    surfix_append(C)

    ans = "".join(["".join(prefix)[::-1], S, "".join(surfix)])
    if is_reversed:
        ans = ans[::-1]

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 41816
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

const int mx=1000010;
const ll mod=1e9+7;

int main(){
  int n; 
  string s; 
  cin >> n >> s;
  vector<int> a(n);
  rep(i,n) a[i]=(int)(s[i]-'0');

  for(int i=0; i<min(10,n-1); i++){
    int k = a.size();
    for(int j=0; j<k-1; j++){
      a[j] = abs(a[j]-a[j+1]);
    }
    a.pop_back();
  }

  int m = a.size();
  if(m==1){ cout << a[0] << endl; return 0; }

  int cnt1=0, cnt2=0;
  bool flag = true;
  rep(i,m){
    if(a[i]==1){
      if(((m-1)&i)==i){
        cnt1++;
      }
      flag = false;
    }
    if(a[i]==2){
      if(((m-1)&i)==i){
        cnt2++;
      }
    }
  }
  if(flag){
    cout << cnt2%2*2 << endl;  
    return 0;  
  }
  cout << cnt1%2 << endl;
  return 0;
}

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

namespace AtCoder
{
    public class A
    {
        public static void Main(string[] args)
        {
            List<string> target = Console.ReadLine().Split(' ').ToList();

            var message = A.Execute(target);
            Console.WriteLine(message);
        }

        public static string Execute(List<string> target)
        {
            var fiveCount = target.Where(x => x.Equals("5")).Count();
            var sevenCount = target.Where(x => x.Equals("7")).Count();
            if (fiveCount == 2 && sevenCount == 1)
            {
                return "YES";
            }

            return "NO";
        }
    }
}

Measured memory_bytes: 11348
#include <algorithm>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define REP(i, m, n) for (int i = int(m); i < int(n); i++)
#define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i)
#define EACH(i, c) for (auto &(i) : c)
#define all(c) begin(c), end(c)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(begin(c), end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x) cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s)                                                               \
    do {                                                                       \
    } while (0)
#define dump(x)                                                                \
    do {                                                                       \
    } while (0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int, int>;
using VP = vector<PII>;

// struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
// constexpr double PI  = acos(-1.0);
// constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
// inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    int n;
    cin >> n;
    VI a(n), b(n), c(n);
    REP(i, 0, n) cin >> a[i];
    REP(i, 0, n) cin >> b[i];
    REP(i, 0, n) cin >> c[i];
    sort(all(a));
    sort(all(b));
    sort(all(c));
    LL ans = 0;
    REP(i, 0, n) {
        LL pa = distance(a.begin(), lower_bound(all(a), b[i]));
        LL pc = distance(lower_bound(all(c), b[i] + 1), c.end());
        ans += pa * pc;
    }
    cout << ans << endl;
}

int main() {
    solve();

    return 0;
}

Measured memory_bytes: 1408
from heapq import heapify, heappop, heappush


def dijkstra(n, train, start):
    d = []
    queue = []
    INF = 10 ** 16
    for i in range(n):
        d.append(INF)
    d[start] = 0
    heapify(queue)
    heappush(queue, (0, start))
    # 都市kに行く時の円またはスヌークのの最小値
    while len(queue) != 0:
        distance, v = heappop(queue)
        if d[v] < distance:
            continue
        for u in range(len(train[v])):
            if d[train[v][u][0]] > d[v] + train[v][u][1]:
                d[train[v][u][0]] = d[v] + train[v][u][1]
                heappush(queue, (d[train[v][u][0]], train[v][u][0]))
    return d


def main():
    n, m, s, t = map(int, input().split())
    s -= 1
    t -= 1
    money = 10 ** 15
    train_en = []
    train_snuuk = []

    for i in range(n):
        train_en.append([])
        train_snuuk.append([])
    for i in range(m):
        fro, to, a, b = map(int, input().split())
        fro -= 1
        to -= 1
        train_en[fro].append((to, a))
        train_en[to].append((fro, a))
        train_snuuk[fro].append((to, b))
        train_snuuk[to].append((fro, b))

    a = dijkstra(n, train_en, s)
    b = dijkstra(n, train_snuuk, t)

    cost_sum = []
    for i in range(n):
        cost_sum.append((a[i] + b[i], i + 1))
    heapify(cost_sum)
    m, y = heappop(cost_sum)
    for i in range(n):
        while y <= i:
            m, y = heappop(cost_sum)
        print(money - m)


if __name__ == '__main__':
    main()


Measured memory_bytes: 90172
def solve(N):
    d = 10 ** 7
    index = d // 2
    while True:
        k1 = index * (index - 1) // 2
        k2 = index * (index + 1) // 2
        if k1 <= N < k2:
            break
        elif k1 < N:
            index = (index + d) // 2
        else:
            d = index
            index = index // 2

    d = k2 - N
    return "\n".join([str(i) for i in range(1, index + 1) if i != d])


if __name__ == "__main__":
    N = int(input())
    print(solve(N))


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
//解説写し
long long oddsolve(long long a){
  return (a+1)/2%2;
}
long long solve(long long a){
  if(a%2==1)return oddsolve(a);
  else return oddsolve(a+1)^(a+1);
}
int main() {
  long long A,B;
  cin>>A>>B;
  cout<<(solve(B)^solve(A-1))<<endl;   
  return 0;
}

Measured memory_bytes: 256
class Node
  attr_reader :id, :siblings
  attr_accessor :state

  def initialize(id)
    @id = id
    @siblings = []
    @distances = {}
    @state = :white
  end

  def add(sibling, distance)
    @siblings << sibling
    @distances[sibling.id] = distance
  end

  def distance_from(other)
    @distances[other.id]
  end
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i

  nodes = []

  n.times do
    id, _, *rest = gets.chomp.split.map(&:to_i)

    nodes[id] ||= Node.new(id)
    node = nodes[id]

    rest.each_slice(2) do |sibling_id, distance|
      nodes[sibling_id] ||= Node.new(sibling_id)
      sibling = nodes[sibling_id]
      node.add(sibling, distance)
    end
  end

  distances = Array.new(n, Float::INFINITY)

  distances[0] = 0
  nodes[0].state = :gray

  loop do
    current = nil
    min = Float::INFINITY

    nodes.each do |node|
      next if node.state == :black

      distance = distances[node.id]

      if distance < min
        min = distance
        current = node
      end
    end

    break unless current

    current.state = :black

    current_distance = distances[current.id]

    current.siblings.each do |sibling|
      next if sibling.state == :black

      distance = current_distance + current.distance_from(sibling)

      if distance < distances[sibling.id]
        distances[sibling.id] = distance
        sibling.state = :gray
      end
    end
  end

  puts distances.map.with_index {|distance, id| [id, distance].join(' ') }.join("\n")
end

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

int main(void) {
	int n;
	vector<string> w;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string w_i;
		cin >> w_i;
		w.push_back(w_i);
	}
	
	for (int i = 1; i < n; i++) {
		int len = w[i-1].size();
		if ((w[i-1][len-1]) != w[i][0]) {
			puts("No");
			return 0;
		}
	}
	
	for (int i = 0; i < n; i++) {
		string nowstr = w[i];
		for (int j = 0; j < i; j++) {
			if (nowstr == w[j]) {
				puts("No");
				return 0;
			}
		}
	}
	
	puts("Yes");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
LL mod = 1e9+7;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	int N, M;
	cin >> N >> M;
	vector<vector<int>>	dp(N, vector<int>(N, INF)), g(N, vector<int>(N, INF));
	for(int i = 0;i < M;i++){
		int a, b, c;
		cin >> a >> b >> c;
		g[a-1][b-1] = c;
		g[b-1][a-1] = c;
		dp[b-1][a-1] = c;
		dp[a-1][b-1] = c;
	}
	for(int k = 0;k < N;k++){
		for(int i = 0;i < N;i++){
			for(int j = 0;j < N;j++){
				dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
			}
		}
	}
	int ans = 0;
	for(int i = 0;i < N;i++){
		for(int j = i+1;j < N;j++){
			if(g[i][j] < INF && dp[i][j] < g[i][j])	ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,k;cin>>a>>b>>c>>k;
    int ans=0;
    if(k>=a){
        if(k>=a+b){
            ans+=a-(k-a-b);
        }else{
            ans=a;
        }
    }else{ans=k;}
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,V,W,T;
    
    scanf("%d %d",&A,&V);
    scanf("%d %d",&B,&W);
    scanf("%d",&T);
    
    int zansa = (A>B)? A-B:B-A;
    int soutaiv = V-W;
    
    //printf("sv:%d\n sv*T:%d\n zansa:%d\n",soutaiv,soutaiv*T,zansa);
    if(soutaiv > 0 && (long)soutaiv*T >= (long)zansa)
        printf("YES\n");
    else
        printf("NO\n");
}


Measured memory_bytes: 3760
import queue

K = int(input())

q = queue.Queue()
for i in range(9): q.put(i+1)

for _ in range(K):
	lunlun = q.get()
	
	if(lunlun%10)!=0: q.put(10*lunlun + lunlun%10 - 1)
	q.put(10*lunlun + lunlun%10)
	if (lunlun%10)!=9: q.put(10*lunlun + lunlun%10 + 1)

print(lunlun)

Measured memory_bytes: 12452
n = int(input())
h = [int(i) for i in input().split()]
h.reverse()

for i in range(1,len(h)):
  if h[i-1] < h[i] :
    if h[i-1] - h[i] == -1:
      h[i] = h[i] - 1
    elif h[i-1] - h[i] < -1:
      print("No")
      exit()

print("Yes")

Measured memory_bytes: 14252
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

mint dp0[2005][2005];
mint dp1[2005][2005];

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

    vector<int> s(n+1), t(m+1);
    rep(i, n) {
        cin >> s[i];
    }
    rep(i, m) {
        cin >> t[i];
    }

    dp0[0][0] = 1;
    rep(i, n+1) {
        rep(j, m+1) {
            dp0[i+1][j] += dp0[i][j];
            dp1[i][j] += dp0[i][j];
            dp1[i][j+1] += dp1[i][j];
            if(s[i] == t[j]) {
                dp0[i+1][j+1] += dp1[i][j];
            }
        }
    }

    mint ans = dp1[n][m];

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

Measured memory_bytes: 63104
#include<stdio.h>
#include<stdlib.h>
int Selectionsort(int *p,int N){
    int i,min,j,tmp,count=0;
    for(i=0;i<=N-1;i++){
    min=i;
    for(j=i;j<=N-1;j++){
        if(*(p+j)<*(p+min)){
            min=j;
        }
    }
            if(min!=i){
            tmp=*(p+i);
            *(p+i)=*(p+min);
            *(p+min)=tmp;
            count++;
            }
    
    }
    return count;

}
int main(void){
int N,*p,n,i=0,count;
    scanf("%d",&N);
    p=malloc(sizeof(int)*N);
    while(scanf("%d",(p+i))==1){
        i++;
        if(i==N) break;
    }
    count=Selectionsort(p,N);
    for(i=0;i<N-1;i++){
        printf("%d ",*(p+i));
    }
    printf("%d\n",*(p+i));
    printf("%d\n",count);
    free(p);
    return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll X,K,D;
int main(){
    cin>>X>>K>>D;
    if(X<0)X*=-1;
    if(X / K>=D){
        cout<<X-D*K;
        return 0;
    }
    ll n=X/D;
    X=X-n*D;
    if((K-n)%2==0){
        cout<<X;
    }else{
        cout<<D-X;
    }
    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vi  = vector<int>;
#define _GLIBCXX_DEBUG
#define IO_STREAM cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;++i)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define INF 1000000000000000LL
const ll MOD = 1000000007;
const double PI = acos(-1);
//||
#define DBG(a,b,c,d) //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<endl

signed main(){
	IO_STREAM;
	string S;
	cin>>S;
	string s1,r1,s2,r2;
	int N=S.size();
	s1=S.substr(0,(N-1)/2);
	r1=s1;
	reverse(all(r1));
	s2=S.substr((N+3)/2-1,(N-1)/2);
	r2=s2;
	reverse(all(r2));
	DBG("","","","");
	if(s1==r1 && s2==r2 && s1==r2){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
int x[10000],i,j;
for (i=1;i<=10000;i++){
	cin>>x[i];
	if(x[i]==0) {
	break;
}
}
for(j=1;j<=10000;j++){
if(x[j]==0){
break;
}
cout<<"Case "<<j<<": "<<x[j]<<endl;
}
return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)
#define debug(var) cout << "[" << #var << "] " << var << endl

const int INF = 1<<29;
const double EPS=1e-9;
const int MOD=998244353;

signed main() {
    int L, R, d;
    cin >> L >> R >> d;
    cout << floor(R/d) - floor((L-1)/d);
}



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

int gcd(int a, int b) {
	if(a<b) swap(a,b);
	if(b==0) return a;
	if(b==1) return 1;
	return gcd(b,a%b);
}

int main() {
	int a,b;
	cin >> a >> b;
	cout << gcd(a,b) << endl;
	return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define maxn 1100
#define inf 1000000007
using namespace std;
struct edge{int r,nxt;}e[maxn<<1];
int dp[maxn][2],head[maxn],esz,val[maxn],mx,n,f[2][maxn*5],g[2][maxn*5];
void addedge(int u,int v){
	e[++esz].r=v;e[esz].nxt=head[u];head[u]=esz;
}
void solve(int u){
	for(int t=head[u];t;t=e[t].nxt)
		solve(e[t].r);
	int p=0,np=1;
	for(int i=0;i<=mx;++i)
		f[np][i]=g[np][i]=0,
		f[p][i]=g[p][i]=inf;
	for(int t=head[u];t;t=e[t].nxt,swap(p,np))
		for(int i=mx;i>=0;--i){
			if(i>=val[e[t].r])f[p][i]=min(f[p][i],f[np][i-val[e[t].r]]+dp[e[t].r][0]);
			if(i>=dp[e[t].r][1])f[p][i]=min(f[p][i],f[np][i-dp[e[t].r][1]]+val[e[t].r]);
			if(i>=val[e[t].r])g[p][i]=min(g[p][i],g[np][i-val[e[t].r]]+dp[e[t].r][1]);
			if(i>=dp[e[t].r][0])g[p][i]=min(g[p][i],g[np][i-dp[e[t].r][0]]+val[e[t].r]);
			f[np][i]=g[np][i]=inf;
	}
	dp[u][0]=f[np][val[u]];
	dp[u][1]=g[np][val[u]];
}
int main(){
	scanf("%d",&n);
	for(int i=2,f;i<=n;++i)scanf("%d",&f),addedge(f,i);
	for(int i=1;i<=n;++i)scanf("%d",&val[i]),mx=max(mx,val[i]);
	solve(1);
	if(dp[1][0]==inf&&dp[1][1]==inf)puts("IMPOSSIBLE");
	else puts("POSSIBLE");
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<cstdio>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9 + 7;
int H, W, K;
ll dp[101][10];//dp[x][y]で高さxにおける左からy本目に到達する横棒の置き方
int main() {
	cin >> H >> W >> K;
	fill(dp[0], dp[H + 1], 0);
	for (int i = 0; i < W; ++i) {
		if (i == 0)dp[0][i] = 1;
		else dp[0][i] = 0;
	}
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < 1 << (W - 1); ++j) {
			bool ignore = false;
			for (int l = 0; l < W - 2; ++l) {
				if (j >> l & 1 && j >> (l + 1) & 1) {
					ignore = true;
				}
			}
			if (!ignore) {
				for (int l = 0; l < W; ++l) {
					if (l != 0 && j >> (l - 1) & 1)dp[i + 1][l] += dp[i][l-1];
					else if (l != W - 1 && j >> l & 1)dp[i + 1][l] += dp[i][l + 1];
					else dp[i + 1][l] += dp[i][l];
					dp[i + 1][l] %= INF;
				}
			}
		}
	}
	cout << dp[H][K - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#N,{N-1,1},{N-2,2}

N = gets.chomp.to_i
sum = 0
max = 1
memory = 0

for i in 1..N
  sum += i
  if sum >= N
    max = i#最大値
    memory = sum - N
    break
  end
end

for i in 1..max
  if i == memory
    next
  else
    puts i
  end
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define MAXN 105
using namespace std;
int a[MAXN];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int minsum=INT_MAX;
    for(int i=a[0];i<=a[n-1];i++)
    {
        int sum=0;
        for(int j=0;j<n;j++)
        {
            sum+=(a[j]-i)*(a[j]-i);
        }
        minsum=min(sum,minsum);
    }
    cout<<minsum;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	int n, a[100005] = { 0 }, a2[100005] = { 0 };

	cin >> n;

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

	int num1 = 0, num2 = 0;
	
	int sum = 0;

	for (i = 0; i <= n; i++) {
		sum = sum + abs(a[i + 1] - a[i]);
	}
	
	for (i = 0; i <= n; i++) {
		

		num1 = abs(a[i + 1] - a[i]) + abs(a[i + 2] - a[i + 1]);
		num2 = abs(a[i+2] - a[i]);
		a2[i] = abs(num2 - num1);


	}


	for (i = 0; i < n; i++) {
		cout << sum - a2[i] << endl;
	}











	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 2048
# https://atcoder.jp/contests/abc158/tasks/abc158_a

read S
one=${S:0:1}
two=${S:1:1}
three=${S:2:1}
if [ $one != $two ] || [ $two != $three ] || [ $three != $one ] ; then
  echo "Yes"
else
  echo "No"
fi



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

public class Main {

	public static void main(String[] args) {
		// AtCoder_C
		Scanner sc = new Scanner(System.in);
		Long ans = (long) 0;

		int N = sc.nextInt();
		String S[] = new String[N];
		char SWK[] = new char[11];

		sc.nextLine();
		for(int i=0; i<N; i++) {
			SWK = sc.nextLine().toCharArray();
			Arrays.sort(SWK);
			S[i] = new String(SWK);

		}

		Arrays.sort(S);

		String nowS = "";
		int indS = 0;

		for(int i=0; i<N; i++) {
			if(nowS.equals(S[i])) {
				ans += (i-indS);
			} else {
				nowS = S[i];
				indS = i;
			}
		}

		System.out.println(ans);

		// Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}

Measured memory_bytes: 67232
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
bool judge(int ans[],string s,int k,int n){
    if(ans[k%n]==1){
        if(s[k%n]=='o' && ans[(k-1)%n]==ans[(k+1)%n]) return true;
        else if(s[k%n]=='x' && ans[(k-1)%n]!=ans[(k+1)%n]) return true;
    }
    else{
        if(s[k%n]=='o' && ans[(k-1)%n]!=ans[(k+1)%n]) return true;
        else if(s[k%n]=='x' && ans[(k-1)%n]==ans[(k+1)%n]) return true;        
    }
    return false;
}
int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    //1が正直者,-1が嘘つき
    int tmpans[n];
    vector<int> init[4] = {{1,1},{-1,1},{1,-1},{-1,-1}};
    rep(i,4){
        fill_n(tmpans,n,0);
        tmpans[0] = init[i][0];
        tmpans[1] = init[i][1];
        for(int j = 1;j<n-1;j++){
            if(tmpans[j]==1){
                if(s[j]=='o') tmpans[j+1]=tmpans[j-1];
                else tmpans[j+1]=(-1)*tmpans[j-1];
            }
            else{
                if(s[j]=='o') tmpans[j+1]= (-1)*tmpans[j-1];
                else tmpans[j+1]=tmpans[j-1];
            }
        }
        if(judge(tmpans,s,n-1,n)&&judge(tmpans,s,n,n)){
            rep(j,n){
                if(tmpans[j]==1) cout << 'S';
                else cout << 'W';
            }
            cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 1024
# B - Box and Ball
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,m=nm()
rb=[False]*n
rb[0]=True
ball=[1]*n
for i in range(m):
    x,y=nm()
    x-=1
    y-=1
    ball[x]-=1
    ball[y]+=1
    if rb[x]==True:
        rb[y]=True
    if ball[x]==0:
        rb[x]=False
ans=0
for r in rb:
    if r:
        ans+=1
print(ans)


Measured memory_bytes: 4596
from bisect import bisect_left

N = int(input())
*A, = map(int, input().split())
A.sort()

if A[0]<=0 and A[-1]<=0:
    ans = sum(map(abs, A[:-1]))+A[-1]
    A.reverse()

    r = 1
    a, b = A[0], A[1]
    t = []
    
    while 1:
        x, y = (a, b) if a>b else (b, a)
        t.append((x, y))
        r += 1
        if not r<N:
            break
        a, b = x-y, A[r]

elif A[0]>=0 and A[-1]>=0:
    ans = sum(A[1:])-A[0]

    r = 1
    a, b = A[0], A[1]
    t = []
    
    while 1:
        x, y = (a, b) if a<b else (b, a)
        t.append((x, y))
        
        r += 1
        if not r<N:
            break
        a, b = x-y, A[r]
    a, b = t[-1]
    t[-1] = (b, a)


else:
    ans = sum(map(abs, A))
    p = bisect_left(A, 0)
    t = []
    s = []

    a = A[p-1]
    for i in range(p, N-1):
        b = A[i]
        t.append((a, b))
        a = a - b
        
    c = A[N-1]
    for i in ([a]+A[:p-1]):
        t.append((c, i))
        c = c-i

print(ans)
for i in t:
    print(*i)

Measured memory_bytes: 20844
// finish date: 2018/07/22
#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)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    int Q, H, S, D;
    int N;
    cin >> Q >> H >> S >> D >> N;
    int one = min({Q * 4, H * 2, S});
    int two = min({Q * 8, H * 4, S * 2, D});
    ll ans = (ll) (N / 2) * two + (ll) (N % 2) * one;
    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31))

typedef struct pair{ll i,c;}P;
int csort(const void*a,const void*b){
	ll p=(*(P*)a).c,q=(*(P*)b).c;
	return p<q?-1:p>q?1:0;
}


P a[200010];
ll flag[100010];
ll cnt[4];
ll n;
int main(){
	scanf("%lld",&n);
	rep(i,0,2*n){
		ll t;
		scanf("%lld",&t);
		a[i].i=i;
		a[i].c=t;
	}
	qsort(a,2*n,sizeof(P),csort);

	ll s=0;
	rep(i,0,n){
		s+=a[i].c;
		flag[a[i].i/2]|=1<<(a[i].i%2);
	}
	rep(i,0,n)cnt[flag[i]]++;

	ll ans=INF;
	
	if(cnt[0]==0&&cnt[1]!=0&&cnt[2]!=0){
		//妥協が必要
		rep(i,n,2*n){
			//i番目を採用する
			//代わりに消せるのは、残りの最大値（ただし相方が選べるのは、もともとのcntが1のときのみ）
			if(a[n-1].i/2==a[i].i/2&&cnt[flag[a[i].i/2]]!=1){
				ans=min(ans,s+a[i].c-a[n-2].c);
			}else{
				ans=min(ans,s+a[i].c-a[n-1].c);
				//これ以上探索する必要はない
				break;
			}
		}
	}else{
		ans=s;
	}
	printf("%lld",ans);
}

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

typedef long long ll;
#define rep(i,n) for( ll (i)=0; (i)<(n); ++(i) )
#define rpi(i,n) for( int (i)=0; (i)<(n); ++(i) )
#define rpv(d) for(auto& v:d)
#if __cplusplus < 201703L
  std::ostream& co_(){ return std::cout << std::endl; }
  std::istream& cn_(){ return std::cin; }
  template<class Head, class... Args>
  std::ostream& co_( Head&& head, Args&&... args ){ std::cout << head; return co_(std::forward<Args>(args)...); }
  template<class Head, class... Args>
  std::istream& cn_( Head&& head, Args&&... args ){ std::cin >> head; return cn_(std::forward<Args>(args)...); }
#else
  template<class... Args>
  std::ostream& co_( Args... args ){ return std::cout << ... << args << std::endl; }
  template<class... Args>
  std::istream& cn_( Args... args ){ return std::cin >> ... >> args; }
#endif
#define co(...) co_(__VA_ARGS__);
#define cn(...) cn_(__VA_ARGS__);
#define all(x) (x).begin(), (x).end()
#define rgt(x,i) (x).begin(), (x).begin()+(i)

int main(){
  int n,r;cn(n,r)
  if (10<=n){
    co(r)
  }else{
    co(r+100*(10-n))
  }
}

Measured memory_bytes: 764
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll gcd(ll a,ll b){return b ? gcd(b, a % b) : a;}
ll lcm(ll a,ll b){return a / gcd(a, b) * b;}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B;
    cin >> A >> B;
    ll ans = lcm(A,B);
    print(ans);

    


}

Measured memory_bytes: 256
#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
my @a;
{
    my $in = <STDIN>;
    @a = split(" ", $in);
}
my $ans = 0;
my $cnt = 1;
for (my $i=0; $i<$n; $i++) {
    if ($cnt==$a[$i]) {
        $cnt++;
    } else {
        $ans++;
    }
}

print "-1\n" if $cnt==1;
print "$ans\n" if $cnt>1;

Measured memory_bytes: 33444
require 'pp'
x = 5.times.each.map {|i| readline.to_i }
x.sort_by! {|d|
  r = d%10
  (r == 0) ? 10 : r
}
sum = 0
x[1..-1].each do |x|
  if x % 10 == 0
    sum += x
  else
    sum += ((x+10)/10)*10
  end
end
puts sum + x[0]


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll t1, t2, r1, r2;
    cin >> t1 >> t2 >> r1 >> r2;

    if(r1 == -1 || r2 == -1) {
        if(t1 == t2) cout << "Draw" << endl;
        else if(t1 < t2) cout << "Alice" << endl;
        else cout << "Bob" << endl;
    } else {
        if(r1 == r2) cout << "Draw" << endl;
        else if(r1 > r2) cout << "Alice" << endl;
        else cout << "Bob" << endl;
    }

    return 0;
}



Measured memory_bytes: 3212
package main

import "fmt"

func delZero(n *int) {
	if *n >= 100 && *n%10 == 0 {
		*n /= 10
		delZero(n)
	}

}
func main() {
	var N int
	fmt.Scan(&N)

	delZero(&N)
	a := N - 1
	sum := 1
	for a >= 1 {
		sum += a % 10
		if a/10 < 1 {
			fmt.Println(sum)
			return
		}
		a /= 10
	}
}

Measured memory_bytes: 512
// https://atcoder.jp/contests/abc156/tasks/abc156_d
// 
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int,int> P;

#define MAX_N 200005
// #define MAX_N 100005


#define M 1000000007
vector<ll> fac(MAX_N); //n!(mod M)
vector<ll> ifac(MAX_N); //k!^{M-2} (mod M)

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1; // n = n/2
    }
    return ans;
}
void init_comb(){
	fac[0] = 1;
	ifac[0] = 1;
	for(ll i = 1; i<MAX_N; i++){
		fac[i] = fac[i-1]*i % M; // n!(mod M)
		ifac[i] = ifac[i-1] * mpow(i, M-2) % M; // k!^{M-2} (mod M)
	}
}
ll combination(ll n,ll m){
	if(m==n || m==0) return 1;
	ll tmp = fac[n] * ifac[m] % M;
	return tmp * ifac[n-m] % M;
}
ll mdev(ll a,ll b){
	return a * mpow(b,M-2) % M;
}
ll msub(ll a,ll b){
	if(a<b){
		a+=M;
		return msub(a,b);
	}
	return (a-b)%M;
}

int main() {
	ll n,a,b;
	cin >> n >> a >> b;
	ll ans=mpow(2,n)-1;
	ll nCa,nCb = 1;
	for(int i=1;i<=b;i++){
		nCb = (nCb * (n+1-i))%M;
		nCb = mdev(nCb,i);
		if(i==a)ans = msub(ans,nCb);
	}
	ans = msub(ans,nCb);
	
	cout << ans << endl;
    return 0;
}



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

string winner(int arr[], int N, int k)
{
	bool dp[k + 1];

	memset(dp, 0, sizeof(dp));

	for (int i = 1; i <= k; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (arr[j] > i)
				continue;
			if (dp[i - arr[j]] == 0)
				dp[i] = 1;
		}
	}
	if (dp[k] == 1)
		return "First";
	else
		return "Second";

}

int main()
{

	int N, K;
	cin >> N >> K;

	int arr[K + 1];

	for (int i = 0; i < K; i++)
		cin >> arr[i];

	cout << winner(arr, N, K);
}

Measured memory_bytes: 3712
#include <cstdio>
#include <map>
#include <cmath>

std::map<long long, long long> prime_factor(long long n)
{
	std::map<long long, long long> r;
	for (long long i = 2; i * i <= n; ++i)
	{
		while (n % i == 0)
		{
			r[i]++;
			n /= i;
		}
	}
	if (n != 1) r[n] = 1;
	return r;
}

int main()
{
  long long n, p;
  scanf("%lld%lld", &n, &p);
  auto mp = prime_factor(p);
  long long ans = 1;
  for (auto &pr : mp)
  {
    if (pr.second >= n) ans *= (long long)std::pow(pr.first, pr.second / n);
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}



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

	string s;
	cin >> s;
	if (s == "SAT") {
		cout << 1 << endl;
	}
	else if (s=="SUN") {
		cout << 7 << endl;
	}
	else if (s=="MON") {
		cout << 6 << endl;
	}
	else if (s=="TUE") {
		cout << 5 << endl;
	}
	else if (s=="WED") {
		cout << 4 << endl;
	}
	else if (s=="THU") {
		cout << 3 << endl;
	}
	else if (s=="FRI") {
		cout << 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 0
for i in range(N - 1):
    p, q = divmod(A[i], 2)
    ans += p
    if q and A[i + 1]:
        A[i + 1] += 1
ans += A[-1] // 2
print(ans)

Measured memory_bytes: 7072
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
strToInt s = (read :: String -> Int) s

main :: IO ()
main = do
    -- スペース区切り整数の入力
    [a, b, c, d] <- map strToInt . words <$> getLine
    let x = (max a c)
    let y = (min b d)
    -- 出力
    putStrLn . show $ if x > y then 0 else y - x


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int sum=0;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            sum+= a[i]*a[j];
        }
    }
    
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[1010][1010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc;

int main(){
    cin>>a>>b>>c>>y;
    if(a>=b)x=b*c+(a-b)*y;
    else x=a*c;
    C x E;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a[5]={1,2,3,4,5};
	for(int i=0;i<5;i++){
		cin>>a[i];
	}
	for(int i=0;i<5;i++){
		if(a[i]==0){
			cout<<i+1;
			exit(0);
		}
	}
	cout<<"no";
	return 0;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int mod = 1e9 + 7;
int dp[8096][4048];
int s[8096];
void add(int &x,int y)
{
    x = x + y;
    if (x >= mod)
        x -= mod;
}
int main(void)
{
    int n,m,k;
    cin>>n>>m>>k;
    dp[0][0] = 1;
    for (int i = 1;i <= 4050;++i)
    {
        s[0] = dp[i - 1][0];
        for (int j = 1;j <= m;++j)
            s[j] = (s[j - 1] + dp[i - 1][j]) % mod;
        for (int j = 0;j <= m;++j)
        {
            add(dp[i][j],s[j]);
            if (j >= k)
                add(dp[i][j],mod - s[j - k]);
        }
    }
    int ans = 0;
    for (int t = 1;t < k;++t)
        for (int i = 0;i <= 4050 / (k - 1);++i)
            for (int j = 0;j <= m;++j)
            {
                const int a = j + t;
                const int b = i * (k - 1) - j + (k - t);
                if (a >= 0 && a <= m && b >= 0 && b <= n && !((m - a) % (k - 1)) && !((n - b) % (k - 1)))
                    add(ans,dp[i][j]);
            }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 65280
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

H, W = MAP()

ans = 0
if H == 1 or W == 1:
    ans = 1
elif W % 2 == 0:
    ans = (W//2) * H
else:
    if H % 2 == 0:
        ans = ((W+1)//2 * (H//2)) + (((W+1)//2-1) * (H//2))
    else:
        ans = ((W+1)//2 * ((H+1)//2)) + (((W+1)//2-1) * (H//2))


print(ans)

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

const int M=10;

int nu[M];

int main()
{
	int n,m; scanf("%d%d",&n,&m);
	int s,c;
	memset(nu,-1,sizeof(nu));
	for(int i=0;i<m;i++)
	{
		scanf("%d%d",&s,&c);
		if(nu[s]==-1||nu[s]==c)
			nu[s]=c;
		else
		{
			printf("-1\n");
			return 0;
		}
	}
	if(nu[1]==-1)
		nu[1]=n==1?0:1;
	if(nu[2]==-1) nu[2]=0;
	if(nu[3]==-1) nu[3]=0;
	if(n!=1&&nu[1]==0)
	{
		printf("-1\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
		printf("%d",nu[i]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ios>//左右揃え
#include<iomanip>//setwで幅指定

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007LL

int main(void) {
    int a, b;
    cin >> a >> b;
    rep(i, 1250) {
        if ((i + 1) * 8 / 100 == a && (i + 1) * 10 / 100 == b) {
            cout << i + 1 << endl;
            exit(0);
        }
    }
    cout << "-1" << endl;
}

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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	string S, T;
	cin >> S >> T;
	int S_len = S.length();
	
	bool ans = false;
	REP(i,S_len){
		S = S.back() + S.substr(0,S_len-1);
		if(S == T) ans = true;
	}
	
	cout << (ans ? "Yes" : "No") << endl;

	return 0;

}


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

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  string s;
  cin >> s;
  rep(i,s.size()){
    cout << 'x';
  }
}
        
    
      
    
      
  
  

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc117/tasks/abc117_c


input_temp = gets.chomp.split(" ")
koma_count = input_temp[0].to_i    # 駒
zahyo_count = input_temp[1].to_i   # 座標

input_temp = gets.chomp.split(" ")
zahyo_position = input_temp.map(&:to_i)

# print "koma_count=",koma_count,"\n"
# print "zahyo_count=",zahyo_count,"\n"
# print "zahyo_position=",zahyo_position,"\n"

# 累積話問題読み

zahyo_position.sort!
kaisa_zahyo_position = []

# 階差
(zahyo_count-1).times do |i|
    kaisa_zahyo_position[i] = (zahyo_position[i+1] - zahyo_position[i]).abs
end

kaisa_zahyo_position = kaisa_zahyo_position.sort.reverse

if kaisa_zahyo_position.size <= (koma_count-1)
    p 0
    exit
end

kaisa_zahyo_position.shift(koma_count-1)

# p kaisa_zahyo_position

puts kaisa_zahyo_position.inject(:+)

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

int main() {
  int w,a,b; cin >> w >> a >> b;
  cout << max(0, abs(a-b)-w) << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC169B
{
    class Program
    {
        static void Main(string[] args)
        {
            long y = 1;
            for (int i = 1; i <= 18; i++)
                y *= 10;
            long n = long.Parse(Console.ReadLine());
            var aa = Console.ReadLine().Split(" ");
            long[] a =new long[n + 1];
            long x;
            int zero = 0;
            for (long i = 1; i <= n; i++)
            {
                a[i] = long.Parse(aa[i - 1]);
                if (a[i] == 0)
                    zero++;
            }
            if (zero == 0)
            {
                x = 1;
                for (long i = 1; i <= n; i++)
                {
                    if (a[i] <= 1000000000000000000 / x)
                        x *= a[i];
                    else
                    {
                        x = -1;
                        break;
                    }
                }

                Console.WriteLine(x);

            }
            else Console.WriteLine("0");
           
        }
    }
}

Measured memory_bytes: 36140