akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Scanner;
class Main{

	
	static char[][] map;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力



		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] l = new int[n];
		for(int i = 0;i < n;i++){
			l[i] = sc.nextInt();
		}
		int ans = 1;
		int current = 0;
		int i = 0;
		
		while(current <= x){
			
			if(i < n && current + l[i] <= x){
				ans++;
				current += l[i++];
				
			}else{
				break;
			}
		}
		
		System.out.println(ans);
		
		
	}
	
	static int rsearch(int y,int x){
		
		int count = 0;
		while(x < map[0].length && map[y][x] != '#'){
			count++;
			x++;
		}
		return count;	
		
	}

	static int csearch(int y,int x){
		
		int count = 0;
		while(y < map.length && map[y][x] != '#'){
			count++;
			y++;
		}
		return count;	
	}


	static boolean checkswitch(int bit,int[] k,ArrayList<ArrayList<Integer>> list,int[] p,int m){

		//		System.out.println("bit " + bit);

		for(int i = 0;i < m;i++){

			ArrayList<Integer> sub = list.get(i);
			int onnum = 0;						//onの数
			for(int j = 0;j < sub.size();j++){
				//				System.out.println("sub "+ sub.get(j));
				if((bit & (1 << sub.get(j))) != 0){				//目的のスイッチがついているか
					onnum++;
					//					System.out.println("on  ");
				}

			}
			if(onnum % 2 != p[i]){				//一個でも電球がつかなかったらout
				return false;
			}

		}


		return true;

	}

	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}





}



class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  otherpair.end - end;
	}
}




Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        long a = sc.nextLong();
		String s = sc.next();
                if(a<3200)
                {
                    System.out.println("red");
                }
                else
                {
                    System.out.println(s);
                }
    }
   
}


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

int main(){
	int j;
	double a,s,n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> a;
		s+=a/n;
	}
	j=s;
	cout << j << "\n";
	
	
return 0;
}

Measured memory_bytes: 1224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();

		int[] h = new int[N];
		for(int i=0; i<N; i++){
			h[i] = sc.nextInt();
		}
		int ans = 0;
		for (int i=0; i<N; i++){
			if (h[i] >= K){
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 49988
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	static long MOD = 1000000007;
	static Long dp[][];

	static long getWays(ArrayList<Integer> tree[], int curr, int par, int color)
	{
		if(tree[curr].size()==1 && tree[curr].get(0)==par)
		{
			return 1;
		}

		if(dp[curr][color]!=null)
			return dp[curr][color];

		long temp=1;

		if(color==1)
		{
			for(int ch: tree[curr])
			{
				if(ch==par)
					continue;
				temp *= getWays(tree, ch, curr, 0);
				temp = temp%MOD;
			}
		}
		else
		{
			for(int ch: tree[curr])
			{
				if(ch==par)
					continue;
				temp *= (getWays(tree, ch, curr, 0)%MOD + getWays(tree, ch, curr, 1)%MOD);
				temp = temp%MOD;
			}
		}
		return dp[curr][color]=temp;
	}

	public static void main(String[] args)
	{
		FastReader scan=new FastReader();
		int n=scan.nextInt();
		ArrayList<Integer> tree[]=new ArrayList[n];
		for(int i=0;i<n;i++)
			tree[i]=new ArrayList<>();

		for(int i=0;i<n-1;i++)
		{
			int u=scan.nextInt()-1;
			int v=scan.nextInt()-1;

			tree[u].add(v);
			tree[v].add(u);
		}

		dp=new Long[n][2];
		long ans = getWays(tree, 0, -1, 0)%MOD + getWays(tree, 0, -1, 1)%MOD;
		ans = ans%MOD;

		System.out.println(ans);

	}


static class FastReader
{
    BufferedReader br;
    StringTokenizer st;
 
    public FastReader()
    {
        br = new BufferedReader(new
                InputStreamReader(System.in));
    }
 
    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
 
    int nextInt()
    {
        return Integer.parseInt(next());
    }
 
    long nextLong()
    {
        return Long.parseLong(next());
    }
 
    double nextDouble()
    {
        return Double.parseDouble(next());
    }
 
    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}



}


Measured memory_bytes: 76536
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

const int MAX_N = 101;
const int INF = 1e+8;
typedef pair<int,int> P;

vector<int> G[MAX_N];

void init(){
	for(int i=0 ; i < MAX_N ; i++ ) G[i].clear();
}

void add_edge(int u, int v ){
	G[u].push_back( v );
}

int solve(int s, int g, int t){
	bool memo[MAX_N];
	for(int i=0 ; i < MAX_N ; i++ ) memo[i] = false;
	queue<P> q;
	q.push( P(0,s) );
	
	while( !q.empty() ){
		int cnt = q.front().first;
		int v = q.front().second;
		q.pop();
		memo[v] = true;
		
		if( v == g ){
			return cnt+1;
		}
		
		for(int i=0 ; i < G[v].size() ; i++ ){
			int to = G[v][i];
			if( cnt+1 < t && !memo[to] ){
				q.push( P(cnt+1,to) );
			}
		}
	}
	return INF;
}

int main(){
	int n;
	while( cin >> n ){
		init();
		
		for(int i=0 ; i < n ; i++ ){
			int u, k;
			cin >> u >> k;
			for(int j=0 ; j < k ; j++ ){
				int v;
				cin >> v;
				add_edge( u , v );
			}
		}
		int p;
		cin >> p;
		for(int j=0 ; j < p ; j++ ){
			int s, g, t;
			cin >> s >> g >> t;
			int ans = solve( s , g , t );
			if( ans == INF )
				cout << "NA" << endl;
			else
				cout << ans << endl;
		}
	}
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        List<String> list01 = new ArrayList<String>(Arrays.asList("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"));
        String arr01[] = mylist.get(0).split(" ");
        String s = arr01[0];

        System.out.println(list01.indexOf(s) == 0 ? 7 : 7 - list01.indexOf(s));

    }

}

