akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

struct Info{
	bool operator<(const struct Info &arg) const{
		return base_year < arg.base_year;
	};

	char name[17];
	int base_year,end_year;
};

void func(int N, int Q){
	Info info[N];
	int tmp1,tmp2;

	for(int i = 0; i < N; i++){
		scanf("%s %d %d",info[i].name,&tmp1,&tmp2);
		info[i].base_year = tmp2-tmp1+1;
		info[i].end_year = tmp2;
	}

	sort(info,info+N);

	bool FLG;
	for(int i = 0; i < Q; i++){
		scanf("%d",&tmp1);

		FLG = false;

		for(int k = 0; k <= N-1; k++){
			if(tmp1 >= info[k].base_year && tmp1 <= info[k].end_year){
				printf("%s %d\n",info[k].name,tmp1-info[k].base_year+1);
				FLG = true;
				break;
			}
		}
		if(!FLG)printf("Unknown\n");
	}
}


int main(){

	int N,Q;

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

		func(N,Q);
	}

	return 0;
}

Measured memory_bytes: 2768
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
ll ord;

ll gcd(ll x, ll y)
{
  if(x<y)
  {
    swap(x,y);
  }
  while(y>0)
  {
    ll r=x%y;
    x=y;
    y=r;
  }
  ord=x;
return 0;
}

int main()
{
  ll A,B,C,D;
  ll ans1;


  cin>>A>>B>>C>>D;
  gcd(C,D);
  A=A-1;
  ans1=B-(B/C+B/D-B/(C/ord*D));

  ans1=ans1+(A/C+A/D-A/(C/ord*D))-A;
  cout<<ans1<<endl;

}

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

using namespace std;
typedef long long int ll;

