akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
#define inf 1000000007
signed main(){
    int n;cin>>n;
   priority_queue<int,vector<int>,greater<int> >pu;
    int sum=0;
    int num[300005];
    int res[300005];
    rep(i,0,3*n){
        cin>>num[i];
    }
    rep(i,0,n){
        pu.push(num[i]);sum+=num[i];
    }
    res[n-1]=sum;
    rep(i,n,2*n){
        pu.push(num[i]);
        sum+=num[i];
        sum-=pu.top();
        pu.pop();
        res[i]=sum;
    }
    priority_queue<int>Q1;
    int sum1=0;
    for(int i=3*n-1;i>=2*n;i--){Q1.push(num[i]);sum1+=num[i];}
    res[2*n-1]-=sum1;
    for(int i=2*n-1;i>=n;i--){
        Q1.push(num[i]);
        sum1+=num[i];
        sum1-=Q1.top();
        Q1.pop();
        res[i-1]-=sum1;
    }
    int ans=-1e15;
    for(int i=n-1;i<2*n;i++){ans=max(ans,res[i]);}
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 7284
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <queue>
using namespace std;

int main(){
	string Sdash, T;
	cin >> Sdash >>T;
	int N = (int)Sdash.size();
	int M = (int)T.size();
	vector<string> S;
	bool check = false;
	for(int i=0;i+M-1<N;i++){
		bool able = true;
		for(int j=0;j<M;j++){
			if(Sdash[i+j] != T[j] && Sdash[i+j] != '?'){
				able = false;
				break;
			}
		}
		if(able){
			string Sans = Sdash;
			for(int j=0;j<N;j++){
				if(j < i && Sans[j] == '?'){
					Sans[j] = 'a';
				}
				if(j >= i && j < i + M && Sans[j] == '?'){
					Sans[j] = T[j - i];
				}
				if(j >= i + M && Sans[j] == '?'){
					Sans[j] = 'a';
				}
			}
			S.push_back(Sans);
		}
	}
	sort(S.begin(), S.end());
	if((int)S.size()) cout << S[0] << endl;
	else cout << "UNRESTORABLE" << endl;
}

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

int main(){
    int W, H, x, y, r;
    
    cin >> W >> H >> x >> y >> r;
    
    if (x - r < 0 || x + r > W || y - r < 0 || y + r > H){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
main(){int n;cin>>n;vector<int> beki={1000,961,900,841,784,729,676,625,576,529,512,484,441,400,361,343,324,289,256,243,225,216,196,169,144,128,125,121,100,81,64,49,36,32,27,25,16,9,8,4,1};for(int i=0;;i++){if(beki[i]<=n){cout<<beki[i]<<endl;return 0;}}}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] p = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        bool[] f = new bool[n];
        for (int i = 0; i < n; i++)
        {
            f[i] = p[i] == (i + 1);
        }
        int ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (f[i])
                ans++;
            try
            {
                if (f[i] && f[i + 1])
                    f[i + 1] = false;
            }
            catch { break; }
        }
        C.WriteLine(ans);
    }
}
//以下標準出力用のクラス
static class C
{
    [System.Runtime.InteropServices.DllImport("msvcrt.dll")]
    private static extern void printf(string s);
    public static void Write(string s) { printf(s); }
    public static void Write(char c) { printf(c.ToString()); }
    public static void Write(long n) { printf(n.ToString()); }
    public static void Write(int n) { printf(n.ToString()); }
    public static void Write(double d) { printf(d.ToString()); }
    public static void WriteLine() { printf("\n"); }
    public static void WriteLine(string s) { printf(s + "\n"); }
    public static void WriteLine(char c) { WriteLine(c.ToString()); }
    public static void WriteLine(long n) { WriteLine(n.ToString()); }
    public static void WriteLine(int n) { WriteLine(n.ToString()); }
    public static void WriteLine(double d) { WriteLine(d.ToString()); }
    public static void WriteLines(string[] s) { foreach (var i in s) WriteLine(i); }
    public static void WriteLines(char[] c) { foreach (var i in c) WriteLine(i); }
    public static void WriteLines(long[] c) { foreach (var i in c) WriteLine(i); }
    public static void WriteLines(int[] c) { foreach (var i in c) WriteLine(i); }
    public static void WriteLines(double[] d) { foreach (var i in d) WriteLine(i); }
}