Measured memory_bytes: 22740
/*
author: orthodoxparadox
01-Sep-2018
17:37:36
*/

#include <bits/stdc++.h>

using namespace std;
#define dbl long double
#define int ll
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define fup(i, a, n) for (ll i = a; i < n; i++)
#define fdw(i, a, n) for (ll i = n-1; i >= a; i--)
#define fnu for(ll i = 0; i < n; i++)
#define fnd for(ll i = n-1; i >= 0; i--)
#define fau(i, v) for(auto i:v)
#define rev(s) reverse(all(s))
#define oill ostream_iterator<ll>(cout, " ")
#define oiint ostream_iterator<int>(cout, " ") 
#define pb emplace_back
#define push_back emplace_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define zero(a) memset(a, 0, sizeof(a))
#define onlyunique(v) v.erase(unique(all(v)), v.end()); //only for sorted vector
// #define x real()
// #define y imag()
typedef complex<double> point;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef __APPLE__
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << " : " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);
}
#else
#define dbg(...)
#endif

int __gcd(int a, int b)
{
	return b ? __gcd(b, a%b) : a;
}

// for set of pairs
struct pair_hash {
    inline std::size_t operator()(const std::pair<int,int> & v) const {
        return v.first*31+v.second;
    }
};

const int mod = 1e9 + 7;

vector<int> binarycut(int x){
	vector<int> v;
	while(x){
		if(x&1) v.pb(1);
		else v.pb(0);
		x>>=1;
	}
	reverse(all(v));
	return v;
}

int takemod(int a){
	return ((a%mod)+mod)%mod;
}

int fast_exp(int base, int expo) {
	int res=1;
	while(expo>0) {
		if(expo&1) res=(res*base)%mod;
		base=(base*base)%mod;
		expo>>=1;
	}
	return res;
}

int modinv(int a){
	return takemod(fast_exp(takemod(a), mod-2));
}

// void siev(int n)
// {
// 	sieve[0]=false;
// 	sieve[1]=false;
// 	for(int i=2; i<=sqrtl(n); i++)
// 	{
// 		if(sieve[i])
// 		{
// 			for(int j=i; i*j<=n; j++)
// 			{
// 			sieve[i*j]=false;
// 			}
// 		}
// 	}
// }

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	#ifdef __APPLE__
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
	#endif
	time_t t1, t2;
	t1 = clock();

	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int a = x2-x1;
	int b = y2-y1;
	int x3, y3, x4, y4;
	x3 = x2-b;
	y3 = y2+a;
	x4 = x3 - a;
	y4 = y3 - b;
	cout << x3 << " " << y3 << " " << x4 << " " << y4;

	t2 = clock();
	cerr << "time taken: " << t2-t1;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>//Graph I - Graph
// G=(V,E) ?????¨?????????????????£??\?????????(adjacency list) ???????????¨?????¨
// ??£??\??????(adjacency matrices)???????????¨????????????????????? 
 
void print();

int n,i,j;
int Adj[100][100];

int main() {
  
  int u,k,v;
  
  scanf("%d",&n);//??????????????? G ???????????° n ????????????????????????
  
  for( i=0 ; i<n ; i++ )
    for( j=0 ; j<n ; j++ )
      Adj[i][j] = 0;
 
  for( i=0 ;  i<n ; i++ ){
    scanf("%d%d", &u, &k);//????????? u ?????£??\????????? Adj[u] ?????\????????¢?????§????????????????????? 
    for( j=0 ; j<k ; j++ ) {
      scanf("%d", &v);
      Adj[i][v-1] = 1;
    }
  }
  print();
  
  return 0;
}

void print() {
  for( i=0 ; i<n ; i++ ){
    for( j=0 ; j<n ; j++ ) {
      printf("%d", Adj[i][j]);
      if(j != n-1) printf(" ");
    }
    printf("\n");
  }
}

 

