akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    void solve(Scanner sc, PrintWriter pw) {
        int N = sc.nextInt();
        int[] data = new int[N];
        for (int i = 0; i < N; i++) {
            data[i] = sc.nextInt();
        }
        int totalXor = 0;
        for (int i = 0; i < N - 1; i += 2) {
            totalXor ^= (data[i] ^ data[i + 1]);
        }
        List<String> result = new ArrayList<>(N);
        for (int i = 0; i < N; i++) {
            result.add(String.valueOf(totalXor ^ data[i]));
        }
        pw.println(String.join(" ", result));
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

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

    vector<lint> A(N);
    for_(i,0,N) cin >> A[i];

    lint S = A[0] + A[1];

    lint X = 0;
    for_(i,2,N) X ^= A[i];

    lint D = (S - X) / 2;
    if ((S - X) % 2 or S < X or (D & X) > 0 or D > A[0]) {
        puts("-1");
        return 0;
    }

    lint Y = 0;
    for (int i=60; i>=0; --i) {
        if (X >> i & 1) {
            lint nY = Y | (1LL << i);
            if ((D ^ nY) <= A[0]) Y = nY;
        }
    }

    lint a = D ^ Y;
    if (a == 0) {
        puts("-1");
        return 0;
    }

    cout << A[0] - a << endl;
}

Measured memory_bytes: 3636
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
 
using namespace std;
int a[3];
int main(void){
  int K;
  cin>>a[0]>>a[1]>>a[2]>>K;
  sort(a,a+3);
  for(int i=0;i<K;i++){
    a[2]*=2;}
  cout<<a[0]+a[1]+a[2]<<endl;
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int n;
  cin>>n;
  int a[n][3];
  int i=0;
  while(i<n)
  {
    cin>>a[i][0]>>a[i][1]>>a[i][2];
    i++;
  }
  int dp1[n],dp2[n],dp3[n];
  dp1[0]=a[0][0];
  dp2[0]=a[0][1];
  dp3[0]=a[0][2];
  for(i=1;i<n;i++)
  {
    dp1[i]=a[i][0]+max(dp2[i-1],dp3[i-1]);
    dp2[i]=a[i][1]+max(dp1[i-1],dp3[i-1]);
    dp3[i]=a[i][2]+max(dp2[i-1],dp1[i-1]);
  }
  cout<<max(dp1[n-1],max(dp2[n-1],dp3[n-1]))<<"\n";
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	int cnt = 0;
	while(true){
		if(n == 1) break;
		n /= 2;
		cnt++;
	}
	cout << (1 << cnt) << endl;
}

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

int main(){
	int N;
	cin >> N;
	int K[N],P[N];
	for(int i=0; i<N; i++){
		cin >>K[i]>>P[i];


	int ans=K[i]%P[i];
	if(ans==0)
		ans=P[i];
		cout << ans <<endl;
	}

	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <queue>
#include <map>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	for(int i=0;i<a.size();i++)
		os<<(i?" ":"")<<a[i];
	return os<<']';
}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& a){
	os<<'{';
	for(typename map<T1,T2>::const_iterator i=a.begin();i!=a.end();++i)
		os<<(i==a.begin()?"":" ")<<i->first<<"=>"<<i->second;
	return os<<'}';
}