Measured memory_bytes: 20192
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        
        for(int i=0; i<19; i++){
        if(i == 5 || i == 13){
            System.out.print(" ");
        }else{
            System.out.print(s.charAt(i));
            }
        }
    }
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,k;
    cin >> n >> k;
    vector<int32> l,r;
    r.push_back(0);
    REP(i,n){
        int32 x;
        cin >> x;
        if(x < 0){
            l.push_back(-x);
        }else if(0 < x){
            r.push_back(x);
        }else{
            k--;
        }
    }
    l.push_back(0);
    reverse(ALL(l));
    int32 ans = INF;
    REP(i,k+1){
        int32 a = INF, b = INF;
        if(i < l.size())
            a = l[i];
        if(k-i < r.size())
            b = r[k-i];
        ans = min({ans, a+b*2, a*2+b});
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 1656
import java.util.Scanner;

public class Main {

  public static void main(final String[] args) {
    final var scanner = new Scanner(System.in);
    final var A = scanner.next();
    final var B = scanner.next();

    int sum = 0;
    for (int i = 0; i < A.length(); i++) {
      if (A.charAt(i) != B.charAt(i)) {
        sum++;
      }
    }

    System.out.println(sum);
  }
}


Measured memory_bytes: 40936
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main(){
    double x1,y1,x2,y2;
    double a;
    cin>>x1>>y1>>x2>>y2;
    cout<<fixed<<setprecision(10)<<sqrt(pow((x2-x1),2)+pow((y2-y1),2))<<endl;
}



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

int main(){
    string s;
    cin>>s;
    int n;
    cin>>n;
    vector<string> v;
    for(int i=0;i<s.size();i++){
        for(int j=1;j<=5&&j+i-1<s.size();j++){
            v.push_back(s.substr(i,j));
        }
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    cout<<v.at(n-1)<<endl;
}

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

int f(int n){
  int num = 0;
  int m = n;
  while(m > 0){
    num += m % 10;
    m /= 10;
  }
  return num;
}

int main(){
  int n;
  cin >> n;
  if(n % f(n) == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
  bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[1000007]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
*/

 
const int N = 5e5+1;  // limit for array size
int n;  // array size
bitset<26> t[2 * N];

void build() {  // build the tree
  for (int i = n - 1; i > 0; --i) t[i] = t[i<<1] | t[i<<1|1];
}

void modify(int p, bitset<26> value) {  // set value at position p
  for (t[p += n] = value; p > 1; p >>= 1) t[p>>1] = t[p] | t[p^1];
}

int query(int l, int r) {  // sum on interval [l, r)
  bitset<26> res;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l&1) res |= t[l++];
    if (r&1) res |= t[--r];
  }
  return res.count();
}

signed main(){
  fast;
  //usefile;
  //test
  {
    cin>>n;
    string s;
    cin>>s;
    for (int i = 0; i < n; i++)
    {
      t[n+i].set(s[i]-'a');
    }
    build();
    
    int te;cin>>te;
    while(te--){
      int q;
      cin>>q;
    // cout<<q<<endl;
      if(q==1)  
      {
        int key;
        cin>>key;
        key--;
        char ch;
        cin>>ch;
        bitset<26> temp;
        modify(key,temp.set(ch-'a'));
      }
      else
      {
        int l,r;
        cin>>l>>r;
        l--;
        cout<<query(l,r)<<endl;
        // for (int i = 0; i < 2*n; i++)
        // {
        //   cout<<t[i].count()<<" ";
        // }
        // cout<<endl;
        
      }
      
    }
    
  }
  //time("");
  return 0;
}

Measured memory_bytes: 8732
#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: 8948
n=input().split()
w=int(n[0])
h=int(n[1])
x=int(n[2])
y=int(n[3])
r=int(n[4])
if (r <= x) & (x + r <= w) & (r <= y) & (r + y <= h):
   print("Yes")
else:
   print("No")


Measured memory_bytes: 5596
import itertools

n = int(input())
a = list(range(1,n+1))
p = list(map(int, input().split()))
q = list(map(int, input().split()))
i = 1
ap = 0
aq = 0
for x in list(itertools.permutations(a)):
    if(list(x) == p):
        ap = i
    if(list(x) == q):
        aq = i
    i = i + 1

if(ap > aq):
    print(ap - aq)
    exit()
print(aq - ap)
    



Measured memory_bytes: 8052
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
using namespace std;

int main() {
	char a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	//cout << a << b << c << d << e << f;
	if (a == f && b == e && c == d)
		cout << "YES";
	else
		cout << "NO";
}

Measured memory_bytes: 256
n, m = list(map(lambda x:int(x), input().split()))
 
key_list = {}
 
for i in range(m):
    key_price, _ = list(map(lambda x:int(x), input().split()))
    open_list = list(map(lambda x:int(x), input().split()))
    key_list[i] = [key_price, open_list]
    
situation_val = 1 << n
 
dp = [[float('INF')] * situation_val for i in range(m+1)]
for i in range(m+1):
    dp[i][0] = 0
 
for i in range(m):
    price = key_list[i][0]
    treasure = key_list[i][1]
    key_val = 0
    for v in treasure:
        key_val += (1 << v-1)
        
    for j in range(situation_val):
        key_used_situation = j | key_val
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])
        dp[i+1][key_used_situation] = min(dp[i+1][key_used_situation], dp[i][j]+price)
        
        