Measured memory_bytes: 636
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	
	vector<int> num(5);
	for(int i = 0; i < 5; i++){
		cin>>num[i];
	}
	int m=10,pos=-1;
	for(int i = 0; i < 5; i++){
		if(num[i]%10<m && num[i]%10!=0){
			m=num[i]%10;
			pos=i;
		}
	}
	int ans=0;
	for(int i = 0; i < 5; i++){
		if(i!=pos){
			ans+=num[i];
			if(num[i]%10!=0) ans+=10-(num[i]%10);
		}
	}
	ans+=num[pos];
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 1e5+1;

int main(){
	int n;
	cin >> n;
	vector<int> a(MAX, 0);
	for(int i=0; i<n; i++){
		int num;
		cin >> num;
		a[num]++;
	}
	int ans=0, sub=0;
	for(int i=0; i<MAX; i++){
		if(a[i]%2==1){
			ans++;
		}else if(a[i]!=0){
			sub++;
		}
	}
	cout << ans + sub/2*2 << endl;
	return 0;
}

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

#define out(v) cout<<v<<"\n"
#define rep(i,n) for(int i=0;i<(n);++i)
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; cin >> N;
  string A, B, C;
  cin >> A >> B >> C;

  int ans = 0;
  rep(i, N) {
    if (A[i] == B[i] && B[i] == C[i])
      continue;
    if (A[i] == B[i] || B[i] == C[i] || A[i] == C[i])
      ++ans;
    else
      ans += 2;
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}
int main()
{
	int K;
	int A,B;
	cin>>K>>A>>B;
	for(int i=A; i<=B; i++)
	{
		if(i%K ==0)
		{
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int n = sc.nextInt();
		int min = (int) Math.pow(10, 9), max = 0;

		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			if (max < x) {
				max = x;
			}
			if (x < min) {
				min = x;
			}
		}
		
		System.out.println((max - min));

		sc.close();
	}
}


Measured memory_bytes: 21844
#include<stdio.h>
#include<string.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)

int main(){
	char s[200000];
	int max = 0,a = 0;
	scanf("%s",s);
	FOR(i,0,strlen(s)){
		if(a == 0 && s[i] == 'A') a = 1;
		if(a != 0 && s[i] == 'Z'){
			max = a++;
		}else if(a != 0) a++;
	}
	printf("%d",max);
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int[] lineX = new int[N+1];
		int[] lineY = new int[M+1];

		lineX[0] = X;
		lineY[0] = Y;


		for (int i = 1; i <= N; i++) {
			lineX[i] = sc.nextInt();
		}

		for (int i = 1; i <= M; i++) {
			lineY[i] = sc.nextInt();
		}

		Arrays.sort(lineX);
		Arrays.sort(lineY);

		if (lineX[lineX.length - 1] <lineY [0]) {
			System.out.print("No War ");
		} else {
			System.out.print("War");
		}


	}

}


Measured memory_bytes: 22612
#define _USE_MATH_DEFINES
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <algorithm>
#include <sstream>
#include <set>
#include <math.h>
#include <cmath>
#include <map>
#include <stack>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <numeric>
 
using namespace std;
 
int N;
 
int in[100001];
 
map<int, int> mp;
map <int,int>::iterator it;
 
int main(){
 
 scanf("%d",&N);
 
 for(int i=0; i<N; i++){
  int x;
  scanf("%d",&x);
  mp[x]=i;
 }
 
 int i=0;
 
 for(it=mp.begin();it!=mp.end();it++){
 
  int x=it->second;
  
  in[i++]=x;
 
 }
 
 int ans=0;
 
for(int i=0; i<N-1; i++){
 
  int j=in[i];
  
  if(j%2==i%2) continue;
  
  int x=1;
 
  while(1){
    if(in[i+x]%2!=(i+x)%2){
      in[i]=i; in[i+x]=i+x; ans++;
      break;
      }
      x++;
    }
 
 }
 
 cout<<ans<<endl;
 
 return 0;
 
}

Measured memory_bytes: 5376
n = int(input())
s = input().split()
for i in range(n):
  s[i] = int(s[i])
memo = [0 for i in range(n)]
memo[0] = 0
for i in range(1,n):
  if i==1:
      memo[i] = memo[i-1]+abs(s[i]-s[i-1])
  else:
      memo[i] = min(memo[i-1]+abs(s[i]-s[i-1]), memo[i-2]+abs(s[i]-s[i-2]))
print(memo[n-1])

Measured memory_bytes: 17384
#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 a, b;
  cin >> a >> b;
  if (a >= 13)
    cout << b << endl;
  else if (a > 5)
    cout << b / 2 << endl;
  else
    cout << 0 << endl;
  return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int N; cin >> N;
	ll sum = 0;
	map<ll,ll> cnt;
	forn(i,0,N){
		ll x; cin >> x;
		cnt[x]++;
		sum += x;
	}
	int Q; cin >> Q;
	while(Q--){
		ll b,c; cin >> b >> c;
		ll ant = cnt[b];
		sum -= ant*b;
		sum += ant*c;
	
		cout << sum << '\n';
		cnt[c] += ant;
		cnt[b] = 0;
	}
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


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