int main()
{
	string i2s[]={"C","C#","D","D#","E","F","F#","G","G#","A","A#","B"}; // index => scale
	map<string,int> s2i; // scale => index
	for(int i=0;i<12;i++)
		s2i[i2s[i]]=i;
	
	int tc; cin>>tc;
	while(tc--){
		int n,m; cin>>n>>m;
		vector<int> stair(n),song(m);
		for(int i=0;i<n;i++){
			string s; cin>>s;
			stair[i]=s2i[s];
		}
		for(int i=0;i<m;i++){
			string s; cin>>s;
			song[i]=s2i[s];
		}
		
		bool ok=false;
		queue<pair<int,int>> q;
		q.emplace(n-1,m-1);
		q.emplace(n-2,m-1);
		while(!q.empty()){
			pair<int,int> cur=q.front(); q.pop();
			int ci=cur.first,cj=cur.second;
			
			if(ci==-1 && cj==-1){
				ok=true;
				break;
			}
			if(ci<=-1 || cj==-1)
				continue;
			
			int diff=song[cj]-stair[ci];
			if(diff==11) diff=-1;
			if(diff==-11) diff=1;
			if(abs(diff)>1) continue;
			
			switch(diff){
			case -1: q.emplace(ci+1,cj-1); break;
			case  0: q.emplace(ci-1,cj-1); break;
			case  1: q.emplace(ci-2,cj-1); break;
			}
		}
		
		cout<<(ok?"Yes":"No")<<endl;
	}
	
	return 0;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;
#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

int h,w;
vvi g;

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

int const inf=1<<28;

inline bool in(int x, int y){
    return 0<=x && 0<=y && x<w && y<h;
}

int ans=inf;

void rec(int x,int y, int depth){
    if(depth>=11) return;
    rep(d,4){
        int cx=x, cy=y;
        if(!in(cx+dx[d],cy+dy[d]) || g[cy+dy[d]][cx+dx[d]]==1) continue;
        while(1){
            int nx=cx+dx[d];
            int ny=cy+dy[d];
            if(!in(nx,ny)) goto next;
            if(g[cy][cx]==0){
                if(g[ny][nx]==0){
                    cx=nx, cy=ny;
                    continue;
                }
                if(g[ny][nx]==1){
                    g[ny][nx]=0;
                    rec(cx,cy,depth+1);
                    g[ny][nx]=1;
                    break;
                }
                if(g[ny][nx]==3){
                    ans=min(ans,depth+1);
                    break;
                }
            }
            if(g[cy][cx]==3){
                ans=min(ans,depth);
            }
        }
    next:;
    }
}

void solve(){
    rep(i,h)rep(j,w)if(g[i][j]==2){
        g[i][j]=0;
        rec(j,i,0);
        return;
    }
}

int main(){
    while(cin >> w>>h && w){
        ans=inf;
        g.assign(h,vi(w));
        rep(i,h)rep(j,w) cin >>g[i][j];
        solve();
        cout << (ans>10?-1:ans) << endl;
    }
}

Measured memory_bytes: 1212
import java.util.*;

// ABC 64-D
// https://beta.atcoder.jp/contests/abc064/tasks/abc064_d

public class Main {

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

		int N = in.nextInt();
		char[] c = in.next().toCharArray();
		
		int pre = 0;
		int post = 0;
		int cur = 0;
		
		for (int i = 0; i < c.length; i++) {
			if (c[i] == '(') {
				cur++;
			} else if (cur > 0) {
				cur--;
			} else {
				pre++;
			}
		}
		post = cur;
		
		for (int i = 0; i < pre; i++) {
			System.out.printf("(");
		}
		for (int i = 0; i < c.length; i++) {
			System.out.print(c[i]);
		}
		for (int i = 0; i < post; i++) {
			System.out.print(')');
		}
		System.out.println();
	}
}


Measured memory_bytes: 21588
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    a, b = LI()
    print(sum([n == int(str(n)[::-1]) for n in range(a, b + 1)]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3864
#include <iostream>
#include <vector>
#include<algorithm>
#include <sstream>

using namespace std;

void writeVector(const vector<int>&);

int main() {
	int n_elem;
	cin >> n_elem;
    vector<int> v;
    int input;
    for(int i=0; i<n_elem; i++){
    	cin >> input;
    	v.push_back(input);
    }

	for(int i=0; i<v.size(); i++){
		int key = v.at(i);
		int j = i - 1;
		while(j>=0 and v.at(j)>key){
			v.at(j+1) = v.at(j);
			j--;
		}
		v.at(j+1) = key;
		writeVector(v);
	}

	return 0;
}

void writeVector(const vector<int>& v){
	for(int i=0; i<v.size(); i++){
		if(i==v.size()-1){
			cout << v.at(i);
			break;
		}
		cout << v.at(i) << " ";
	}
	cout << endl;
}


Measured memory_bytes: 3152
(n, m) = map(int, input().split())
roads = []
for _ in range(m):
    (ai, bi) = map(int, input().split())
    roads.append([ai, bi])
nums = [0 for _ in range(n)]
for road in roads:
    nums[road[0] - 1] += 1
    nums[road[1] - 1] += 1

for num in nums:
    print(num)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 1000000000000000
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PP;
int mod=1000000000;

vector<int> ans(500010);
int n,m;

void update(int i,int x){
  i+=131071;
  ans[i]=x;
  while(i>0){
    i=(i-1)/2;
    ans[i]=min(ans[i*2+1],ans[i*2+2]);
  }
}

int query(int a,int b,int k,int l,int r){
  if(r<=a||b<=l) return INF;
  if(a<=l&&r<=b) return ans[k];
  else{
    int c1=query(a,b,2*k+1,l,(l+r)/2);
    int c2=query(a,b,2*k+2,(l+r)/2,r);
    return min(c1,c2);
  }
}

signed main(){
  cin >> n >> m;
  vector<int> l(m),r(m),c(m);
  for(int i=0;i<m;i++){
    cin >> l[i] >> r[i] >> c[i];
    l[i]--; r[i]--;
  }
  vector<PP> p(m);
  for(int i=0;i<m;i++) p[i]=PP(P(l[i],r[i]),c[i]);
  sort(p.begin(),p.end());
  for(int i=0;i<m;i++){
    l[i]=p[i].first.first;
    r[i]=p[i].first.second;
    c[i]=p[i].second;
  }
  for(int i=0;i<270000;i++) ans[i]=INF;
  update(0,0);
  for(int i=0;i<m;i++){
    int k=query(l[i]+131071,r[i]+131071,0,131071,262143); cerr << k << endl;
    if(k+c[i]<ans[r[i]+131071]) update(r[i],k+c[i]);
  }
  if(ans[131070+n]>=INF) cout << -1 << endl;
  else cout << ans[131070+n] << endl;
}

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

namespace test
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string s = Console.ReadLine();
			char c = s[8];
			Console.WriteLine("A" + c + "C");
		}
	}
}


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