int main(){
	int n;
	string s;
	cin>>n;
	cin>>s;
	int ans = 0;
	for(int i = 0; i <n; i++){
		set<char> charCount;
		for(int j = 0; j <= i; j++){
			for(int k = i + 1; k < n; k++){
				if( s[j] == s[k]) charCount.insert(s[j]);
			}
		}
		ans = max(ans,(int)charCount.size());
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
	double a,b,c,d,e,f;
	double x,y;
	while(cin >> a >> b >> c >> d >> e >> f){
		y=(d*c-a*f)/(b*d-a*e);
		x=(c-b*y)/a;
		x*=1000;
		x+=0.5;
		x=floor(x);
		x/=1000;
		y*=1000;
		y+=0.5;
		y=floor(y);
		y/=1000;
		cout << fixed << setprecision(3) << x << " " << y << endl;
	}
	return 0; 
}

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

int main() {
  int d;
  cin>>d;
  if(d==25) cout<<"Christmas"<<endl;
  else if(d==24) cout<<"Christmas Eve"<<endl;
  else if(d==23) cout<<"Christmas Eve Eve"<<endl;
  else cout<<"Christmas Eve Eve Eve"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
#define inarr(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define enld endl
int main(){
	int n;
	cin>>n;
	vector<ll>x(n),y(n);
	inarr(x,n);
	y=x;
	sort(y.begin(),y.end());
	int mini=y[n/2-1],maxi=y[n/2];
	for(int i=0;i<n;i++){
		if(x[i]<=mini){
			cout<<maxi<<endl;
		}
		else {
			cout<<mini<<endl;
		}
	}
}


Measured memory_bytes: 5376
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import itertools
I = [int(_) for _ in open(0).read().split()]
N, M, R = I[:3]
r = np.array(I[3:3 + R])
ABC = I[3 + R:]
F = floyd_warshall(csr_matrix((ABC[2::3], (ABC[::3], ABC[1::3])), (N + 1, N + 1)), 0).astype(np.int64)
ans = float('inf')
for root in itertools.permutations(r, R):
    ans = min(ans, sum(F[i,j] for i, j in zip(root, root[1:])))
print(ans)


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

void start() {
	ios::sync_with_stdio(false); cin.tie(0);
	cout<<fixed<<setprecision(10);
}

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define ii pair<int, int>
#define ll long long
#define endl '\n'
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()

int main() {
	start();

	int n; cin>>n;
	int dig = n%10;

	if (dig == 2 ||dig == 4 ||dig == 5 ||dig == 7 ||dig == 9) cout<<"hon";
	else if ( dig == 3) cout<<"bon";
	else cout<<"pon";
}

// by Freyam

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int a,b;

void solve(){
  cin >> a >> b;
  cout << a*b << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 3616
fun main(arr:Array<String>) {
    val (itemCount, maxCount) = readLine()!!.split(" ").map { it.toInt() }
    items.addAll(readLine()!!.split(" ").map { it.toInt() })
    val ans = getAns(0, maxCount, listOf(), 0)
    println(ans)
}

val items = mutableListOf<Int>()
val dic = mutableMapOf<Long, Long>()

fun getAns(key:Long, remain:Int,  minusList:List<Int>, subtotal:Long):Long {
    if(remain <= 0) {
        return subtotal
    }
    if(dic.containsKey(key)) {
        return dic[key]!!
    }
    var ans = subtotal
    for(i in (0 until items.size)) {
        val newKey = 1L shl i;
        if(key.and(newKey) == 0L) {
            val newMinus = mutableListOf<Int>()
            newMinus.addAll(minusList)
            if(items[i] < 0) {
                newMinus.add(items[i])
            }
            ans = Math.max(getAns(key + newKey, remain - 1, newMinus.sorted(), subtotal + items[i]), ans)
            break
        }
    }

    for(i in (0 until  items.size).reversed()) {
        val newKey = 1L shl i;
        if(key.and(newKey) == 0L) {
            val newMinus = mutableListOf<Int>()
            newMinus.addAll(minusList)
            if(items[i] < 0) {
                newMinus.add(items[i])
            }
            ans = Math.max(getAns(key + newKey, remain - 1, newMinus.sorted(), subtotal + items[i]),ans)
            break
        }
    }

    if(remain <= minusList.size) {
        ans = Math.max(ans, subtotal - minusList.take(remain).sum())
    } else if(key == (1L shl items.size) - 1) {
        ans = Math.max(ans, subtotal - minusList.sum())
    }
    dic[key] = ans
    return ans
}


Measured memory_bytes: 40880
using System;
class Program
 {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            int a = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            int b = int.Parse(str[1]);
          	int c = 0;
          
            for (int i = 1; i <= 3; i++) {
            	int x = a * b * i;
              	if (x % 2 == 1) c++;
            }
          
          	if (c > 0) {
            Console.WriteLine("Yes");//改行付き出力
            } else {
            Console.WriteLine("No");
            }
        }
 }

Measured memory_bytes: 11092
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

n, q = map(int, input().split())
uf = UnionFind(n)
for _ in range(q):
    c, x, y = map(int, input().split())
    if c == 0:
        uf.unite(x, y)
    else:
        print(1 if uf.same(x, y) else 0)



Measured memory_bytes: 5720
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    int m = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
        m = max(m, h[i]);
    }

    int count = 0;
    for (int i = 0; i < m; i++)
    {
        bool f = true;
        for (int j = 0; j < n; j++)
        {
            if (h[j] != 0)
            {
                if (f)
                {
                    f = false;
                    count++;
                }
                h[j]--;
            }
            else
            {
                f = true;
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String [] args) {
		
		Scanner scan = new Scanner(System.in);
		int turn;
		int playerA = 0, playerB = 0;
		String playerAcard, playerBcard;
		
		turn = scan.nextInt();
		
		for (int i = 0; i < turn; i++) {
			
			playerAcard = scan.next();
			playerBcard = scan.next();
			
			//判定
			if (playerAcard.compareTo(playerBcard) > 0) {
				playerA += 3;
			} else if (playerAcard.compareTo(playerBcard) == 0){
				playerA += 1;
				playerB += 1;
			} else {
				playerB += 3;
			}
			
		}
		
		scan.close();
		System.out.println (playerA + " " + playerB);
		
		
		
	}
	
}



Measured memory_bytes: 29780
#include<bits/stdc++.h>
using namespace std;
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);

int main(){
    fast
    int n, m;
    cin>>n>>m;
    bool vis[n+5]={false};
    
    vector< pair<int, string> > v;
    int c=0, wa=0;
    
    for(int i=0; i<m; i++){
        int x;
        string a;
        cin>>x>>a;
        v.push_back({x, a});
    }
    int ww[n+1]={0};
    for(int j=0; j<m; j++){
        int y=v[j].first;
        string z=v[j].second;
        
        if(vis[y]==false){
            if(z=="WA") ww[y]++;
            else if(z=="AC"){
                wa+=ww[y];
                c++;
                vis[y]=true;
            }
        }
    }
    
    cout<<c<<" "<<wa;
    return 0;
}


Measured memory_bytes: 7024
#include<bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
ll ceil(ll x,ll y){
    if(x%y==0) return x/y;
    else return x/y+1;
}
int main(){
    ll n;
    cin >> n;
    vector<ll> pas(5);
    rp(i,5) cin >> pas.at(i);
    sort(pas.begin(),pas.end());
    ll group=ceil(n,pas.at(0));
    cout << group+4ll << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    int n; std::cin >> n;
    std::set<std::string> set;
    while (n--) {
        std::string s; std::cin >> s;
        set.insert(s);
    }
    std::cout << set.size() << std::endl;
}

Measured memory_bytes: 19228
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  ll C[N];
  ll p;
  for(int i=0;i<N;++i){
    cin>>p;
    p--;
    C[p] = i;
  }
  ll A[N];
  ll B[N];
  A[0] = 1;
  B[0] = C[0] - A[0];
  for(int i=1;i<N;++i){
    if(C[i]>C[i-1]){
      A[i] = A[i-1] + (C[i] - C[i-1]) + 1;
      B[i] = B[i-1] - 1;
    }
    else{
      A[i] = A[i-1] + 1;
      B[i] = B[i-1] + (C[i] - C[i-1]) - 1;
    }
  }
  ll minB = B[N-1];
  if(minB<=0){
    minB = -minB;
    for(int i=0;i<N;++i){
      B[i] += minB + 1;
    }
  }
  for(int i=0;i<N;++i){
    cout<<A[i]<<" ";
  }
  cout<<endl;
  for(int i=0;i<N;++i){
    cout<<B[i]<<" ";
  }
  cout<<endl;
}