int main() {
    long long n,a,b,c,e,ans=0,i,j;
    long double f,d;
    cin>>n>>d;
    for(i=0; i<n; i++){
        cin>>a>>b;
        c=pow(a,2);
        e=pow(b,2);
        f=sqrt(c+e);
        if(f<=d){
            ans++;
            
        }
        
    }
    
    cout<<ans;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,ans=INF;
	string s,t;
	cin >> n >> s >> t;
	for(ll i=1;i<=n;i++){
		ll cnt=0;
		for(ll j=0;j<i;j++){
			if(s[n-i+j]!=t[j]) break;
			cnt++;
		}
		chmin(ans,2*n-cnt);
	}
	cout << ans << endl;
	return 0;
}

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

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

    vector<int> O(N);
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> O[i];
        sum += O[i];
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += (sum - O[i]) * O[i];
    }
    cout << ans /2 << endl;
    
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A = [0] + A + [0]
S = 0
for i in range(1,N+2):
  S += abs(A[i]-A[i-1])
Si = [0]*(N+2)
for i in range(1, N+1):
  Si[i] = S-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])
  print(Si[i])

Measured memory_bytes: 14048
#include <stdio.h>

int main() {
  int ans = 0;
  int N;
  scanf("%d", &N);
  char S[N + 1];
  scanf("%s", &S);
  for (int i = 2; i < N; i++) {
    if (S[i] == 'C' && S[i-1] == 'B' && S[i-2] == 'A') {
      ans++;
    }
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main()
{
	int scanCheck = 0;
	int n, k, i, j;
	static int nedan[1000] = {0};
	int hoji;
	int goukei = 0;
	
	scanCheck = scanf("%d", &n);
	scanCheck = scanf("%d", &k);

	for (i = 0; i < n; i++) {
		scanCheck = scanf("%d", &nedan[i]);
	}
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			if (nedan[i] > nedan[j]) {
				hoji = nedan[i];
				nedan[i] = nedan[j];
				nedan[j] = hoji;
			}
		}
	}
	for (i = 0; i < k; i++) {
		goukei += nedan[i];
	}
	printf("%d", goukei);
	
	return (0);
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >> a;
  cout << v[a-1] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	char str[3][101], next;
	unsigned char p;
	int idx[3] = {0};

	for(int i=0; i < 3; i++) {
		scanf("%s", str[i]);
	}

	next = str[0][idx[0]++];
	while(next != '\0') {
		p = next - 'a';
		next = str[p][idx[p]++];
	}
	printf("%c", p+'A');

	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		double [] mon = new double [n];
		String [] cur = new String [n];
		
		for (int i=0; i<n; i++) {
			mon[i] = sc.nextDouble();
			cur[i] = sc.next();
		}
		
		for (int i=0; i<n; i++) {
			if (cur[i].equals("BTC")) {
				mon[i] *= 380000;
			}
		}
		
		double sum = 0.0;
		
		for (int i=0; i<n; i++) {
			sum+=mon[i];
		}
		
		System.out.println(sum);
		
	}

}


Measured memory_bytes: 25428
import java.util.Scanner;

public class Main {


    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a[] = new int[3], work;
    	a[0] = sc.nextInt();
    	a[1] = sc.nextInt();
    	a[2] = sc.nextInt();
    	for(int i = 0; i < 2; i++)
        	for(int j = i + 1; j < 3; j++)
        {
    			if(a[i] > a[j])
    	        {
    	            work = a[i];
    	            a[i] = a[j];
    	            a[j] = work;
    	        }
        }
        System.out.println(a[0] + " " + a[1] + " " + a[2]);
        sc.close();
    }

}