ans = dp[m][situation_val-1]

if ans == float('inf'):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 196500
while True:
    n,x = map(int,input().split())
    if n == 0 and x == 0:
        break
    c = 0
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if i + j + k == x:
                    c += 1
    print(c)


Measured memory_bytes: 5588
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

signed main(void)
{
  string s;
  cin >> s;
  int cnt = 0;
  REP(i, 3) if(s[i] == '1') cnt++;
  cout << cnt << endl;

  return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N)
    {
        cin >> A[i];
    }
    sort(ALL(A));

    vector<ll> sumA(N);
    sumA[0] = A[0];
    REP(i, N - 1)
    {
        sumA[i + 1] = sumA[i] + A[i + 1];
    }
    ll ans = 1;
    REP(i, N - 1)
    {
        if (A[N - 1 - i] <= 2 * sumA[N - 2 - i])
        {
            ans++;
        }
        else
        {
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4752
#include<iostream>
#include<stdio.h>
#include<string>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<string.h>
#include<cctype>
#include<map>
#include<set>
#include<vector>
#include<sstream>
 
using namespace std;
 
int main()
{
  int n;
  int total=100000;
  cin>>n;
  while(n--)
  {
    total=(int)(total*1.05);
    if(total%1000==0) continue;
    else total=(total/1000+1)*1000;          
  }
  cout<<total<<endl;
  //while(1);      
  return 0;    
}

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int limit = in.nextInt();
		int[][] graph = new int[limit][limit];
		for(int i = 0; i < limit; i++) {
			int index = in.nextInt();
			int neighbors = in.nextInt();
			for(int j = 0; j < neighbors; j++) {
				graph[i][in.nextInt() - 1] = 1;
			}
		}
		in.close();
		Boolean[] searched = new Boolean[limit];
		for(int i = 0; i < limit; i++) {
			searched[i] = false;
		}
		int[] time_searched = new int[limit];
		int[] done_searching = new int[limit];
		int curr_time = 0;
		for(int i = 0; i < limit; i++) {
			if(!searched[i])
			curr_time = DFS(graph, searched, time_searched, done_searching, curr_time + 1, i);
		}
		for(int i = 0; i < limit; i++) {
			System.out.print((i + 1) + " " + time_searched[i] + " " + done_searching[i]);
			System.out.println();
		}
	}
	
	public static int DFS(int[][] graph, Boolean[] searched, int[] time_searched, int[] done_searching, int curr_time, int node) {
		searched[node] = true;
		time_searched[node] = curr_time;
		for(int i = 0; i < graph.length; i++) {
			if(graph[node][i] == 1 && !searched[i]) {
				curr_time = DFS(graph, searched, time_searched, done_searching, curr_time + 1, i);
			}
		}	
		curr_time++;
		done_searching[node] = curr_time;
		return curr_time;
	}
}



Measured memory_bytes: 28480
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    int n;
    cin >> n;
    vector<int> d(n);
    REP(i, n) cin >> d[i];
    sort(ALL(d));
    if(n%2==1) {
        cout << 0 << endl;
        return 0;
    }
    cout << d[n/2] - d[n/2-1] << endl;
    
    return 0;
}

Measured memory_bytes: 640
import itertools
N,C = list(map(int,input().split()))
D = [list(map(int,input().split())) for i in range(C)]
data = [list(map(int,input().split())) for i in range(N)]
s = []
total = [[0 for i in range(C)] for j in range(3)]
ans = []
for i in range(C):
    s.append(i)

col = list(itertools.permutations(s,3))

for i in range(N):
    for j in range(N):
        total[(i+j+2)%3][data[i][j]-1] += 1

for i in col:
    tempans = 0
    for s in range(3):
        for t in range(C):
            tempans += D[t][i[s]]*total[s][t]
    ans.append(tempans)

print(min(ans))

Measured memory_bytes: 8584
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
typedef long long int ll;

char fi[8][8];
int h=8,w=8;

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

int score(int x,int y,char c){
    int res=0;
    for(int k=0;k<8;k++){
        int cnt=0;
        bool ed=0;
        int nx=x+dx[k],ny=y+dy[k];
        while(0<=nx&&nx<h&&0<=ny&&ny<w){
            if(fi[nx][ny]=='.')break;
            else if(c!=fi[nx][ny]){
                cnt++;
            }
            else{
                ed=1;
                break;
            }
            nx+=dx[k];
            ny+=dy[k];
        }
        if(ed){
            res+=cnt;
        }
    }
    return res;
}