Measured memory_bytes: 4004
#include<stdio.h>
int main(void){
    int x,y,H,W;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0&&W==0) break;
        for(x=0;x<H;x++){
            for(y=0;y<W;y++){
                if(x==0||x==H-1||y==0||y==W-1){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++)

const char nl = '\n';
const int MOD = 1e9 +7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 + 5;


bool comp(pair<string, pair<int, int> > a, pair<string, pair<int, int> > b){
  if(a.fi == b.fi) return a.se.fi > b.se.fi;
    return a.fi < b.fi;
}
int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);

  int n; cin >> n;
  int sum = 0;
  vi v;
  for(int i = 0; i < n; i++){
    int x; cin >> x;
    sum += x;
    v.pb(x);
  }
  int tmp = 0;
  int ans = sum;
  for(int i = 0; i < n; i++){
      tmp+=v[i];
      sum -= v[i];
    ans = min(abs(tmp - sum), ans);
  }
  cout << ans << nl;
return 0;




}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<cctype>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    if(A>B||(N==1&&A!=B))cout << 0;
    else{
        cout << (B-A)*(N-2)+1;
    }
    return 0;
}


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

int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];
    int c=0;
    for(int i =0;i<n;i++)
    {
        cin>>arr[i];
        if(arr[i]>=k)
            c++;
    }
    cout<<c<<endl;






    return 0;
}






Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include "iomanip"
#include <cstdio>
#include <cstring>
#include <set>
#include <vector>
#include <fstream>
#include <algorithm>
#include <queue>
#include <cassert>
#include <stack>


using namespace std;

void print(vector<int> &b);


void print(vector<int> &b) {
    for (auto i : b) {
        cout << i << " ";
    }
    cout << endl;
}


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

    int n;
    unordered_set<string> s;
    string st;
    cin >> n >> st;
    s.insert(st);
    char l = st[st.size() - 1];
    for (int j = 0; j < n - 1; ++j) {
        cin >> st;
        char f =  st[0];
        if (f != l || s.count(st)){
            cout << "No";
            return 0;
        }
        s.insert(st);
        l = st[st.size() - 1];
    }
    cout << "Yes";
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n1,n2,n3,n4,n5;
  cin >> n1 >>n2>>n3>>n4>>n5;
  
  if(n1 == 0) cout << 1<< endl;
  if(n2 == 0) cout << 2<< endl;
  if(n3 == 0) cout << 3<< endl;
  if(n4 == 0) cout << 4<< endl;
  if(n5 == 0) cout << 5<< endl;
  
  
}

Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define forn(i,n) for(int i=0;i<n;i++)
#define free(i,a,b) for(int i = a; i < b; i++)
#define sf(n) scanf("%lld", &n)
#define sff(a,b) scanf("%lld %lld", &a, &b)
#define sfff(a,b,c) scanf("%lld %lld %lld", &a, &b, &c)
#define pfn(n) printf("%lld\n", n)
#define pfs(n) printf("%lld ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define f find
#define ub upper_bound
#define lb lower_bound
#define ld long double
#define in insert
#define bs binary_search
#define le length()
const ll max_i=1e9+7;
#define np(s) next_permutation(s.begin(),s.end())
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
//it gives the lexicographically smallest string//