int main(){
    int a, b, c, d;
    int l, r;
    cin >> a >> b >> c >> d;
    l = a + b;
    r = c + d;
    if(l > r) cout << "Left" << endl;
    else if (l == r) cout << "Balanced" << endl;
    else cout << "Right" << endl;
}

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

using namespace std;


long long dp[123456];

int main() {
	int N;
	long long W;
	int Vsm;
	cin >> N >> W;
	
	vector<long long> w(N);
	vector<int> v(N);
	memset(dp, 0x3f3f3f3f, sizeof dp);

	for(int i = 0; i < N; i++) {
		cin >> w[i] >> v[i];
		Vsm += v[i];
	}

	dp[0] = 0;

	for(int i = 0; i < N; i++) {
		for(int u = 1000*100; u >= v[i]; u--) {
			if(dp[u-v[i]]!=0x3f3f3f3f3f3f3f3fLL)
				dp[u] = min(dp[u], dp[u-v[i]] + w[i]);
		}
	}
	int res = 0;
	

	for(int i = 0; i <= 1000*100; i++) {
		if(dp[i] <= W)
			res = i;
	}
	cout << res << endl;

}


Measured memory_bytes: 1152
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main(){
    
    int n,k;
    cin>>n>>k;
    
    int ans=1;
    
    for(int i=0;i<n;i++){
     if(ans>=k){
         ans=ans+k;
     }else{
         ans=ans*2;
     }
    }
    
    cout<<ans<<endl;
    return 0;
}








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