void update(int x,int y){
    for(int k=0;k<8;k++){
        int cnt=0;
        bool ed=0;
        int nx=x+dx[k],ny=y+dy[k];
        while(0<=nx&&nx<h&&0<=ny&&ny<w){
            if(fi[nx][ny]=='.')break;
            else if(fi[x][y]!=fi[nx][ny]){
                cnt++;
            }
            else{
                ed=1;
                break;
            }
            nx+=dx[k];
            ny+=dy[k];
        }
        if(ed){
            for(int i=1;i<=cnt;i++){
                fi[x+dx[k]*i][y+dy[k]*i]=fi[x][y];
            }
        }
    }
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> fi[i][j];
        }
    }
    int stop=0;
    int turn=0;
    while(1){
        int mx=0;
        int x,y;
        if(turn==0){
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    if(fi[i][j]=='.'){
                        if(mx<score(i,j,'o')){
                            mx=score(i,j,'o');
                            x=i,y=j;
                        }
                    }
                }
            }
        }
        else{
            for(int i=h-1;i>=0;i--){
                for(int j=w-1;j>=0;j--){
                    if(fi[i][j]=='.'){
                        if(mx<score(i,j,'x')){
                            mx=score(i,j,'x');
                            x=i,y=j;
                        }
                    }
                }
            }
        }
        if(mx==0){
            //break;
            stop++;
        }
        else{
            fi[x][y]=(turn?'x':'o');
            update(x,y);
            stop=0;
        }
        if(stop>2)break;
        turn^=1;
    }
    for(int i=0;i<8;i++){
        for(int j=0;j<8;j++){
            printf("%c",fi[i][j]);
        }
        printf("\n");
    }
}


Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll 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 fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
struct Unionfind{
    vector<int> data;
    Unionfind(int size):data(size, -1) {}
    bool unite(int x, int y){
        x=root(x);
        y=root(y);
        if(x!=y){
            if(data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x!=y;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    int root(int x){
        return (data[x] < 0) ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n,t; cin >> n >> t;
    t/=2;
    vector<int> a(n);
    vector<P> v(n);
    vector<int> ve(n);
    rep(i,n){
        cin >> a[i];
        v[i]={a[i],i};
    }
    sort(ALL(v));
    rep(i,n) ve[i]=v[i].fi;
    vector<int> sum(n);
    sum[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--){
        sum[i]=max(sum[i+1],a[i]);
    }
    int d=0;
    rep(i,n){
        if(sum[i]-a[i]>d){
            d=sum[i]-a[i];
        }
    }

    int ans=0;
    vector<bool> ok(n,1);
    rep(i,n){
        int p=(int)(lower_bound(ALL(ve),a[i]+d)-ve.begin());
        while(p<n&&v[p].fi==d+a[i]){
            if(i<v[p].se&&ok[v[p].se]==1){
                ok[v[p].se]=0;
                ans++;
                break;
            }
            p++;
        }
    }
    cout << ans << endl;
}


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

int main() {

	int n;
	scanf("%d", &n);

	int x = (n * 100) / 108;
	if((x - 1) * 108 / 100 == n) {
		printf("%d\n", x - 1);
	}else if(x * 108 / 100 == n) {
		printf("%d\n", x);
	}else if((x + 1) * 108 / 100 == n) {
		printf("%d\n", x + 1);
	}else {
		printf("%s\n", ":(");
	}
}

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

const int MOD = 1e9+7;

int main(){
  int n;
  string s;
  cin>>n>>s;
  map<char,int> mp;
  rep(i,n){
    mp[s[i]]++;
  }
  ll ans=1;
  for(auto x : mp){
    ans*=(x.second+1);
    ans%=MOD;
  }
  ans--;
  cout<<ans<<endl;
}


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

int main() {
	int N, x[100], y[100], h[100];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}

	for (int Cx = 0; Cx <= 100; Cx++) {
		for (int Cy = 0; Cy <= 100; Cy++) {
			int H = -1; // -1:未確定
			int Hmax = 2e9;
			bool success = true;
			for (int i = 0; i < N; i++) {
				int distance = abs(Cx - x[i]) + abs(Cy - y[i]);
				if (h[i] > 0) {
					int H2 = h[i] + distance;
					if (H > 0 && H != H2) {
						success = false;
						break;
					} else H = H2;
				} else Hmax = min(Hmax, distance);
			}
			if (success && H <= Hmax) {
				cout << Cx << " " << Cy << " " << H << endl;
			}
		}
	}

	return 0;
}

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

void p(int nu, int key){
//cout<<"dckjw"<<nu<<" "<<key<<endl;
string s[10]={"",".,!?","cab","fde","igh","ljk","omn","spqr","vtu","zwxy"};
if(key==1){
nu=nu%5;
if(nu==0) cout<<" ";
else cout<<s[1][nu-1];
}
if(key==2){
nu=nu%3;
//cout<<s[2];
cout<<s[2][nu];
}
if(key==3){
nu=nu%3;
cout<<s[3][nu];
}
if(key==4){
nu=nu%3;
cout<<s[4][nu];
}
if(key==5){
nu=nu%3;
cout<<s[5][nu];
}
if(key==6){
nu=nu%3;
cout<<s[6][nu];
}
if(key==7){
nu=nu%4;
cout<<s[7][nu];
}
if(key==8){
nu=nu%3;
cout<<s[8][nu];
}
if(key==9){
//cout<<"9ban "<<nu<<endl;
nu=nu%4;
cout<<s[9][nu];
}


}
int main(){
string s;
int n,l;
cin>>n;
for(int www=0;www<n;www++){
cin>>s;
l=s.length();
int nu=1,key;
key=s[0]-'0';


for(int j=0;j<l-1;j++){
if(s[j]!=s[j+1]){
p(nu,key);
nu=1;
key=s[j+1]-'0';
}
else{
nu++;
}

}
p(nu,key);
cout<<endl;
}
return 0;
}

Measured memory_bytes: 1212
from collections import Counter
N=int(input())
S=input()
mod = 10**9+7
d = Counter(S)
ans = 0
for i in S:
    tmp = 1
    d[i] -=1
    for k,v in d.items():
        if i!=k and v:
            tmp *=(v+1)
            tmp%=mod
    ans += tmp
    ans %=mod
print(ans)

Measured memory_bytes: 3572
use std::collections::VecDeque;

const INF: u64 = std::u64::MAX / 2;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let m: usize = sc.read();
    let mut graph = vec![vec![]; n];
    for _ in 0..m {
        let v = sc.read::<usize>() - 1;
        let u = sc.read::<usize>() - 1;
        graph[v].push(u);
    }
    let s = sc.read::<usize>() - 1;
    let t = sc.read::<usize>() - 1;

    let mut dist = vec![vec![INF; n]; 3];
    dist[0][s] = 0;

    let mut q = VecDeque::new();
    q.push_back((s, 0));
    while let Some((v, step)) = q.pop_front() {
        if v == t && step == 0 {
            println!("{}", dist[step][t] / 3);
            return;
        }
        let next_step = (step + 1) % 3;
        for &next in graph[v].iter() {
            if dist[next_step][next] > dist[step][v] + 1 {
                dist[next_step][next] = dist[step][v] + 1;
                q.push_back((next, next_step));
            }
        }
    }
    println!("-1");
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 14588
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}


int n;

signed main(){
	write(read(n)*180-360);
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int cnt[10000005];
void divisor()
{
    for(int i=1;i<=10000005;i++)cnt[i]=1;
    for(int i=2;i<=10000000;i++){
        for(int j=i;j<=10000000;j+=i)
            cnt[j]++;
    }
}
int main()
{
    divisor();
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++)
        ans+=i*cnt[i];
    cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

int main()
{
    int w, h, n;
    cin >> w >> h >> n;
    vector<int> x(n), y(n), a(n);
    rep(i, n) cin >> x[i] >> y[i] >> a[i];

    int xx = 0, yy = 0;
    rep(i, n)
    {
        if (a[i] == 1)
        {
            xx = max(x[i], xx);
        }
        else if (a[i] == 2)
        {
            w = min(w, x[i]);
        }
        else if (a[i] == 3)
        {
            yy = max(y[i], yy);
        }
        else
        {
            h = min(y[i], h);
        }
    }
    int ans = 0;
    if (h > yy && w > xx)
    {
        ans = (h - yy) * (w - xx);
    }

    cout << ans << endl;
    return (0);
}


Measured memory_bytes: 3640
#include<iostream>

using namespace std;

int main(){
	double x1, y1, x2, y2, x3, y3, px, py;
	double det, s, t;

	// 入力の終わりまでループ
	while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> px >> py){
		// 係数行列の行列式を計算
		det = ((x2 - x1) * (y3 - y1)) - ((x3 - x1) * (y2 - y1));
		// 係数行列の行列式が0でないことを確かめる
		if(det == 0){
			cerr << "行列式の値が0です" << endl;
			return -1;
		}

		// s, t の値を求める
		s = (((y3 - y1) * (px - x1)) + ((x1 - x3) * (py - y1))) / det;
		t = (((y1 - y2) * (px - x1)) + ((x2 - x1) * (py - y1))) / det;

		// 結果の判定・表示
		if((s > 0) && (s < 1) && (t > 0) && (t < 1) && ((s + t) < 1)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1220
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<int, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 30010;
const int MAXK = 16;
const int MAXQ = 200010;

int n, k, a[MAXN], f[MAXN];
map<int, int> ma;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k;
    FOR(i,1,n) cin >> a[i];
    FOR(i,1,n) a[i] = a[i] % k;
    FOR(i,1,n) a[i] = (a[i] - 1 + k) % k;
    ma[0] = 1;
    int sum = 0;
    ll res = 0;
    f[0] = sum;
    FOR(i,1,n) {
        if (i - k >= 0) ma[f[i-k]]--;
        sum = (sum + a[i]) % k;
        if (ma.count(sum)) res += ma[sum];
        ma[sum]++;
        f[i] = sum;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 11264
arr = Array.new(4){Array.new(13)}

for i in 0..3
for j in 0..12
 arr[i][j] = true
end
end

n = gets.to_i

for i in 1..n
suit, r =  gets.split
rank = r.to_i

if suit == "S"
 arr[0][rank-1] = false
elsif suit == "H"
 arr[1][rank-1] = false
elsif suit == "C"
 arr[2][rank-1] = false
else suit == "D"
 arr[3][rank-1] = false
end
end

su = ["S", "H", "C", "D"]

for i in 0..3
 for j in 1..13
if arr[i][j-1]
 puts su[i] + " " + j.to_s
end
end
end

 




Measured memory_bytes: 6864
import sys

input = sys.stdin.readline

def main():
    N, K, Q = map(int, input().split())
    a = [0]*N
    for _ in range(Q):
        a[int(input())-1] += 1
    for i in range(N):
        if a[i] - Q + K > 0:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 4680
from itertools import accumulate
from collections import Counter

N,M=list(map(int,input().split()))
S=[0]+list(accumulate(map(int,input().split())))

modlst=[]

for s in S:
    modlst.append(s%M)

c=Counter(modlst)
ans=0

for v in c.values():
    ans+=v*(v-1)//2

print(ans)

Measured memory_bytes: 63896
#include <bits/stdc++.h>
#include <stdlib.h>
#include <time.h> 
 
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e7;
double EPS = 1e-12;
typedef long long int lld;
long double tick(){static clock_t oldt; clock_t newt=clock();
    long double diff=1.0L*(newt-oldt)/CLOCKS_PER_SEC; oldt = newt; return diff; }
#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define repI(i,a,n) for(int i = (a); i <= (n); ++i)
#define repD(i,a,n) for(long long int i = (a); i >= (n); --i)
#define repDI(i,a,n) for(int i = (a); i >= (n); --i)
inline lld sc() { lld a; scanf("%lld", &a); return a; }
inline int scd() { int a; scanf("%d", &a); return a; }
inline double scf() { double a; scanf("%lf",&a); return a; }
#define prL(a) printf("%lld\n",a)
#define prS(a) printf("%lld ",a)
#define prdL(a) printf("%d\n",a)
#define prdS(a) printf("%d ",a)
#define all(c) (c).begin(), (c).end()
#define sz(a) ((int)a.size())
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
#define errorpair(a) cout<<#a<<" = ( "<<((a).first)<<" , "<<((a).second)<<" )\n";
#define mset(a, v) memset(a, v, sizeof(a))
#define popcount __builtin_popcountll

typedef pair<lld,lld> PA;

lld powP(lld x, lld y) {
    lld ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}
 
bool bitSet(lld n, lld bit){
    if((n & (1LL << bit)) != 0) return true;
    else return false;
}
 
lld findGcd(lld a, lld b){
    while(a != 0) { lld temp = b % a; b = a; a = temp; }
    return b;
}

#define lim 300010
#define lim2 200010
#define qqqqqq 210
// Ab :)
// inline lld sqr(lld x) { return x * x; }
// unordered_map<lld,lld>::iterator it;
// std::ios::sync_with_stdio(false);
// priority_queue<PA> Q;
// lld dp[1<<18];

// vector<lld> G[lim];
// string S[lim];
// lld A[lim];
#define PI          3.1415926535897932384626


int main(){
    lld A = sc(), B = sc(), H = sc(), M = sc();
    double hourAngle = (H * 60 + M) / 2.0;
    double minuteAngle = M * 6;
    double angle = abs(hourAngle - minuteAngle);
    angle = min(angle, 360 - angle);
    angle = angle * PI / 180;
    // Error(angle, cos(angle));
    printf("%0.12lf\n", sqrt(A * A + B * B - 2 * A * B * cos(angle)));
    return 0;
}


Measured memory_bytes: 4320
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

LL solve(){
	int n, m;
	scanf("%d%d", &n, &m);
	vector<vector<pll>> G(n);
	for(int i = 0; i < m; ++i){
		int l, r, c;
		scanf("%d%d%d", &l, &r, &c);
		G[l - 1].emplace_back(r, c);
	}

	priority_queue<pll> pq;
	LL d = 0;
	for(int i = 0; i < n - 1; ++i){
		for(cauto e : G[i]){
			pq.emplace(d - e.second, e.first);
		}
		while(!pq.empty()){
			auto t = pq.top();
			if(i < t.second - 1){
				break;
			}
			pq.pop();
		}
		if(pq.empty()){
			return -1;
		}
		d = pq.top().first;
	}
	return -d;
}

void mainmain(){
	cout << solve() << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 7032
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;

void myprint1D(vi &data)
{
  REP(i,data.size())
    cout<<data[i]<<" ";
  cout<<endl;
}

//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
  REP(i,data.size())
    myprint1D(data[i]);
}

//配列を[x][y]で表示
void myprint2D(vvi &data)
{
  ll l1=data.size();
  ll l2=data[0].size();
  REP(j,l2){
    REP(i,l1)
      cout<<data[i][j]<<" ";
    cout<<endl;
  }
}

//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}


ll n,k,x,y;


//moddivとnCk
//c剰余下でaをbで割った値
ll moddiv(ll a,ll b,ll c){
	ll x0=c,x1=b,x2,n0=0LL,n1=1LL,n2,t=a%b,m,ans;
	if (t==0LL) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=(n0-m*n1)%c;
      if (x2==1LL){
        ans=(n2+c)%c;
        break;
      }
      x0=x1;x1=x2;
      n0=n1;n1=n2;
    }
	return (a+((t*ans)%c)*b-t)/b;
}
//剰余の割ざん

//aのn乗 mod c
ll expmod(ll a,ll n,ll c){
  ll ans=1LL,aa=a,beki=n;
  for(int i=0;i<64;i++){
    if (beki%2==1LL) ans=ans*aa%c;
    aa=aa*aa%c;
    beki/=2LL;
    if (beki==0LL)break;
  }
  return ans;
}

//nCk
vi mulmod(500001);//0!,1!,2!,3!,4!,,,,
void first_nCk(){
  mulmod[0]=1LL;
  for(ll i=1;i<500001;i++){
    mulmod[i]=mulmod[i-1]*i%MOD;
  }
}
ll nCk(ll nn,ll kk){
  return moddiv(mulmod[nn],mulmod[kk]*mulmod[nn-kk]%MOD,MOD);
}

ll modinv(ll a,ll b){
  return moddiv(1,a,b);
}

ll garner(ll a,ll b,ll ar,ll br){
  return ar+(br-ar+b)%b*modinv(a,b)%b*a;
}
ll garner2(ll a,ll b,ll ar,ll br){
  ar%=a;
  br%=b;
  ll ret=(ar+(br-ar)%b*moddiv(1,a,b)%b*a+a*b)%(a*b);
  return ret;
}

ll gcd(ll a,ll b){
  ll r = a % b;
  while(r!=0LL){
    a = b;
    b = r;
    r = a % b;
  }
return b;
}





int main(){
  ll ans=0;
  cin >> n;

  if (n==1){
    cout<<1<<endl;
    return 0;
  }
  if (n%2==0){
    ans=2*n-1;
  }else{
    ans=n-1;
  }

  n*=2;
  for(ll i=2;i<=n+2;i++){
    if (i*i>n)break;
    if (n%i==0){
      ll val0=i;
      ll val1=n/i;
      if (val0==1)continue;
      if (val1==1)continue;
      if (gcd(val0,val1)==1){
        ll ans0=garner2(val0,val1,1,0)-1;
        ll ans1=garner2(val0,val1,0,1)-1;
        //ans0%=val0*val1;
        //ans1%=val0*val1;
        if (ans0>1)
          ans=min(ans,ans0);
        if (ans1>1)
          ans=min(ans,ans1);
      }
    }
  }


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

Measured memory_bytes: 7056
function main(input: string) {
  const lines = input.trim().split('\n')

  const [n] = lines[0].split(' ').map(Number)
  const h = lines[1].split(' ').map(Number)
  let v = 0
  const ok = h.every(hi => {
    if (v <= hi) {
      v = hi
      return true
    }
    return v <= hi + 1
  })
  console.log(ok ? 'Yes' : 'No')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

int main()
{
    int a,b;cin>>a>>b;
    int sum=a+b;
    if(sum%3==0||a%3==0||b%3==0)
        cout<<"Possible";
    else cout<<"Impossible";

    return 0;
}


Measured memory_bytes: 3592
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		a, _ := strconv.Atoi(scanner.Text())
		b := float64(a)
		c := b * float64(2) * 3.1415
		fmt.Println(c)
	}
}


Measured memory_bytes: 1756
import sys
input = sys.stdin.readline

base = 1000
mod = 10**23 + 117

N = int(input())
S = [input().rstrip()[::-1] for _ in range(N)]
S.sort(key=lambda s: -len(s))
cnt = {}
ans = 0
one = [0] * 26
for s in S:
    n = len(s)
    if n == 1:
        ans += one[ord(s[0]) - ord('a')]
        continue
    hashes = [0] * (n - 1)
    hashes[0] = ord(s[0])
    for i in range(1, n - 1):
        hashes[i] = (hashes[i-1] * base + ord(s[i])) % mod
    if hashes[-1] in cnt:
        ans += cnt[hashes[-1]][ord(s[-1]) - ord('a')]
    found = [0] * 26
    found[ord(s[-1]) - ord('a')] = 1
    for i in range(n - 2, 0, -1):
        found[ord(s[i]) - ord('a')] = 1
        if hashes[i-1] not in cnt:
            cnt[hashes[i-1]] = [0] * 26
        for c in range(26):
            cnt[hashes[i-1]][c] += found[c]
    found[ord(s[0]) - ord('a')] = 1
    for c in range(26):
        one[c] += found[c]
print(ans)


Measured memory_bytes: 552728
#include<stdio.h>

int main(){
    int a, temp, digit, sum = 0;;
    scanf("%d", &a);
    temp=a;
    while (a > 0)
    {
        digit = a % 10;
        sum  = sum + digit;
        a /= 10;
    }
    if (temp%sum==0)
    printf("Yes\n");
    else if (temp%sum!=0)
    printf("No\n");
    return 0;
}






Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second

using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};
int a, b;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> a >> b;
    if (a <= b) cout << a << endl;
    else cout << a - 1 << endl;
    return 0;
}



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


#define int long long 


const int N = 2e5 + 7, mod = 998244353;


int t[N << 2], lzy[N << 2], pwr[N], hsh[10][N];


void pushDown(int v, int l, int r) {
	if(lzy[v]) {
		t[v] = hsh[lzy[v]][r - l + 1];
		if(l ^ r) {
			lzy[v * 2] = lzy[v];
			lzy[v * 2 + 1] = lzy[v];
		}
		lzy[v] = 0;
	}
}

void modify(int v, int l, int r, int L, int R, int x) {
	pushDown(v, l, r);
	if(l > R || r < L) return;
	if(l >= L && r <= R) {
		lzy[v] = x;
		pushDown(v, l, r);
		return;
	}
	int mid = (l + r) / 2;
	modify(v * 2, l, mid, L, R, x);
	modify(v * 2 + 1, mid + 1, r, L, R, x);
	t[v] = (t[v * 2] * pwr[r - mid] + t[v * 2 + 1]) % mod;
}

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, q; cin >> n >> q;
	pwr[0] = 1;
	for(int i = 1; i <= n; i++) {
		pwr[i] = (pwr[i - 1] * 10) % mod;
	}

	for(int i = 1; i <= 9; i++) {
		for(int j = 1; j <= n; j++) {
			hsh[i][j] = (hsh[i][j - 1] * 10 + i) % mod;
		}
	}

	modify(1, 1, n, 1, n, 1);

	for(int i = 1; i <= q; i++) {
		int l, r, x; cin >> l >> r >> x;
		modify(1, 1, n, l, r, x);
		cout << t[1] << endl;
	}
}

Measured memory_bytes: 27340
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  int k = 0;
  while (n >= 4 && k < 3) {
    if (n % 4 == 0) {
      cout << "Yes";
      return 0;
    }
    n -= 7;
    k++;
  }
  if (n == 0) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int n,m,x;
struct node
{
    int c;
    int a[100];
}q[100];
int ans[100];
int minn1=10000000000;
void dfs(int index,int minn2)
{
    if(index==n)
    {
        if(minn2<minn1)
        {
            int flag=0;
            for(int i=0;i<m;i++)
            {
                if(ans[i]<x)
                {
                    flag=1;
                    break;
                }
            }
            if(flag==0)
            {
                minn1=minn2;
            }
        }
        return;
    }
     for(int i=0;i<m;i++)
    {
        ans[i]+=q[index].a[i];
    }
    dfs(index+1,minn2+q[index].c);
     for(int i=0;i<m;i++)
    {
        ans[i]-=q[index].a[i];
    }
    dfs(index+1,minn2);

}
int main()
{
    scanf("%d%d%d",&n,&m,&x);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&q[i].c);
        for(int j=0;j<m;j++)
        {
            scanf("%d",&q[i].a[j]);
        }
    }
    dfs(0,0);
    if(minn1==1410065408)
    {
        printf("-1\n");
    }
    else
    printf("%d\n",minn1);
}


Measured memory_bytes: 1740
#include <iostream>
using namespace std;
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include<map>
#include<cstdio>

#define ll long long
#define MAX 1000000000
#define INF 1000000000

int main() {
        int n;
        cin>>n;
        int temp = n+(n*n)+(n*n*n);
        cout<<temp<<endl;

}

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

using namespace std;

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    char S[3],T[3];
    rep(i, 3) cin >> S[i];
    rep(i, 3) cin >> T[i];
    int count = 0;
    rep(i, 3) if(S[i]==T[i]) count++;
    cout << count << endl;

}

Measured memory_bytes: 256