Measured memory_bytes: 26088
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
int main() {
    int n;
    scanf("%d",&n);
 
    LL a=1,b=1;
    for(int i=1;i<=n;i++){
        LL x,y;
        scanf("%lld%lld",&x,&y);
        LL percent=max(a/x,b/y);
        while(true){
            if(percent*x>=a&&percent*y>=b)
                break;
            percent++;
        }
        a=percent*x;
        b=percent*y;
    }
    printf("%lld\n",a+b);
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main(){
    list<char> t;
    string s;
    cin >> s;
    int q;
    cin >> q;
    for(char c: s){
        t.push_back(c);
    }
    bool flag = false;
    while(q --){
        int op;
        cin >> op;
        
        if(op == 1){
            flag = !flag;
        }
        if(op == 2){
            int op2;
            char c;
            cin >> op2 >> c;
            if((op2 == 1 && flag == false)||(op2 == 2 && flag)){
                t.push_front(c);
            }
            else{
                t.push_back(c);
            }
        }
    }
    if(flag) t.reverse();
    for(auto it = t.begin(); it != t.end(); it ++){
        cout << *it;
    }
    cout << endl;

    return 0;
}

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

class Dice{
	int face[6];
public:
	Dice(int a, int b, int c, int d, int e, int f){
		face[0] = a;
		face[1] = b;
		face[2] = c;
		face[3] = d;
		face[4] = e;
		face[5] = f;
	}

	void move(char dire){
		int t;
		if (dire == 'E'){
			t = face[0];
			face[0] = face[3];
			face[3] = face[5];
			face[5] = face[2];
			face[2] = t;
		}
		if (dire == 'W'){
			t = face[0];
			face[0] = face[2];
			face[2] = face[5];
			face[5] = face[3];
			face[3] = t;
		}
		if (dire == 'N'){
			t = face[0];
			face[0] = face[1];
			face[1] = face[5];
			face[5] = face[4];
			face[4] = t;
		}
		if (dire == 'S'){
			t = face[0];
			face[0] = face[4];
			face[4] = face[5];
			face[5] = face[1];
			face[1] = t;
		}
	}

	int uemen(){
		return face[0];
	}
};

int main(){
	int a0, b0, c0, d0, e0, f0;
	cin >> a0 >> b0 >> c0 >> d0 >> e0 >> f0;

	Dice dice1(a0, b0, c0, d0, e0, f0);
	
	string st;
	cin >> st;

	for (int i = 0; i < st.size(); i++){
		char di = st[i];
		dice1.move(di);
	}

	cout << dice1.uemen() << endl;

	return 0;
}


Measured memory_bytes: 3140
#include <cstdio>
#include <cstring>
#include <algorithm> 
using namespace std;
int main()
{
	char a[100001];
	int ans = 0;
	int n;
	scanf("%d",&n);
	scanf("%s",a);
	int maxn = 0;
	for(int i = 0;i < n;i++)
	{
		if(a[i] == 'I')
		{
			ans++;
		}
		maxn = max(maxn,ans);
		if(a[i] == 'D')
		{
			ans--;
		}
	}
	printf("%d",maxn);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#define fi(p) for(int i=0;i<(p);i++)
using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int N;
	cin >> N;
	bool judge = false;
	vector<int> p(N);
	vector<int> save(N);
	fi(N) {
		int input;
		cin >> input;
		save[i] = input;
		p[i] = input;
	}

	int count = 0;
	fi(N) {
		
		if (p[i]==i+1) {
			continue;
		}
		else {
			count++;
		}
	}
	if (count<=2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

}


int main()
{
	solve();

	return 0;
}

Measured memory_bytes: 256
local n=io.read("n","l")
local t={}
for _,a in utf8.codes(io.read()) do
    if not t[a] then
        t[a]=1
    else
        t[a]=t[a]+1
    end
end

local combination=1
for _,frequency in pairs(t) do
    combination=combination*(frequency+1)%1000000007
end
print(combination-1)

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 2005;
char s[N][N], t[4] = {'R', 'Y', 'G', 'B'};
int n, m, d;

void paint(int sx, int sy, int z, char letter) {
    int k = sy, j = sx;
    for (int i = 2; i <= z; i += 2, k--, j++) {
        for (int h = 0; h < i; h++) {
            if (j >= 0 && j < n && k + h >= 0 && k + h < m) {
                s[j][k + h] = letter;
            }
        }
    }
    k += 2;
    for (int i = z - 2; i >= 2; i -= 2, k++, j++) {
        for (int h = 0; h < i; h++) {
            if (j >= 0 && j < n && k + h >= 0 && k + h < m) {
                s[j][k + h] = letter;
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >> d;

    if (d % 2) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                s[i][j] = t[(i + j) & 1];
            }
        }
    }
    else {
        for (int i = -N; i < N * 2; i += d) {
            for (int j = -N; j < N * 2; j += d) {
                paint(i, j, d, t[(i + N + j + N) / d & 1]);
            }
        }

        for (int i = -N; i < N * 2; i += d) {
            for (int j = -N; j < N * 2; j += d) {
                paint(i + d / 2, j + d / 2, d, t[((i + N + j + N) / d & 1) + 2]);
            }
        }

        int ct = 0;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                ct += (s[i][j] > 0);
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << s[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 1536
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    int h,w;cin>>h>>w;
    vector<string> s(h);
    for(int i=0;i<h;i++) cin>>s[i];
    int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
    bool f=true;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s[i][j]=='.') continue;
            bool tmp=false;
            for(int k=0;k<4;k++){
                int nx=i+dx[k],ny=j+dy[k];
                if(nx<0 || h<=nx || ny<0 || w<=ny) continue;
                if(s[nx][ny]=='#') tmp=true;
            }
            if(!tmp) f=false;
        }
    }
    if(f) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

int main() {
	int n, x, y; cin >> n >> x >> y; --x; --y;
	vector<vector<int>> edge(n, vector<int>());
	edge[x].emplace_back(y);
	edge[y].emplace_back(x);
	for (int i = 0; i < n-1; ++i) {
		edge[i].emplace_back(i+1);
		edge[i+1].emplace_back(i);
	}

	vector<int> cnt(n);
	for (int i = 0; i < n; ++i) {
		queue<int> q; q.emplace(i);
		vector<int> cost(n, 1e9); cost[i] = 0;
		while (!q.empty()) {
			int v = q.front(); q.pop();
			cnt[cost[v]]++;
			for (int j = 0; j < edge[v].size(); ++j) {
				int nxt = edge[v][j];
				if (cost[v]+1 < cost[nxt]) {
					cost[nxt] = cost[v]+1;
					q.emplace(nxt);
				}
			}
		}
	}

	for (int k = 1; k < n; ++k) {
		cout << cnt[k]/2 << endl;
	}
}

Measured memory_bytes: 384
import sys
from collections import deque


def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    edge = [[] for _ in range(N + 1)]
    for i in range(N - 1):
        u, v, w = map(int, input().split())
        edge[u].append((v, w))
        edge[v].append((u, w))

    color = [False] * N
    color[0] = 0
    q = deque([1])

    while q:
        u = q.popleft()
        c1 = color[u - 1]
        for c, w in edge[u]:
            if color[c - 1] is False:
                q.append(c)
                color[c - 1] = (c1 + w) % 2

    print(*color)


if __name__ == "__main__":
    main()


Measured memory_bytes: 95892
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n=II()
    print((n+1)//2)

main()

Measured memory_bytes: 3064
using System;
using System.Linq;

class P
{
  static void Main()
  {
    var a = Console.ReadLine()
            .Split(' ')
            .Select(x => int.Parse(x))
            .ToList();
    Console.WriteLine("{0} {1}", a[0] * a[1], 2 * (a[0] + a[1]));
  }
}

Measured memory_bytes: 9504
#include<bits/stdc++.h> 
using namespace std; 
int main(){
  int arr[5]; 
  int m;
  for(int i=0;i<5;i++){
    cin>>arr[i]; 
    if(arr[i]==0){ m=i+1;
      }
    }
  cout<<m; 
  
  }


Measured memory_bytes: 3624
n=int(input())  
B=list(map(int, input().split())) 
A = []
for i in range(len(B)):
    if i == 0:
        A.append(B[i])
    elif B[i] > B[i-1]:
        A.append(B[i-1])
    else:
        A.append(B[i])
    #print(B[i], B[i-1])
A.append(B[i])

print(sum(A))

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

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  long long a[x], b[y], c[z];
  for ( int i = 0; i < x; i++ ) { cin >> a[i]; }
  for ( int i = 0; i < y; i++ ) { cin >> b[i]; }
  for ( int i = 0; i < z; i++ ) { cin >> c[i]; }
  sort(a, a+x, greater<long long>());
  sort(b, b+y, greater<long long>());
  sort(c, c+z, greater<long long>());

  vector<long long> e;
  for ( int i = 0; i < x; i++ ) {
    for ( int j = 0; j < y; j++ ) {
      e.push_back(a[i]+b[j]);
    }
  }
  sort(e.begin(), e.end(), greater<long long>());

  vector<long long> ans;
  for ( int i = 0; i < k && i < e.size(); i++ ) {
    for ( int j = 0; j < z; j++ ) {
      ans.push_back(e[i]+c[j]);
    }
  }
  sort(ans.begin(), ans.end(), greater<long long>());

  for ( int i = 0; i < k; i++ ) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 44108
/*************************************************************************
    > File Name: D.cpp
    > Author: Roundgod
    > Mail: wcysai@foxmail.com 
    > Created Time: 2018-12-22 20:06:44
 ************************************************************************/

#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,a[MAXN];
int main()
{
    bool f=true;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) 
    {
        scanf("%d",&a[i]);
        if(a[i]%2==1) f=false;
    }
    if(!f) puts("first"); else puts("second");
    return 0;
}



Measured memory_bytes: 640
N, L = map(int, raw_input().split())
a = map(int, raw_input().split())
b = [a[i]+a[i+1] for i in xrange(N-1)]
maxb = max(b)
maxbi = b.index(maxb)
if maxb < L:
    print 'Impossible'
    exit()
print 'Possible'
for i in xrange(maxbi):
    print i+1
for i in xrange(N-2, maxbi, -1):
    print i+1
print maxbi+1


Measured memory_bytes: 26080
#include <cstdio>
#include <cmath>
#define mod 1000000007 
#define ll long long 
using namespace std;
int main() {
	ll d, m, ans = 1, f = 1;
	scanf("%lld %lld", &d, &m);
	if(d==m) f = 0;
	if(fabs(d-m) > 1) {
		printf("0\n");
		return 0;
	}
	else {
		while(d != 1) {
			ans *= d;
			ans %= mod;
			d--;
		}
		while(m != 1) {
			ans *= m;
			ans %= mod;
			m--;
		}
	}
	if(!f)
		ans = ans * 2 % mod;
	printf("%lld\n", ans); 
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  int sum = accumulate(A.begin(), A.end(), 0L);
  double tmp = sum / (4.0 * M);
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (A.at(i) >= tmp) cnt++;
  }
  cout << ((cnt >= M) ? "Yes" : "No") << "\n";
}

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

int main(void){
    int i, n, a[101], max=0, min=1001;
    
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf(" %d", &a[i]);
    }

    for(i=0;i<n;i++){
        //printf("%d ", a[i]);
        if(max < a[i]) max=a[i];
        if(min > a[i]) min=a[i];
    }
    
    printf("%d\n", max-min);
    
    return 0;
}


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextIntSlice(size int) []int {
	re := make([]int, size)
	for i := 0; i < size; i++ {
		re[i] = nextInt()
	}
	return re
}