int main() {
	int N, L;
	cin >> N >> L;
	string S[200];
	string ans;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	sort(S, S + N);
	ans = S[0];
	for (int k = 1; k < N; k++) {
		ans = ans + S[k];
		
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
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 prev = 0;
	rep(i,n) {
		int a;
		cin >> a;
		if (a == prev+1) {
			++prev;
		}
	}
	if (prev == 0) {
		cout << -1 << endl;
	} else {
		cout << n-prev << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<ll> a(n), b(n);
  REP(i,n) cin >> a[i] >> b[i];
  ll ans = 0;
  REPR(i,n-1){
    a[i] += ans;
    if(a[i]%b[i]>0) ans += b[i] - (a[i]%b[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
double a,b,c,d,e,f;
while(cin >> a >> b >> c >> d >> e >> f,!cin.eof()){
b/=a,c/=a,a=1;
e-=d*b,f-=d*c,d=0;
f/=e,e=1;
c-=b*f,b=0;
c+=0.0004,f+=0.0004;
cout << setprecision(3) << fixed << c << " " << f << endl;
}
}

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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999;
	
	public static void Main(string[] args)
	{
		var s = Console.ReadLine();
		long wa = 700;
		for(int i = 0; i < s.Length; i++)
		{
			if(s[i] == 'o')
				wa+=100;
		}
		Console.WriteLine(wa);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}


Measured memory_bytes: 11092
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int n,k;
  cin >> n >> k;
  if(n <= k){
    cout << 1 << endl;
    return 0;
  }
  int ans = 1;
  int len = k;
  while(true){
    len += k - 1;
    ans ++;
    if( n <= len) break;
  }
  cout << ans << endl;
  return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}
int dp[9][1010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  dp[1][0] = 1;
  REP(i,1,n+1){
    if(s[i-1] == 'J'){
      rep(k,8){
        rep(j,8){
          if( (k & j)!= 0 && (k & 1) != 0){
            dp[k][i] = (dp[k][i]+ dp[j][i-1]) % 10007;
          }
        }
      }
    }
    else if(s[i-1] == 'O'){
      rep(k,8){
        rep(j,8){
          if( (k & j)!= 0 && (k & 2) != 0){
            dp[k][i] = (dp[k][i]+ dp[j][i-1]) % 10007;
          }
        }
      }
    }
    else{
      rep(k,8){
        rep(j,8){
          if( (k & j)!= 0 && (k & 4) != 0){
            dp[k][i] = (dp[k][i]+ dp[j][i-1]) % 10007;
          }
        }
      }
    }
  }
  int ans = 0;
  rep(i,9){
    ans += dp[i][n];
  }
  cout << ans % 10007<<endl;
  return 0;
}

Measured memory_bytes: 3264
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <math.h>
 
using namespace std;
 
int main()
{
  long long N, A, B;
  cin >> N >> A >> B;
 
  long long div = N / (A + B);
  long long rest = N % (A + B);
  long long rest_bule = rest > A ? A : rest;
 
  cout << div * A + rest_bule << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<array>
#include<algorithm>
int main()
{
	while (true)
	{
		int a, b, c, d, e;
		char foo;
		std::cin >> a >> foo >> b >> foo >> c >> foo >> d >> foo >> e;
		if (std::cin.eof())
		{
			break;
		}
		std::array<int, 5>num = { a,b,c,d,e };
		std::sort(num.begin(), num.end());
		if (num[0] == num[3] || num[1] == num[4])
		{
			std::cout << "four card" << std::endl;
		}
		else if (num[0] == num[1] && num[2] == num[4] || num[0] == num[2] && num[3] == num[4])
		{
			std::cout << "full house" << std::endl;
		}
		else if (num[2] == num[1] + 1 && num[3] == num[1] + 2 && num[4] == num[1] + 3 && (num[0] == num[1] - 1 || num[0] == 1 && num[1] == 10))
		{
			std::cout << "straight" << std::endl;
		}
		else if (num[0]==num[2]||num[1]==num[3]||num[2]==num[4])
		{
			std::cout << "three card" << std::endl;
		}
		else
		{
			int pair = 0;
			for (int i = 0; i < 4; i++)
			{
				if (num[i] == num[i + 1])
				{
					pair++;
				}
			}
			switch (pair)
			{
			case 2:
				std::cout << "two pair" << std::endl;
				break;
			case 1:
				std::cout << "one pair" << std::endl;
				break;
			case 0:
				std::cout << "null" << std::endl;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3124
import Control.Applicative
main = do
    ss <- words <$>getLine
    let a:b:_ = [read x| x<- ss] ::[Int]
    if a==0 && b==0 then return ()
    else do
      let o = concat[x++"\n" | x<-(take a (repeat(take b (repeat '#'))))]
      putStrLn $ o
      main

Measured memory_bytes: 3940
n, m = [int(item) for item in input().split()]

ids, ps, ys = [], [], []
for i in range(m):
  p, y = [int(item) for item in input().split()]
  ids.append(i)
  ps.append(p)
  ys.append(y)

city_num = [0] * (n+1)
ids, ps, ys = zip(*sorted(zip(ids, ps, ys) ,key = lambda x : x[2]))
names = []

for p in ps:
  city_num[p] += 1
  names.append("{0:06d}".format(p) + "{0:06d}".format(city_num[p]))
  
names, _ = zip(*sorted(zip(names, ids), key=lambda x:x[1]))
for name in names:
  print(name)

Measured memory_bytes: 38580
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)a;i<=(sign)b;++i)
#define Fordown(i,a,b) for(register sign i=(sign)a;i>=(sign)b;--i)
bool cmax(sign &a,sign b){return (a<b)?a=b,1:0;}
bool cmin(sign &a,sign b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
  T ans=0,f=1;
  char ch=getchar();
  while(!isdigit(ch)&&ch!='-')ch=getchar();
  if(ch=='-')f=-1,ch=getchar();
  while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
  return ans*f;
}
template<typename T>void write(T x,char y)
{
  if(x==0)
  {
      putchar('0'),putchar(y);
      return;
  }
  if(x<0)
  {
      putchar('-');
      x=-x;
  }
  static char wr[20];
  int top=0;
  for(;x;x/=10)wr[++top]=x%10+'0';
  while(top)putchar(wr[top--]);
  putchar(y);
}
void file()
{
  #ifndef ONLINE_JUDGE
      freopen("test.in","r",stdin);
      freopen("test.out","w",stdout);
  #endif
}
const int N=1e5+5;
int n,a[N];
const int mo=1e9+7;
ll power(ll x,int y)
{
	ll res=1;
	for(;y;x=x*x%mo,y>>=1)if(y&1)res=res*x%mo;
	return res;
}
void input()
{
	n=read<int>();
	For(i,1,n)a[i]=read<int>();
}
int ans,sum[N];
void work()
{
	int mc=1;
	For(i,1,n)
	{
		sum[i]=(sum[i-1]+power(i,mo-2))%mo;
		mc=1ll*mc*i%mo;
	}
	For(i,1,n)
	{
		int res=(sum[i]+sum[n-i+1]-1)%mo;
		ans=(ans+1ll*res*a[i]%mo)%mo;
	}
	ans=1ll*ans*mc%mo;
	write(ans,'\n');
}
int main()
{
//	file();
	input();
    work();
	return 0;
}


Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });

            var AB = Sarray();
            var A = AB[0];
            var B = AB[1];
            var S = ReadLine();
            var res = 0L;
            var bAt = true;
            if (!long.TryParse(S.Substring(0, (int)A), out res)) 
                bAt = false;
            if (S[(int)A] != '-')
                bAt = false;
            if (!long.TryParse(S.Substring((int)A + 1, (int)B), out res))
                bAt = false;
            WriteLine(bAt ? "Yes" : "No");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13268
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class FPerilsInParallel {
public:

    vector<P> graph[100005];
    vector<bool> bomb;
    vector<bool> used;
    vector<bool> ans;

    bool dfs(int p) {
      used[p] = true;
      for(auto e: graph[p]) {
        if (used[e.first]) continue;
        if (dfs(e.first)) {
          ans[e.second] = true;
          bomb[p] = bomb[p] ^ true;
        }
      }
      return bomb[p];
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll n, m; cin >> n >> m;
      vector<pair<int, bool>> b(n);
      bomb.resize(n+1);
      used.resize(n+1);
      ans.resize(m);
      rep(i, n) {
        cin >> b[i].first >> b[i].second;
      }
      sort(all(b));
      bomb[0] = b[0].second;
      bomb[n] = b[n-1].second;
      for(int i=1; i<n; i++) {
        bomb[i] = b[i].second ^ b[i-1].second;
      }

      vector<int> c(n);
      rep(i, n) {
        c[i] = b[i].first;
      }

      rep(i, m) {
        int l, r; cin >> l >> r;
        auto it = lower_bound(all(c), l);
        auto u = distance(c.begin(), it);
        it = upper_bound(all(c), r);
        auto v = distance(c.begin(), it);
        graph[u].emplace_back(v, i);
        graph[v].emplace_back(u, i);
      }

      rep(i, n+1) {
        if (!used[i]) {
          if (dfs(i)) {
            cout << -1 << endl;
            return;
          }
        }
      }

      int k = 0;
      rep(i, m) {
        if (ans[i]) k++;
      }
      cout << k << endl;
      rep(i, m) {
        if (ans[i]) cout << i+1 << ' ';
      }
      cout << endl;

    }



};

signed main() {
  FPerilsInParallel solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

int main(){
	char b;
	cin>>b;
	
	char s[]="ACGT";
	int i=0;
	while(b-s[i]){
		i++;
	}
	
	cout<<s[3-i]<<endl;
	return 0;
}//abc122_a.復習.参考.

Measured memory_bytes: 256
import math

N = int(input())

def judge(n):
    if n <= 1:
        return False
    for i in range(2, int(math.sqrt(n))+1):
        if n % i == 0:
            n //= i
            while n != 1:
                if n % i != 0:
                    return False
                n //= i
            return True
    return True


def get_prime(n):
    if n <= 1:
        return []
    prime = [2]
    limit = int(math.sqrt(n))

    data = [i + 1 for i in range(2, n, 2)]
    while limit > data[0]:
        prime.append(data[0])
        data = [j for j in data if j % data[0] != 0]
    return prime + data

ans = 0
i = 2
limit = int(math.sqrt(N))
while N != 1:
    
    if i > limit:
        if N > i:
            ans += 1
        break
    if N % i == 0 and judge(i): 
        N //= i
        ans += 1
        
    i += 1
    
print(ans)

Measured memory_bytes: 9260
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
#define MOD 1000000007
#define INF LLONG_MAX
#define PI 3.14159265359
using namespace std;


int main()
{
  fastio
  string s;
  cin >> s;
  int ans = 0;
  for(int i=0; i<3; i++) if(s[i]=='S') ans++;
  if(ans==1 && s[1]=='S') cout << 1;
  else cout << 3-ans;
	return 0;
}





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

long long const MOD = 1000000007;
int main()
{
  int N;
  char s[100001];
  long long dp[100001][13]; //dp[i][j] 
  cin >> s;
  N = strlen(s);

  rep(i,N) {
    rep(j,12) dp[i][j]=0;
  }
  dp[0][0] = 1;
  
  for(int i=0; i<N; i++){
    rep(j,13){
      if(s[i]!='?'){
        int num = s[i]-'0';
        int residual = (j*10 + num) % 13;
        dp[i+1][residual] += dp[i][j];
      }
      else {
        rep(k, 10){
          int residual = (j*10 + k) % 13;
          dp[i+1][residual] += dp[i][j];
        }
      }
    }
    rep(j, 13) dp[i+1][j] %= MOD;

  }

  #if 0
  rep(i,13) {
    rep(j,N) {
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  #endif

  cout << dp[N][5] << endl;
}

Measured memory_bytes: 10496
import bisect
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
a.sort()
b.sort()
c.sort()
l=0
for j in b:
    aa=bisect.bisect_left(a,j)
    cc=bisect.bisect_right(c,j)
    if cc!=0:
        l+=(aa*(len(c)-cc))
    else:
        l+=(aa*len(c))
print(l)


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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
#define check cout<<"?\n";
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
    io();
    int n; cin >> n;
    priority_queue<ld, vector<ld>, greater<ld> > pq;
    vector<ld> v(n);
    for(int i  = 0; i < n; ++i){
        ld x; cin >> x;
        pq.push(x);
    }
    ld ans = 0;    
    while(pq.size() > 1){
        ld f = pq.top();
        pq.pop();
        ld s = pq.top();
        pq.pop();
        pq.push((f + s)/2);
    }
    cout << fixed << setprecision(9);
    cout << pq.top() << '\n';
    return 0;
}

Measured memory_bytes: 3764
#include<iostream>
using namespace std;
int main()
{

    int s, c;
    cin >> s;

    c = 0;

    if(s-100>=0){
        s-=100;
        c++;
    }

    if(s-10>=0) {
        s-=10;
        c++;
    }
    
    if(s-1==0) {
        c++;
    }
    cout << c;

    return 0;

}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> vec(N);
    int a, b;
    for (int i = 0; i < M; i++){
        cin >> a >> b;
        vec[a-1]++;
        vec[b-1]++;
    }
    for (int i = 0; i < N; i++){
        cout << vec[i] << endl;
    }
}



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

int main()
{
    string s;
    cin >> s;
    int preans=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='p')
            preans++;
    }
    int ans=s.size()/2;
    cout << ans-preans << "\n";
}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

template <typename T> lint gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> lint lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b) a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b) a=b;}

struct IoSetup{
    IoSetup(){
      ios::sync_with_stdio(false);
      cin.tie(0);
      cout << fixed << setprecision(20);
      cerr << fixed << setprecision(20);
    }
} IoSetup;

int main() {
  int n; cin >> n;
  vector <lint> vec(n);
  map<string, int> mp;
  for (int i = 0; i < n; ++i) {
    int x;
    string s;
    cin >> s >> x;
    mp[s] = i;
    vec[i] = vec[max(0,i-1)] + x;
  }
  string str;
  cin >> str;
  
  cout << vec[n - 1] - vec[mp.at(str)] << '\n';
}


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

typedef long long ll;

const int MN = 200010;

int N;
int A[MN];

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

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

    for(int i = 0; i < N; i++) {
        if(A[i] > i) {
            printf("-1");
            return 0;
        }
    }
    for(int i = 0; i < N - 1; i++) {
        if(A[i + 1] - A[i] > 1) {
            printf("-1");
            return 0;
        }
    }
    ll ans = 0;
    for(int i = 0; i < N - 1; i++) {
        if(A[i] + 1 != A[i + 1]) {
            ans += A[i];
        }
    }
    ans += A[N - 1];
    printf("%lld", ans);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define PII pair<ll,ll>
#define VI  vector<ll>
#define VB  vector<bool>
#define VVI vector<vector<ll>>
#define VS  vector<string>
#define VP  vector<PII>
#define lf(i,a,b) for(ll i=a;i<=b;i++)
#define lr(i,a,b) for(ll i=a;i>=b;i--)
#define lfl(i,v) for(ll i=0;i<v.size();i++)
#define lrl(i,v) for(ll i=(ll)(v.size())-1;i>=0;i--)
#define chk2(a,b) cout<<"check :  "<<a<<" "<<b<<endl
#define chk3(a,b,c) cout<<"check :  "<<a<<" "<<b<<" "<<c<<endl
#define chk4(a,b,c,d) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define chk5(a,b,c,d,e) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl
#define lb(v,k)  lower_bound(v.begin(),v.end(),k)-v.begin()
#define ub(v,k)  upper_bound(v.begin(),v.end(),k)-v.begin()
#define mod 1000000007
#define pb push_back
#define pf push_front
#define m_p make_pair
#define fi first
#define se second
#define sz size()
#define sort(v) sort(v.begin(),v.end())
ll n,m;
VVI gp;
ll dp[100005];
ll fun(ll v)
    {   if(dp[v]!=-1)
            return dp[v];
        ll maxi=0;
        lfl(i,gp[v])
        {   maxi=max(maxi,1+fun(gp[v][i]));
        }
        return dp[v]=maxi;
    }
int main()
{   cin>>n>>m;
    gp=VVI(n+1);
    memset(dp,-1,sizeof(dp));
    lf(i,1,m)
    {   ll u,v;cin>>u>>v;
        gp[u].pb(v);
    }
    ll maxi=0;
    lf(i,1,n)
    {   maxi=max(maxi,fun(i));
    }
    cout<<maxi<<endl;
}

Measured memory_bytes: 8576
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;
int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
    stack<int> S;
    S.push(r);
    color[r] = c;
    while ( !S.empty() ) {
        int u = S.top();
        S.pop();
        for ( int i = 0; i < G[u].size(); i++ ){
            int v = G[u][i];
            if ( color[v] == NIL ) {
                color[v] = c; S.push(v);
            }
            
        }
    }
        }