void solve()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 ll x,k,d;
 cin>>x>>k>>d;
 x=abs(x);
 ll r=x%d;
 if(r==0) 
 {
  if(k<x/d) cout<<x-k*d;
  else if(k==x/d) cout<<0;
  else 
  {
    if((k-(x/d))%2==0) cout<<0;
    else cout<<d;
  }
 }
 else
 {
  if(k<x/d) cout<<x-k*d;
  else
  {
        if(r<=d-r) 
        {
          if((k-(x/d))%2==0) cout<<r;
          else if(k-((x/d)+1)>=0) cout<<d-r;
          else cout<<r+d;
        }
        else if(k==x/d) cout<<r;
        else
        {
          if((k-((x/d)+1))%2==0) cout<<d-r;
          else cout<<r;
        }
  }
 }
}
int main()
{
  #ifndef ONLINE_JUDGE
  freopen("input1.txt", "r",stdin);
  freopen("output1.txt","w",stdout);
  #endif
  solve();
  return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string s;
int main(){
	cin >> s;
	if(s == "Sunny") puts("Cloudy");
	else if(s == "Rainy") puts("Sunny");
	else if(s == "Cloudy") puts("Rainy");
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 200000

int main(){

  int i;
  int j;
  int n;
  int minv;
  int maxv =-2000000000;
  int data[N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
  }

  minv = data[0];

  for(i=1;i<n;i++){
    if(maxv < data[i]-minv){
      maxv = data[i]-minv;
    }
    if(minv >data[i]){
      minv = data[i];
    }
  }

  printf("%d\n",maxv);
  
  return 0;
}

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

int main() {
  ll X;
  cin >> X;
  ll sita=X%500ll;
  cout << ((X/500ll)*1000ll+(sita/5ll)*5ll) << endl;
  return 0;
}

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


const ll MOD = 1e9 + 7;
template<ll MOD> struct ModInt {
    ll value;
    ModInt() : value(0) {}
    ModInt(const ll& v) : value(v % MOD) {
        if ( value < 0 ) value += MOD;
    }
    ModInt<MOD>& operator=(const ModInt& o) {
        value = o.value;
        return *this;
    }
    inline bool operator==(const ModInt& o) {
        return value == o.value;
    }
    inline bool operator!=(const ModInt& o) {
        return value != o.value;
    }
    ModInt<MOD>& operator+=(const ModInt& o) {
        value += o.value;
        if ( value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator-=(const ModInt& o) {
        value += MOD - o.value;
        if (value >= MOD ) value -= MOD;
        return *this;
    }
    ModInt<MOD>& operator*=(const ModInt& o) {
        value *= o.value;
        value %= MOD;
        return *this;
    }
    ModInt<MOD>& operator/=(const ModInt& o) {
        value *= inverse(o.value);
        value %= MOD;
        return *this;
    }
    ModInt<MOD> operator-() {
        return ModInt<MOD>(-value);
    }
    ModInt<MOD> operator+(const ModInt& o) {
        ModInt<MOD> r(*this);
        r += o;
        return r;
    }
    ModInt<MOD> operator-(const ModInt& o) {
        ModInt<MOD> r(*this);
        r -= o;
        return r;
    }
    ModInt<MOD> operator*(const ModInt& o) {
        ModInt<MOD> r(*this);
        r *= o;
        return r;
    }
    ModInt<MOD> operator/(const ModInt& o) {
        ModInt<MOD> r(*this);
        r /= o;
        return r;
    }
    ModInt<MOD> pow(ll n) {
        ModInt<MOD> t(*this), r = 1;
        while ( n > 0 ) {
            if ( n & 1 ) r *= t;
            t *= t;
            n >>= 1;
        }
        return r;
    }
private:
    ll inverse(ll a) {
        ModInt<MOD> t(a);
        return t.pow(MOD - 2).value;
    }
};
template<ll MOD> std::ostream& operator<< (std::ostream& os, const ModInt<MOD>& o) {
    os << o.value;
    return os;
}
template<ll MOD> std::istream& operator>> (std::istream& is, ModInt<MOD>& o) {
    is >> o.value;
    return is;
}

using Int = ModInt<MOD>;

ll solve() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    vector<vector<Int>> dp(N+1, vector<Int>(K+1));
    dp[0][0] = 1;
    for ( int j = 1; j <= N; j++ ) {
        Int s = 0;
        for ( int k = 0; k <= K; k++ ) {
            s += dp[j-1][k];
            if ( k-A[j-1]-1 >= 0 ) s -= dp[j-1][k-A[j-1]-1];
            dp[j][k] = s;
        }
    }
    return dp[N][K].value;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

int main() {
    int k, n;
    cin >> k >> n;
    auto a = vector<int>(n);
    for (auto &a_i : a)
        cin >> a_i;
    sort(a.begin(), a.end());
    auto copy = a;
    a.insert(a.end(), copy.begin(), copy.end());
    for (auto i = n; i < 2 * n; ++i)
        a[i] += k;
    auto dist = vector<int>(2 * n);
    for (auto i = 1; i < 2 * n; ++i)
        dist[i] = a[i] - a[i - 1];

    // start==0
    auto sum = accumulate(dist.begin() + 1, dist.begin() + n, 0);
    auto minsum = sum;

    // start>=1
    for (int start = 1; start <= n; ++start) {
        auto last = start + (n - 1);
        sum = sum - dist[start] + dist[last];
        minsum = min(minsum, sum);
    }

    cout << minsum;
    return 0;
}


Measured memory_bytes: 4208
using System;
class Program
{
    public static void Main()
    {
        string str = Console.ReadLine();
        int count = 0;
        for (int i = 0; i < 3; i++)
            if (1 == (int)Char.GetNumericValue(str[i]))
                count++;
        Console.WriteLine(count);
    }
}

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

using namespace std;

int main() {
//#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//#endif
	int n;
	cin >> n;
	if (n % 10 == 9 || n / 10  == 9) {
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}


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

    cin >> N;

    N %= 10;


    if(N == 3) cout << "bon" <<  endl;
    else if(N == 0 || N == 1 || N == 6 ||N == 8  ) cout << "pon" <<endl;
    else cout << "hon" << endl;


}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <unordered_map>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

bool is_equal(const int* a, const int* b, int n){
    rep(i,n){
        if( *(a + i) != *(b + i) ){
            return false;
        }
    }
    return true;
}

int main(){
    int n;
    cin >> n;
    int p[n], q[n], standard[n];
    rep(i,n){
        cin >> p[i];
        standard[i] = i + 1;
    }

    int p_order = 0, q_order = 0;
    do{
        if( is_equal(p, standard, n) ){
            break;
        }
        p_order++;
    }while (next_permutation(standard, standard+n));
    
    rep(i,n){
        cin >> q[i];
        standard[i] = i + 1;
    }
    do{
        if( is_equal(q, standard, n) ){
            break;
        }
        q_order++;
    }while (next_permutation(standard, standard+n));

    cout << abs(p_order - q_order) << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define pii std::pair<int,int>
#define pli std::pair<ll,int>
#define pil std::pair<int,ll>
#define psi std::pair<string,int>
#define pll std::pair<ll,ll>
#define pci std::pair<char,int>
#define sll(x) scanf("%lld",&x)
#define prll(x) printf("%lld ",x)
#define pri(x) printf("%d ",x)
#define si(x) scanf("%d",&x)
#define pb push_back
#define vll std::vector<ll>
#define vpi std::vector<std::pair<int,int>>
#define vi std::vector<int>
#define vvi std::vector<std::vector<int>>
#define vvpil std::vector<std::vector<std::pair<int,ll>>>
#define vlpii std::vector<std::list<pii>>
#define vlpil std::vector<std::list<pil>>
#define li std::list<int>
#define lpil std::list<pil>
#define Endl printf("\n")
#define vli vector<list<int>>
#define vvll vector<vector<ll>>
#define mp make_pair
#define x first
#define y second
#define ull uint64_t
#define ma 100000000
#define imie(...) "[" << #__VA_ARGS__": " << (__VA_ARGS__) << "] "
const ll  INF=10000000000000;
const ll mod =  1e9 + 7;
using namespace std;
void add(ll& a , ll b){
	a += b;
	if(a >= mod) a -= mod;
}
ll mul(ll a , ll b){
	return (a * b) % mod;
}
ull Pow(ull a , ull b){
	if(b == 0) return 1 ;
	ull c = Pow(a , b / 2) ;
	if(b % 2) return (a * ((c * c) % mod)) % mod;
	return (c * c) % mod ;
}

int main(){
	IOS;
	cout.precision(30) ;
	int n ; cin >> n ;
	vll d(n) ; for(int i = 0 ; i < n ; i++) cin >> d[i] ;
	sort(d.begin() , d.end()) ;
	cout << d[n / 2] - d[n / 2 - 1] <<endl ;
	return 0;
}


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

int main(void){
    string s, t, r;
    cin >> s;
    cin >> t;
    int count = 0;
    int ans = 0;
    while(count <= s.length()){
        r = s.substr(count, s.length()-count)+s.substr(0, count);
        if(r==t)
            ans++;
        count++;
    }
    if(ans != 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

int int_compare(const int* a, const int* b)
{
    if (*a < *b) {
        return 1;
    }
    if (*a > *b) {
        return -1;
    }
    return 0;
}

int main(void)
{
    int n;
    scanf("%d", &n);

    int a[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

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

    qsort(sorted, n, sizeof(int), (int (*)(const void*, const void*))(*int_compare));

    int max = sorted[0];
    int second_max = sorted[1];

    for (int i = 0; i < n; i++) {
        printf("%d\n", a[i] == max ? second_max : max);
    }
    return 0;
}


Measured memory_bytes: 3120
def gcd(a,b):
    return a if b==0 else gcd(b,a%b)

n=int(input())
a=list(map(int,input().split()))
l = [0]*(n+1)
r = [0]*(n+1)
for i in range(1,n+1):
    l[i] = gcd(l[i-1],a[i-1])
for i in range(n-1,0,-1):
    r[i] = gcd(r[i+1],a[i])

ans = 1

for i in range(n):
    ans = max(ans, gcd(l[i],r[i+1]))
print(ans)

Measured memory_bytes: 14052
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		HashMap<Integer, int[]> map = new HashMap<Integer, int[]>(); 
		while( !s.equals("") ) {
			String[] vs = s.split(",");
			int id = Integer.parseInt(vs[0]);
			if( map.containsKey(id) ) {
				int[] tmp = map.get(id); tmp[0]++;
				map.put(id, tmp);
			}
			else {
				int[] tmp = new int[2]; tmp[0]++;
				map.put(id, tmp);
			}
			s = sc.nextLine();
		}
		while( sc.hasNext() ) {
			s = sc.nextLine();
			String[] vs = s.split(",");
			int id = Integer.parseInt(vs[0]);
			if( map.containsKey(id) ) {
				int[] tmp = map.get(id); tmp[1]++;
				map.put(id, tmp);
			}
		}
		LinkedList<int[]> ans = new LinkedList<int[]>();
		for(Map.Entry<Integer, int[]> entry: map.entrySet()) {
			int[] tmp = entry.getValue();
			if(tmp[0] > 0 && tmp[1] > 0) ans.add( new int[] {entry.getKey(), tmp[0]+tmp[1] } );
		}
		Collections.sort(ans, new Comp());
		for(int[] a: ans) System.out.println(a[0] + " " + a[1]);
		
	}
	
	class Comp implements Comparator<int[]> {

		@Override
		public int compare(int[] o1, int[] o2) {
			// TODO 自動生成されたメソッド・スタブ
			return o1[0] - o2[0];
		}
		
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 11000
#include <iostream>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <utility>
    #include <functional>
     
    using namespace std;
     
    int main() {
    	long long n, m;
     
    	cin >> n >> m;
    	if (n >= m) {
    		cout << m / 2 << endl;
    	}
    	else {
    		if (n * 2 >= m) {
    			cout << m / 2 << endl;
    		}
    		else {
    			cout << n + (m - n * 2) / 4 << endl;
    		}
    	}
     
    	return 0;
    }

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

typedef long long int ll;
using namespace std;


int main(){
    int a, b;
    int data[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    cin >> a >> b;
    cout << (data[a] == data[b] ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <map>
#include <stack>
using namespace std;

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


int main() {
int r[8]={1,10,100,1000,10000,100000,1000000,10000000};

int q,n,ans;
cin>>q;
for(int z=0;z<q;z++){
ans=0;
cin>>n;
while(n>=10){
int m=0;
for(int i=1;i<7;i++){
if((n%(r[i]))*(n/(r[i]))>m) m=(n%(r[i]))*(n/(r[i]));

}
n=m;
ans++;


}
cout<<ans<<endl;

}

	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Sieve of Eratosthenes
//-------------------------------------------------
class Sieve
{
private:
    ::std::vector<bool> prime;
public:
    Sieve(int n):prime(n+1, true){
        prime[0] = prime[1] = false;
        for(int i=2; i*i<=n; i++){
            if (!prime[i]) continue;
            for(int j=i*2; j<=n; j+=i){
                prime[j] = false;
            }
        }
    }
    bool isprime(int x){return prime[x];}
};

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    Sieve sieve(55555);
    vi ans;
    for(int i=2; i<=55555; i+=5){
        if (sieve.isprime(i)){
            ans.pb(i);
            if (ans.size()==n) break;
        }
    }
    rep(i,ans.size()){
        if (i>0) cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;
    return 0;
}


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

const int MAX_N = 110000;
const int MAX_M = 220000;
std::vector<int> edge[MAX_N];
std::vector<int> costs(MAX_N, MAX_M);
std::vector<int> ans(MAX_N, -1);

void dijkstra()
{
    auto compare = [&](int a, int b)
    {
        return costs[a] > costs[b];
    };
    std::priority_queue<int, std::vector<int>, decltype(compare) > que {compare};
    que.push(0);
    costs[0] = 0;
    ans[0] = 0;
    while(!que.empty())
    {
        int from = que.top();
        que.pop();
        for (auto to: edge[from])
        {
            if (costs[from] + 1 < costs[to])
            {
                costs[to] = costs[from] + 1;
                ans[to] = from;
                que.push(to);
            }
        }
    }
    return;
}
int main()
{
    int n, m;
    std::cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        int a, b;
        std::cin >> a >> b; --a; --b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    dijkstra();
    std::cout << "Yes" << std::endl;
    for (int i = 1; i < n; ++i)
    {
        std::cout << ans[i] + 1 << std::endl;
    }
    return 0;
}

Measured memory_bytes: 11136
import java.util.*;
 
public class Main{

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

        Map<Integer, Integer> map = new HashMap<>();
        int N = sc.nextInt();
        for(int i = 0; i < N; i++){
            int a = sc.nextInt();
            if(map.containsKey(a))
                map.put(a, map.get(a)+1);
            else
                map.put(a, 1);
        }
        sc.close();
        int count = 0;
        for(Integer key: map.keySet()){
            if(map.get(key) % 2 == 1)
                count++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 63136
#include <stdio.h>


int main (void) {
    int N, m[10][10], x, v, r, c, dr, dc;

    for (x = 1; scanf("%d\n", &N) != EOF && N; x++) {
        r = 0;
        c = 0;
        dr = -1;
        dc = 1;
        for (v = 1; v <= N * N; v++) {
            if (r >= N) {
                r -= 1;
                c += 2;
                dr *= -1;
                dc *= -1;
            }
            else if (c >= N) {
                r += 2;
                c -= 1;
                dr *= -1;
                dc *= -1;
            }
            else if (r < 0) {
                r += 1;
                dr *= -1;
                dc *= -1;
            }
            else if (c < 0) {
                c += 1;
                dr *= -1;
                dc *= -1;
            }
            m[r][c] = v;
            r += dr;
            c += dc;
        }

        printf("Case %d:\n", x);
        for (r = 0; r < N; r++) {
            for (c = 0; c < N; c++) {
                printf("%3d", m[r][c]);
            }
            puts("");
        }

    }
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

ll N;
vector<ll> A, B;

vector<ll> C;
vector< pair<ll, ll> > sub; // first: B[i] - A[i] second: i

ll solve() {
    ll sum_a = 0, sum_b = 0;        // 総和
    vector<ll> remain;              // 条件を満たしていない C のインデックス
    // C と sub の作成
    REP(i, N) {
        C.push_back(A[i]);
        sum_a += A[i];
        sum_b += B[i];
        if(B[i] - A[i] > 0) { remain.push_back(i); }
        if(A[i] - B[i] > 0) {
            sub.push_back(make_pair(A[i] - B[i], i));
        }
    }
    // 総和が負けてるなら無理
    if(sum_a < sum_b) { return -1; }
    if(remain.size() == 0) { return 0; }

    sort(sub.begin(), sub.end(), greater< pair<ll, ll> >());
    // 差が大きいやつから余剰を分配
    for(auto& s : sub) {
        ll val = s.first;
        ll ind = s.second;

        while(val > 0 && remain.size() > 0) {
            ll c_ind = remain[remain.size()-1];
            remain.pop_back();
            ll c_need = B[c_ind] - C[c_ind];     // 条件を満たすために必要な値
            if(c_need <= val) {
                C[c_ind] += c_need;
                val -= c_need;
            }
            else {
                C[c_ind] += val;
                val = 0;
                remain.push_back(c_ind);
            }
        }
        C[ind] = B[ind] + val;
        if(remain.size() == 0) { break; }
    }
    // ret の作成
    ll ret = 0;
    REP(i, N) {
        if(A[i] != C[i]) { ret++; }
    }
    return ret;
}

signed main()
{
    cin >> N;
    A.resize(N);
    REP(i, N) { cin >> A[i]; }
    B.resize(N);
    REP(i, N) { cin >> B[i]; }
    ll ans = solve();
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4292
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
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); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int H, W, h, w;

int main(){
    INIT;
    cin >> H >> W >> h >> w;
    cout << H * W - h*W - H*w + h*w << endl;
}

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

const int MAX_N = (int)2e5 + 5;
int dist[MAX_N];
vector<int> G[MAX_N];

void dfs(int s, int p, int d){
    dist[s] = d;
    for(auto u : G[s]){
        if(u != p) dfs(u, s, d+1);
    }
}

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N; cin >> N;
    for(int i=0;i<N-1;i++){
        int a, b; cin >> a >> b;
        G[a-1].push_back(b-1); G[b-1].push_back(a-1);
    }

    dfs(0, -1, 0);
    int idx = distance(dist, max_element(dist, dist+N));
    for(int i=0;i<N;i++) dist[i] = 0;
    dfs(idx, -1, 0);
    int r = *max_element(dist, dist+N);
    if(r%3==1) cout << "Second" << endl;
    else cout << "First" << endl;
    return 0;
}

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

using namespace std;

#define ll long long 
#define forn(i,n) for(int i = 0;i<int(n);i++)

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

int gcd(int a,int b,int c){
    int ab = gcd(a,b);
    return gcd(ab,c);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    ll ans=0;
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=n;j++){
            for(int k =1;k<=n;k++){
                long long  a=gcd(i,j,k);
                ans+=a;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    int res=0;
    int mini=mod;
    int cnt=0;
    for(auto it:a){
        if(it<0)cnt++;
        res+=abs(it);
        mini=min(mini,abs(it));
    }
    if(cnt%2==0)cout<<res<<endl;
    else cout<<res-2*mini<<endl;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
string strd(int n){
    string x;
    while(n){
        int d=n%10;
        x+=(d+'0');
        n/=10;
    }
    reverse(x.begin(),x.end());
    return x;
}
void digit()
{
    cin>>s;
    ll sum=0;
    for(int i=0;i<s.size();i++){
        char a=(char)s[i];
        int d=(int) a-'0';
        sum+=d;
    }
    if(sum%9==0)cout<<"Yes\n";
    else cout<<"No\n";
}
int main()
{
    string s;
    cin>>s;
    int cnt=0;
    if(s[1]=='R')cnt++;
    if(cnt)
    {
        if(s[0]=='R')cnt++;
        if(s[2]=='R')cnt++;
        cout<<cnt<<endl;
    }
    else if(s[0]=='R'||s[2]=='R')cout<<1<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 3616
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  int count = 0;
  map<int,int>m;
  rep(i,n){
    ll s;
    cin >> s;
    m[s]++;
    if(m[s]==2) m[s]=0;
  }
  for (auto p:m){
    if(p.second == 1 ){
      count ++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 4992
n,*h=map(int,open(0).read().split());a=[0]+[abs(h[1]-h[0])]+[0]*(n-2)
for i in range(2,n):
    a[i]=min(a[i-1]+abs(h[i]-h[i-1]),a[i-2]+abs(h[i]-h[i-2]))
print(a[-1])

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

int main() {
   int n;
   cin >> n;
   pair<pair<string,int>,int> P[105];
   for(int i=1;i<=n;i++){
      string s; int p;
      cin >> s >> p;
      P[i]={{s,-p},i};
   }
   sort(P,P+n+1);
   for(int i=1;i<=n;i++)
   cout << P[i].second << endl;
}

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

int main(){
  string data1,data2;
  cin>>data1;
  cin>>data2;
  int flag=1;
  if(data1.size()>data2.size()){
    cout<<"GREATER"<<endl;
  }
  else if(data1.size()<data2.size()){
    cout<<"LESS"<<endl;
  }
  else if(data1.size()==data2.size()){
    for(int i=0;i<data1.size();i++){
      if(data1[i]>data2[i]){
        flag=0;
        cout<<"GREATER"<<endl;
        break;
      }
      else if(data1[i]<data2[i]){
        flag=0;
        cout<<"LESS"<<endl;
        break;
      }
    }
    if(flag==1){
      cout<<"EQUAL"<<endl;
    }
  }
}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define PI (3.141592653589793238462643383279502884197169399375105820974944)
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define PDB pair<db,db>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 650555;
const int L = 21;
const int M = 2155;
const int K = 555;

void solve() {
    int n;
    cin >> n;

    ll sum = 0;
    for (int i = 1; i <= n; i++){
        if (i % 3 != 0 && i % 5 != 0) sum += i;
    }

    cout << sum;

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

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

using namespace std;

//kごとに1から辿っていって数える？
//上はkを固定してその後iを固定している(?)固定するものの視点を変えてみる
//(editorial)(i,j)を固定して最短距離を効率的に求める
//min(|j-i|,|X-i| + 1 + |j-Y|,|Y-i|+1+|X-j|)

int main(void){
  int N,X,Y;
  int k;
  cin >> N >> X >> Y;
  int a[N];
  for(int i=0;i<N;i++){
    a[i] = 0;
  }
  for(int i=1;i<=N-1;i++){
    for(int j=i+1;j<=N;j++){
      k = min(min(abs(j-i),abs(X-i)+1+abs(j-Y)),abs(Y-i)+1+abs(X-j));
      a[k]++;
      //cout << "i:" << i << " j:" << j << " k:" << k <<endl;
    }
  }

  for(int i=1;i<N;i++){
    cout << a[i] << endl;
  }

  return 0;
}


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

inline long long read()
{
    long long x = 0, f = 1;
    char c = getchar();
    while (!std::isdigit(c))
    {
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while (std::isdigit(c))
        x = x * 10 + c - '0', c = getchar();
    return x * f;
}

long long n, k;

int main()
{
    n = read(), k = read();
    if (k % 2)
    {
        long long ans = (long long)n / k;
        ans = ans * ans * ans;
        printf("%lld\n", ans);
    }
    else if (k % 2 == 0)
    {
        long long ans = (long long)n / k;
        long long ans2 = ans;
        (n % k >= k / 2) ? ++ans2 : 0;
        ans = ans * ans * ans;
        ans2 = ans2 * ans2 * ans2;
        printf("%lld\n", ans + ans2);
    } 
    return 0;
}

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

class B
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        long sum = 0;
        for (int i = 0; i < N; i++)
        {
            sum += A[i];
        }

        long minVal = A[0];
        int minIndex = 0;
        long sum2 = A[0];
        for (int i = 1; i < N - 1; i++)
        {
            sum2 += A[i];
            if (Math.Abs(minVal - sum / 2) > Math.Abs(sum2 - sum / 2))
            {
                minVal = sum2;
                minIndex = i;
            }
        }

        Console.WriteLine(Math.Abs(minVal * 2 - sum));
    }
}

Measured memory_bytes: 31580