func max(a []int) int {
	max := a[0]
	for _, v := range a {
		if v > max {
			max = v
		}
	}
	return max
}

func min(a []int) int {
	min := a[0]
	for _, v := range a {
		if v < min {
			min = v
		}
	}
	return min
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	//sc.Split(bufio.ScanWords)
	var n, m int
	fmt.Scan(&n, &m)
	a := make([]int, n)
	b := make([]int, n)
	c := make([]int, m)
	d := make([]int, m)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&c[i], &d[i])
	}

	for i := 0; i < n; i++ {
		minj := 0
		mindist := abs(a[i]-c[0]) + abs(b[i]-d[0])
		for j := 1; j < m; j++ {
			tempdist := abs(a[i]-c[j]) + abs(b[i]-d[j])
			if tempdist < mindist {
				minj = j
				mindist = tempdist
			}
		}
		fmt.Println(minj + 1)
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N;
  cin >> N;
  vector<int64_t> A(N), B(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    B.at(A.at(i) - 1)++;
  }
  int64_t ans = 0;  
  for (int i = 0; i < N; i++) {
    ans += ((B.at(i) * (B.at(i) - 1)) / 2);
  }
  for (int i = 0; i < N; i++) {
    cout << ans - B.at(A.at(i) - 1) + 1 << endl;
  }
}
  

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