void assignColor() { int id = 1;
    for(int i=0; i<n; i++) color[i]=NIL;
    for(int u=0; u<n; u++){
        if(color[u] ==NIL) dfs(u,id++);
    }
    }

int main() {
    int s, t, m, q;
    cin >> n >> m;

    for ( int i = 0; i<m; i++){
         cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
         }
    assignColor();
    cin >> q;
    
         for ( int i = 0; i < q; i++ ) {
             cin >> s >> t;
             if ( color[s] == color[t] ) {
                 cout << "yes" << endl;
                 
             } else {
                     cout << "no" << endl;
                 
             }
         }
         return 0; }



Measured memory_bytes: 8988
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long M = sc.nextLong();
    long n, m;
    if(N >= 2){
      n = N-2;
    }else{
      n = 1;
    }
    
    if(M >= 2){
      m = M-2;
    }else{
      m = 1;
    }

    System.out.println(n * m);
  }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

int main(){
        ll n;
        cin >> n;
        vll a(n+1);
        REP(i,1,n){
                cin >> a[i];
        }
        ll ttl = 0;
        REP(i,1,n){
                ttl += a[i];
        }
        ll cur = 0;
        ll ans = 1e18;
        REP(i,1,n){
                cur += a[i];
                ll another = ttl - cur;
                ans = min(ans, abs(another - cur));
        }
        cout << ans << endl;
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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 (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (a == 0) return 0; else if (b % 2 == 0) return (pow((a * a) % m, b / 2, m) % m); else return (pow((a * a) % m, b / 2, m) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

int main(){
   ll N; cin >> N;
   Vi A(N);
   REP(i, N) cin >> A[i];
   ll ans = 0;
   REP(i, N) ans = gcd(ans, A[i]);
   cout << ans << endl;
}


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

int grid[3][3];

int main() {

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

  cin >> grid[0][0] >> grid[0][1] >> grid[0][2];
  cin >> grid[1][0] >> grid[1][1] >> grid[1][2];
  cin >> grid[2][0] >> grid[2][1] >> grid[2][2];


  bool a = ((grid[0][0] - grid[0][1]) == (grid[1][0] - grid[1][1])) && ((grid[1][0] - grid[1][1]) == (grid[2][0] - grid[2][1]));
  
  bool b = ((grid[0][0] - grid[0][2]) == (grid[1][0] - grid[1][2])) && ((grid[1][0] - grid[1][2]) == (grid[2][0] - grid[2][2]));
  
  bool c = ((grid[0][1] - grid[0][2]) == (grid[1][1] - grid[1][2])) && ((grid[1][1] - grid[1][2]) == (grid[2][1] - grid[2][2]));

  if (a && b && c) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	
	ll s, c;
	cin >> s >> c;
	if (s >= c/2) {cout << c/2; return 0;}
	c -= s*2;
	cout << s + c/4;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
signed main(void){
    int n; cin>>n;
    int ans = n/2LL;
    if(n %2 == 0) ans--;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int card[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) { cin >> card[i][j]; }
  }

  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    int num;
    cin >> num;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (card[i][j] == num) { card[i][j] = -1; }
      }
    }
  }

  bool flag = false;
  for (int i = 0; i < 3; i++) {
    if (card[i][0] == -1 && card[i][1] == -1 && card[i][2] == -1) flag = true;
    if (card[0][i] == -1 && card[1][i] == -1 && card[2][i] == -1) flag = true;
  }
  if (card[0][0] == -1 && card[1][1] == -1 && card[2][2] == -1) flag = true;
  if (card[0][2] == -1 && card[1][1] == -1 && card[2][0] == -1) flag = true;

  cout << (flag ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 888
# -*- coding: utf-8 -*-

import sys
import os

for s in sys.stdin:
    N = int(s)
    if N == 0:
        break

    X = []
    Y = []
    visited = [False] * N

    for i in range(N):
        x, y = map(float, input().split(','))
        X.append(x)
        Y.append(y)

    def paint(start_i, is_right, is_up):
        x_start = X[start_i]
        y_start = Y[start_i]
        visited[start_i] = True

        if is_right:
            dir_sign = 1 # search right only
        else:
            dir_sign = -1 # search left only

        if (is_up and is_right) or (not is_up and not is_right) :
            min_max_sign = 1 # search min
        else:
            min_max_sign = -1 # search max

        tangent_min_i = None
        tangent_min = None
        for i, x in enumerate(X):
            if dir_sign * (x - x_start) > 0:
                y = Y[i]
                tangent = (y - y_start) / (x - x_start)
                if tangent_min is None:
                    tangent_min = tangent
                    tangent_min_i = i
                else:
                    if min_max_sign * (tangent_min - tangent) > 0:
                        tangent_min = tangent
                        tangent_min_i = i
        if tangent_min_i is not None:
            paint(tangent_min_i, is_right, is_up)


    start_index = Y.index(min(Y))
    visited[start_index] = True
    paint(start_index, is_right=True, is_up=True)
    paint(start_index, is_right=False, is_up=True)

    start_index = Y.index(max(Y))
    visited[start_index] = True
    paint(start_index, is_right=True, is_up=False)
    paint(start_index, is_right=False, is_up=False)

    visit_num = 0
    for is_visit in visited:
        if is_visit:
            visit_num += 1
    print(len(X) - visit_num)

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

int main(int argc, char const *argv[]) {
  int k, a, b;
  cin >> k >> a >> b;
  bool flag = false;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      flag = true;
      break;
    }
  }
  if (flag)
    cout << "OK" << endl;
  else
    cout << "NG" << endl;
  return 0;
}


Measured memory_bytes: 3636
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    V, E = map(int, readline().split())
    dist = [[INF] * V for _ in range(V)]
    for i in range(E):
        u, v, cost = map(int, readline().split())
        dist[u][v] = cost
    dp = [[-1] * V for _ in range(1<<V)]

    def rec(s, v, dp):
        if dp[s][v] >= 0:
            return dp[s][v]

        if s == ((1 << V) - 1) and v == 0:
            dp[s][v] = 0
            return 0

        res = INF
        for u in range(V):
            if ((s >> u) & 1) == 0:
                res = min(res, rec(s | (1 << u), u, dp) + dist[v][u])
        dp[s][v] = res
        return res

    ans = rec(0, 0, dp)
    if ans==INF:
        print(-1)
    else:
        print(ans)
if __name__ == '__main__':
    main()




Measured memory_bytes: 15452
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
int main(){
ll n,k;
cin >> n >> k;
ll a[n];
for (ll i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
}
ll logk = 1;
while ((1LL << logk) < k) logk++;
ll doubling[logk][n];//i番目の街から2^t進んだとこ
for (ll i = 0; i < n;i++){
    doubling[0][i] = a[i];
}
for (ll t = 0; t < logk;t++){
    for (ll i = 0; i < n;i++){
        doubling[t + 1][i] = doubling[t][doubling[t][i]];
    }
}
ll ans=0;
for (ll i = 0; k > 0;i++){
    if (k & 1) ans = doubling[i][ans];
    k >>= 1;
}
cout << ans + 1 << endl;
}