using namespace std;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int m,n,i,x,sum=0;
    cin>>m>>n;
    for(i=0;i<n;i++){
        cin>>x;
        sum+=x;
    }
    if(sum>m)cout<<"-1\n";
    else cout<<m-sum<<endl;
 	return 0;
}


Measured memory_bytes: 3656
use std::io;
use std::collections::HashMap;


fn main() {
    const MOD: usize = 1_000_000_007;
    let n = read_one::<usize>();

    let mut hm = HashMap::new();
    for i in 1..n + 1 {
        let mut x = i;
        while let Some(f) = divide(x) {
            x /= f;
            *hm.entry(f).or_insert(0) += 1;
        }
        *hm.entry(x).or_insert(0) += 1;
    }

    let mut ans: usize = 1;
    for (k, v) in hm.iter() {
        if k == &1 { continue; }
        ans = ans * (*v + 1);
        ans = ans % MOD;
    }
    println!("{}", ans);

}

fn divide(n: usize) -> Option<usize> {
    for i in 2..(n as f64).sqrt().ceil() as usize + 2 {
        if n % i == 0 {
            return Some(i);
        }
    } 
    return None;
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define iikae auto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

int main(){
  kyopro;
  ll N, K, X, Y;
  cin >> N >> K >> X >> Y;
  if(N > K) cout << K * X + (N - K) * Y << rt;
  else cout << N * X << rt;
}

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

int main(void){
	int pow3[16], c[16];
	int n, m, i, j, k, d, x, y, p;

	pow3[0] = 1;
	for(i = 1; i <= 15; ++i){
		pow3[i] = pow3[i-1] * 3;
	}

	while(scanf("%d%d", &n, &m), n){
		for(i = 0; i < 3; ++i){
			for(scanf("%d", &j); j > 0; --j){
				scanf("%d", &k);
				c[n-k] = i;	/* 番号付け替え */
			}
		}

		p = 0;
		x = 0;
		for(i = n - 1; i >= 0; --i){
			d = abs(p - c[i]);
			x += pow3[i] * d;
			if(d == 1){
				p = 2 - p;	/* 反対側に移動 */
			}
		}

		y = pow3[n] - 1 - x;
		if(x > y){
			x = y;
		}
		printf("%d\n", x > m ? -1 : x);
	}
	return 0;
}

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

int main(){
  int n,d,x;
  cin >> n >> d >> x;
  int ans=x;
  for (int i=0;i<n;++i){
    int a;
    cin >> a;
    //気持ち的にはd日間a間隔なのでd/aだけど厳密には1<=d<=aのとき1,a+1<=d<=2aのとき2なので一つの式にすると
    ans+=(d-1)/a+1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
s=input()
g=0
p=0
ans=0
for i in s:
  if i=="g":
    if p<g:
      ans+=1
      p+=1
    else:
      g+=1
  elif i=="p":
    if p<g:
      p+=1
    else:
      g+=1
      ans-=1
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
    ll n;
    cin >> n;
    ll a[n];
    ll sum = 0;
    for (ll i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    if(n%2==0){
        for (ll i = n / 2; i < n; i++) {
            sum += 2 * a[i];
        }
        sum -= a[n - 1];
    }
    else
    {
        for (ll i = n / 2; i < n; i++) {
            sum += 2 * a[i];
        }
        sum -= a[n - 1];
        sum -= a[n / 2];
    }

        cout << sum << endl;
}


Measured memory_bytes: 5188
#!/usr/bin/env python3
import sys
from collections import Counter


def solve(N: int, A: "List[int]"):
    c = Counter(A)
    values, counts = zip(*c.most_common())
    cc = 0
    for c in counts:
        if c % 2 == 0:
            cc += 1
    if cc % 2 == 0:
        print(len(counts))
    else:
        print(len(counts)-1)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

int main() 
{ 
 int num; 
 int a;
 while(1){
  cin >>num; 
  if(num==0){
   break;}
  else
  {
  for(int i=1;i<10;i++)
    {
    cin>>a;
    num=num-a;
    }
  }
  cout<<num<<"\n";
 }
 return 0; 
} 

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
using namespace std;

int main(){
	int N,A[101][101];
	int dp[101][101]={};
	cin>>N;
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			cin>>A[i][j];
		}
	}
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			dp[i][j] = dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+A[i][j];
		}
	}
	int ans=INT_MIN;
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N;j++){
			for(int k=0;k<i;k++){
				for(int l=0;l<j;l++){
					ans = max(ans,dp[i][j]-dp[k][j]-dp[i][l]+dp[k][l]);
				}
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

long long a, b, k;

int main() {
  cin >> a >> b >> k;
  long long now = min(a, k);
  a -= now;
  k -= now;
  b -= min(b, k);
  cout << a << " " << b << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC155D
{
    class Program
    {
        static long count = 1;
        static long ans = 0;
        static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            long N = long.Parse(NK[0]);
            long K = long.Parse(NK[1]);
            string[] Ainput = Console.ReadLine().Split(' ');
            long[] A = new long[N];
            for (long i = 0; i < N; i++)
            {
                A[i] = long.Parse(Ainput[i]);
            }
            Array.Sort(A);
            long L = (long)(-Math.Pow(10, 18));
            long R = (long)(Math.Pow(10, 18));
            //Console.WriteLine(L);
            while (L + 1 < R)
            {
                long x = (L + R) / 2;
                bool hantei = search(N, K, x, A);
                if (hantei) L = x;
                else R = x;
            }
            Console.WriteLine(L);
        }
        static bool search(long N, long K, long x, long[] A)
        {
            long sum = 0;
            for(int i = 0; i < N; i++)
            {
                long L = -1;
                long R = N;
                if (A[i] < 0)
                {
                    while (L + 1 < R)
                    {
                        long C = (L + R) / 2;
                        if (A[i] * A[C] < x) R = C;
                        else L = C;
                    }
                    sum += N - R;
                }
                else
                {
                    while (L + 1 < R)
                    {
                        long C = (L + R) / 2;
                        if (A[i] * A[C] < x) L = C;
                        else R = C;
                    }
                    sum += R;
                }
                if (A[i] * A[i] < x)
                {
                    sum -= 1;
                }
            }
            sum /= 2;
            if (sum < K) return true;
            else return false;
        }
    }
}


Measured memory_bytes: 45728
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int k;
	while(k=in()){
		int i;
		int sum=0;
		for(i=0;i<k*(k-1)/2;i++){
			sum+=in();
		}
		sum/=k-1;
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>

 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define LLIandI pair<long long int , int>
#define ll long long

int A[200002];
int A2[21][200002];
int main(void){
    int N;
    
    scanf("%d",&N);
    rep(i,N){
        scanf("%d",&A[i]);
        rep(j,20){
            A2[j][i]= ( A[i]%(int)pow(2,j+1) )/(int)pow(2,j) ;
        }
    }
    rep(i,20){
        rep(j,N){
            if(j>0)A2[i][j]= A2[i][j-1]+A2[i][j];
        }
    }
    ll int ans=0;
    int right=0;
    rep(left,N){
        int num=0;
        while(num<2){
            rep(i,20){
                left==0? num=A2[i][right] : num=A2[i][right]-A2[i][left-1];
                if(num>=2){
                    ans+=right-left;right--;
                    break;
                }
            }
            if(num<=1){
                if(right==N-1){
                    ans+=N-left;num=2;
                }else{
                    right++;
                }
            }
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 17280
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
h, w = MAP()
print(H*W - h*W - w*H + h*w)

Measured memory_bytes: 5456