Measured memory_bytes: 98764
#include<cstdio>
#include<string>
using namespace std;
char a[100005];
string s;
int main(){
    
    scanf("%s",&a);
    s=a;
    for (int i=0;i<=s.size()-1;i+=2)
	{
       printf("%c",s[i]);
    }
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <utility>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <stack>
#define N 100010

using namespace std;

int n;

int main()
{
    scanf("%d",&n);
    long long t, a;
    for (int i=0;i<n;i++)
    {
        int x, y;
        scanf("%d%d",&x,&y);
        if (!i)
        {
            t = x;
            a = y;
        }
        else
        {
            long long tx = t/x;
            long long ty = a/y;
            if (t%x)
            {
                tx++;
            }
            if (a%y)
            {
                ty++;
            }
            long long mam = max(tx,ty);
            t = x*mam;
            a = y*mam;
        }
    }
    printf("%lld\n",t+a);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a,b,c,d,f=0;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	while(a>0&&c>0){
		c-=b;
		if(c<=0){
			f=1;
		}
		a-=d;
	}
	if(f==1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}


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

using namespace std;

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


int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> v = {a, b, c};
  int res = 0;
  while(true) {
    sort(v.begin(), v.end());
    // cout << v[0] << ":" << v[1] << ":" << v[2] << endl;
    if (v[0] == v[1] && v[0] == v[2]) {
      cout << res << endl;
      return 0;
    }
    if (v[0] != v[1]) {
      v[0] += 2;
      res++;
    }else if (v[0] == v[1] && v[1] != v[2]){
      v[0]++;
      v[1]++;
      res++;
    }
    if(v[0] == v[1] && (v[0] + 1 == v[2])){
      res++;
      cout << res << endl;
      return 0;
    }
  }


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lop(i,n) for(i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(i=n-1;i>=0;i--)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
#define F first
#define S second
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define LCM(a,b) (a*b)/__gcd(a,b)
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define sz(x) (ll)x.size()
#define ld long double
#define pcnt(x) __builtin_popcountll(x)
const long long I1 = 1e9;
const long long I2 = 1e18;

template<typename T, typename T1>T maxn(T &a, T1 b) {if (b > a)a = b; return a;}
template<typename T, typename T1>T minn(T &a, T1 b) {if (b < a)a = b; return a;}
bool isPrime(int n)
{
    if (n <= 1) return false;
    if (n <= 3) return true;

    if (n % 2 == 0 || n % 3 == 0) return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}


int main() {
//#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
//#endif
    ll n, i;
    cin >> n;
    ll a[n];
    lop(i, n)
    cin >> a[i];
    ll ans[n];
    ans[0] = 0;
    for (i = 1; i < n; i++) {
        ans[i] = min((i - 1 >= 0 ? (ans[i - 1] + abs(a[i] - a[i - 1])) : I1), (i - 2 >= 0 ? (ans[i - 2] + abs(a[i] - a[i - 2])) : I1));
    }
    cout << ans[n - 1] << endl;
    return 0;
}


Measured memory_bytes: 5196
def main(n,k,p):
    res = 0
    #期待値リスト
    kitai = [0] * n
    ruiseki = [0] * n
    kitai[0] = (p[0] + 1) / 2
    ruiseki[0] = kitai[0]
    if n == 1:
        return kitai[0]
    else:
        for i in range(1, len(p)):
            kitai[i] = (p[i] + 1) / 2
            ruiseki[i] = ruiseki[i-1] + kitai[i]
    for i in range(k-1, len(ruiseki)):
        res = max(res, ruiseki[i] - (ruiseki[i-k] if (i-k) >= 0 else 0))
    return res


n,k = map(int, input().split())
p = list(map(int,input().split()))
print(main(n,k,p))

Measured memory_bytes: 25604
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 233333;
int n,a[N],res;
int main() {
	read(n);rep(i,1,n)read(a[i]);int cnt=1e5;
	rep(i,2,n)if(a[i]==a[i-1]){
		res++;a[i]=++cnt;
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 764