akhauriyash/Code-Regression huggingface dataset:
import queue
import sys

write = sys.stdout.write

hoge = list(map(int, input().split()))
H = hoge[0]
W = hoge[1]

class Block:
    visited = False
    parent = None
    def __init__(self, c, x, y):
        self.color = c
        self.x = x
        self.y = y

def trace(A, blk):
    blk.color = "r"
    if blk.x == 1 and blk.y == 1:
        return
    trace(A, blk.parent)

def solve(A):
    global H
    global W

    #ゴールとスタートが黒ならむりぽ
    if A[1][1].color == "#" or A[H][W].color == "#":
        return -1

    q = queue.Queue()
    q.put(A[1][1])
    while not q.empty():
        blk = q.get()
        if blk.x == H and blk.y == W: #ゴールに到達したら通ってきた道を戻って関数を抜け出す
            trace(A, blk)
            return 1
        #上:A[blk.x - 1][blk.y]
        #下:A[blk.x + 1][blk.y]
        #右:A[blk.x][blk.y + 1]
        #左:A[blk.x][blk.y - 1]

        #上
        if A[blk.x - 1][blk.y].visited == False and A[blk.x - 1][blk.y].color == ".":
            A[blk.x - 1][blk.y].parent = blk
            A[blk.x - 1][blk.y].visited = True
            q.put(A[blk.x - 1][blk.y])

        #下
        if A[blk.x + 1][blk.y].visited == False and A[blk.x + 1][blk.y].color == ".":
            A[blk.x + 1][blk.y].parent = blk
            A[blk.x + 1][blk.y].visited = True
            q.put(A[blk.x + 1][blk.y])

        #右
        if A[blk.x][blk.y + 1].visited == False and A[blk.x][blk.y + 1].color == ".":
            A[blk.x][blk.y + 1].parent = blk
            A[blk.x][blk.y + 1].visited = True
            q.put(A[blk.x][blk.y + 1])

        #左
        if A[blk.x][blk.y - 1].visited == False and A[blk.x][blk.y - 1].color == ".":
            A[blk.x][blk.y - 1].parent = blk
            A[blk.x][blk.y - 1].visited = True
            q.put(A[blk.x][blk.y - 1])
    return -1



cnt = 0 #ゴール後の白カウント

maze = [[Block("d", i, j) for j in range(W+2)] for i in range(H+2)]
for i in range(1, H+1):
    row = input()
    for j in range(W):
        maze[i][j+1] = Block(row[j], i, j+1)

possible = solve(maze)

if possible == -1:
    print("-1")
else:
    for i in range(1, H+1):
        for j in range(1, W+1):
            if maze[i][j].color == ".":
                cnt += 1
    print(str(cnt))

Measured memory_bytes: 5360
#include<stdio.h>
#include<limits.h>
#define MAX 100000
int main(){
 int n,i;
 int min=INT_MAX;
 int max=-INT_MAX;
 int x;
 long sum=0;

 scanf("%d",&n);

 for(i=0;i<n;i++){
     scanf("%d",&x);
     if(x > max)max=x;
     if(x < min)min=x;
     sum+=x;

 }

 printf("%d %d %ld\n",min,max,sum);

 return 0;
}


Measured memory_bytes: 2100
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define REP(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  int n, m;
  cin >> n >> m;
  // n-mケースでは100msかかり必ず正解
  // mケースでは1900msかかり1/2の確率で正解
  int total = (100 * (n - m) + m * 1900) * pow(2, m);
  cout << total << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int d = sc.nextInt();
    int n = sc.nextInt();

    int sum = 1;

    for(int i=1;i<=d;i++){
      sum = sum * 100;
    }

    System.out.println(sum*(n+n/100));

  }
}


Measured memory_bytes: 21972
// READ & UNDERSTAND
// ll, int overflow, array bounds
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

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

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n,m,c;
	cin >> n >> m >> c;
	int b[m],ans=0;
	int a[n][m];
	for(int i=0; i<m; i++)cin >> b[i];
	for(int i=0; i<n; i++){
		int cnt=0;
		for(int j=0; j<m; j++){
			cin >> a[i][j];
			cnt += a[i][j]*b[j];
		}
		cnt += c;
		if(cnt>0)ans++;
	}
	cout << ans << endl;
}	


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound 
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int> 
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
    
	const int N =1e5;
    
     int mod= 1e9+7;
     
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};
    
    vi v[N];
     
     void solve(){
          
         int n,m;
         cin>>n>>m;
         
  priority_queue<int> p;
         int sum=0;
         
         while(n--){
			 int x,y;
			  cin>>x>>y;
			  v[x].pb(y);
		 }
		 
		 rep(i,1,m+1){
			 
			for(auto to:v[i])
			   p.push(to);
			
			if(sz(p)) {
				sum+=p.top();
				p.pop();			
			}
	 }
	 cout<<sum<<endl;

     }
   
   
   
   
      int32_t main() {
	    cool;
	    int t=1;
        //cin>>t;
	    while(t--)
	       solve();
	       
	       
	       return 0;	   
	   }


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

int main(){
 long long N,u,c,ans;
  cin>>N>>c;
  if(N+c==15){
  cout<<'+'<<endl;
  }
  else if(N*c==15){
  cout<<'*'<<endl;
  }
  else{
  cout<<"x"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
#define ck(n,a,b) (a<=(n)&&(n)<b)
#define F first
#define S second
typedef long long ll;
using namespace std;

int main(){
	int n;
	cin>>n;
	string s[51];
	map<int,int> m[51];
	REP(i,0,n) {
		cin>>s[i];
		REP(j,0,(int)s[i].size()) m[i][s[i][j]-'a']++;
	}

	string ans="";
	REP(i,0,26){
		int tmp=100;
		char now='a'+i;
		REP(j,0,n) tmp=min(tmp,m[j][i]);
		REP(j,0,tmp){
			ans+=now;
		}
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            String input = Console.ReadLine();
            String[] nums = input.Split(' ');
            int[] a = new int[4];
            for (int i=0; i < 4; i++)
            {
                a[i] = int.Parse(nums[i]);
            }

            int rect1 = a[0] * a[1];
            int rect2 = a[2] * a[3];

            if (rect1 > rect2) {
                Console.WriteLine(rect1);
            }
            else
            {
                Console.WriteLine(rect2);
            }
        }
    }
}


Measured memory_bytes: 11220
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
long long x,k,d; 
int main()
{
	cin>>x>>k>>d;

	x = abs(x);
	if (x >= d)
	{
		long long cnt = x / d;
		cnt = min(cnt, k);
		long long curr = x - d * cnt;
		k-=cnt;
		if (k % 2 == 0) {cout<< curr <<endl; return 0;}
		else			{cout<< abs(curr - d) << endl; return 0;}
	}
	else
	{

		if (k % 2 == 0){cout<<x<<endl; return 0;}
		else		   {cout<<abs(x - d)<<endl; return 0;}
	}
	


return 0;
}

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

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N+1);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // BFS のためのデータ構造
    vector<int> dist(N+1, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 1 を初期ノードとする)
    dist[1] = 0;
    que.push(1); // 1 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

int ans[N+5] = {};

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    for (int v = 2; v <= N; ++v) {
        //cout << v << ": " << dist[v] << endl;
        for (int nv : G[v]) {
            //cout << "v:" << v << " nv:" << nv << endl;
            if(dist[nv]==dist[v]-1) {
                //cout << nv << endl;
                ans[v] = nv;
                break;
            }
        }
    }

    for(int i=2; i<=N; i++) {
        if(ans[i]==0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    for(int i=2; i<=N; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 10564
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	double v, t, y;
	
	while(cin >> v){
		t = v / 9.8;
		y = 4.9*t*t;
		
		for(int i = 1; i > 0; i++){
			if((5*i-5) > y){
				cout << i << endl;
				break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int N=20;
int n,a[N],b[N];
struct node
{
    int x,p;
    node(int x=0,int p=0):x(x),p(p){}
}c[N];
int d[N];
int solve(int x)
{
    for(int i=0;i<n;i++)
        if(x>>i&1)
            c[i+1]=node(b[i+1],1),d[i+1]=b[i+1];
        else
            c[i+1]=node(a[i+1],0),d[i+1]=a[i+1];
    sort(d+1,d+1+n);
    int ans=0;
    for(int i=n;i>=1;i--)
    {
        bool flag=false;
        for(int j=i;j>=1;j--)
            if(c[j].x==d[i]&&c[j].p==(i-j&1))
        {
            flag=true;
            ans+=i-j;
            for(int k=j;k<i;k++)
            {
                c[k+1].p^=1;
                swap(c[k],c[k+1]);
            }
            break;
        }
        if(!flag) return inf;
    }
    return ans;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) scanf("%d",&b[i]);
    int ans=inf;
    for(int i=0;i<1<<n;i++)
        ans=min(ans,solve(i));
    if(ans==inf) ans=-1;
    printf("%d\n",ans);
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string s;
    cin >> s;

    vector<char> res;
    for (int i = 0; i < s.length(); i++) {
        switch(s[i]) {
            case '0':
            case '1': res.push_back(s[i]); break;
            case 'B': if (!res.empty()) res.pop_back(); break;
        }
    }

    for (int i = 0; i < res.size(); i++) cout << res[i];
    cout << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> a >> b >> k;
	m = min(a , b);
	for(i=m;i>0;i--) {
		if (a%i==0 && b%i==0) {
			ans++;
			if (k==ans) break;
		}
	}
	cout << i << endl;
	return 0;
}


Measured memory_bytes: 3556
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

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

  int n;
  cin >> n;

  int a = 0;
  int b = 0;
  int ba = 0;
  int ans = 0;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    for (int j = 0; j < s.size() - 1; j++) {
      if (s[j] == 'A' && s[j + 1] == 'B') ++ans;
    }

    if (s.front() == 'B' && s.back() == 'A') ++ba;
    if (s.front() == 'B' && s.back() != 'A') ++b;
    if (s.front() != 'B' && s.back() == 'A') ++a;
  }
  if (ba == 0) {
    ans += min(a, b);
  } else {
    if (a + b == 0) {
      ans += ba - 1;
    } else {
      ans += min(a, b) + ba;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmin(ll &a,ll b){if(a>b) a = b ;}

int main(){
	string s ; cin >> s ;
	ll n = s.size() ;
	if(s.at(0)=='0'||s.at(n-1)=='1') cout << -1 << endl ;
	else{
		for(int i=1;i<=n/2;i++){
			if(s.at(i-1)!=s.at(n-1-i)){
				cout << -1 << endl ;
				return 0 ;
			}
		}
		s.at(n-1) = '1' ;
		ll pre = n ;
		for(int i=n-1;i>0;i--){
			cout << i << " " << pre << endl ;
			if(s.at(i-1)=='1') pre = i ;
		}
	}
}


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

int main(){
  int n; cin >> n;
  int per[n];
  rep(i, n) per[i] = i + 1;
  int p[10];
  int q[10];
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  int cnt_p = 1, cnt_q = 1;
  int ans1, ans2;
  do{
    bool ok_p = true, ok_q = true;
    for(int i = 0; i < n; i++){
      if(p[i] != per[i]) ok_p = false;
    }
    for(int i = 0; i < n; i++){
    if(q[i] != per[i]) ok_q = false;
    }
    if(!(ok_p)) cnt_p++;
    else ans1 = cnt_p;
    if(!(ok_q)) cnt_q++;
    else ans2 = cnt_q;
  }while(next_permutation(per, per + n));
  cout << abs(ans1 - ans2) << endl;
}
        
  

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

int main() {
  long long int x,y;
  cin>>x>>y;
  long long int cnt=0;
  long long int xx=abs(x),yy=abs(y);
  
  if(x==y)
    cnt=0;
  else if(x==0){
    if(y>=0) cnt=yy;
    else cnt=yy+1;
  }
  else if(y==0){
    if(x<0) cnt=xx;
    else cnt=xx+1;
  }
  else if(xx==yy)
    cnt=1;
  else if(xx<yy){
    if(x>0 && x<y) cnt=yy-xx;
    else if(x<0 && x<y) cnt=yy-xx+1;
    else if(x>0 && y<x) cnt=yy-xx+1;
    else cnt=yy-xx+2;
  }
  else {
    if(x>0){
      if(y>0) cnt=xx-yy+2;
      if(y<0) cnt=xx-yy+1;
    }
    else {
      if(y>0) cnt=xx-yy+1;
      else cnt=xx-yy;
    }
  }
  
  cout<<cnt;
    
  
  
}

Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>str>>stra;
    rep(i,3){
        if(str[i]==stra[i]) sum++;
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
#include <cmath>
#include <numeric>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    string S;
    cin >> S;

    string s1 = S.substr(0, 2), s2 = S.substr(2);

    if((1 <= stoi(s1) && stoi(s1) <= 12) && (1 <= stoi(s2) && stoi(s2) <= 12)){
        cout << "AMBIGUOUS" << endl;
    }else if(1 <= stoi(s1) && stoi(s1) <= 12){
        cout << "MMYY" << endl;
    }else if(1 <= stoi(s2) && stoi(s2) <= 12){
        cout << "YYMM" << endl;
    }else{
        cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

int main() {
	ll k, a, b;
	cin >> k >> a >> b;

	ll s = k - a + 1;
	if (k <= a - 1 || b - a <= 2)puts(k + 1);
	else puts(a + (s/2) * (b - a) + (s%2));
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

double gaiseki(double[2], double[2]);

int main(){
	double triPoint1[2];	//三角形の点1
	double triPoint2[2];	//三角形の点2
	double triPoint3[2];	//三角形の点3
	double pPoint[2];		//点Pの座標

	while (std::cin >> triPoint1[0] >> triPoint1[1]
		>> triPoint2[0] >> triPoint2[1]
		>> triPoint3[0] >> triPoint3[1]
		>> pPoint[0] >> pPoint[1]){
		double vector1_2[2] = { triPoint2[0] - triPoint1[0], triPoint2[1] - triPoint1[1] };
		double vector1_p[2] = { pPoint[0] - triPoint1[0], pPoint[1] - triPoint1[1] };
		double vector2_3[2] = { triPoint3[0] - triPoint2[0], triPoint3[1] - triPoint2[1] };
		double vector2_p[2] = { pPoint[0] - triPoint2[0], pPoint[1] - triPoint2[1] };
		double vector3_1[2] = { triPoint1[0] - triPoint3[0], triPoint1[1] - triPoint3[1] };
		double vector3_p[2] = { pPoint[0] - triPoint3[0], pPoint[1] - triPoint3[1] };
		
		if ((gaiseki(vector1_2, vector1_p) > 0 && gaiseki(vector2_3, vector2_p) > 0 && gaiseki(vector3_1, vector3_p) > 0)
			|| (gaiseki(vector1_2, vector1_p) < 0 && gaiseki(vector2_3, vector2_p) < 0 && gaiseki(vector3_1, vector3_p) < 0)){
			std::cout << "YES" << std::endl;
		}
		else{
			std::cout << "NO" << std::endl;
		}
	}
	return 0;
}

double gaiseki(double vector1[2], double vector2[2]){
	return vector1[0] * vector2[1] - vector1[1] * vector2[0];
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define ALL(v) v.begin(),v.end()
typedef long long ll;
int main() {
  int r;
  cin >> r;
  cout << r*r << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
const int MOD = 1000000007;
int N, M, f[301][301][301];
std::vector < std::pair < int, int > > V[301];
inline void add(int &x, int y)
{
	x = x + y < MOD ? x + y : x + y - MOD;
}
int main()
{
	scanf("%d%d", &N, &M);
	while (M--)
	{
		int l, r, t;
		scanf("%d%d%d", &l, &r, &t);
		V[r].push_back({ l, t });
	}
	f[0][0][0] = 1;
	for (int i = 0; i < N; i++)
		for (int j = 0; j <= i; j++)
			for (int k = j; k <= i; k++)
			{
				bool check = true;
				for (auto &e : V[i])
					if (1 + (j >= e.first) + (k >= e.first) != e.second)
						check = false;
				if (check)
				{
					add(f[i + 1][j][k], f[i][j][k]);
					add(f[i + 1][j][i], f[i][j][k]);
					add(f[i + 1][k][i], f[i][j][k]);
				}
			}
	int O = 0;
	for (int i = 0; i <= N; i++)
		for (int j = 0; j <= N; j++)
		{
			bool check = true;
			for (auto &e : V[N])
				if (1 + (i >= e.first) + (j >= e.first) != e.second)
					check = false;
			if (check)
				add(O, f[N][i][j]);
		}
	printf("%d\n", O);
	return 0;
}


Measured memory_bytes: 104832
#include<bits/stdc++.h>
using namespace std;
const int maxN = 1e3 + 13;
int n, m, mvx[4] = {0, 0, 1, -1}, mvy[4] = {1, -1, 0, 0};
char a[maxN][maxN];
int main () {
    cin >> n >> m;
    for (int i = 0; i < n; i++)
	for (int j = 0; j < m; j++) 
	    cin >> a[i][j];

    for (int i = 0; i < n; i++)
	for (int j = 0; j < m; j++) {
	    if (a[i][j] == '#') {
		bool fl = 0;
		for (int k = 0; k < 4; k++) {
		    int curx = i + mvx[k], cury = j + mvy[k];
		    if (curx >= 0 && curx < n && cury >= 0 && cury < m && a[curx][cury] == '#')
			fl = 1;
		}
		if (!fl)
		    return cout << "No" << endl, 0;
	    }
	}
    cout << "Yes" << endl;
}
	   
    


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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

string s;
int k, len = 1;
LL ans;

signed main() {
	cin >> s;
	read(k);
	if (k == 1 || s[0] != s[(int) s.size() - 1]) {
		for (int i = 1; i < (int) s.size(); ++i)
			if (s[i] == s[i - 1]) ++len;
			else {
				ans += len / 2;
				len = 1;
			}
		ans += len / 2;
		write(ans * k);
		putchar('\n');
	} else {
		int l, r;
		for (l = 1; s[l] == s[l - 1] && l < (int) s.size(); ++l);
		for (r = s.size() - 1; s[r] == s[r - 1] && r; --r);
		if (l >= r) {
			write((int) s.size() * k / 2);
			putchar('\n');
		} else {
			for (int i = l + 1; i < r; ++i)
				if (s[i] == s[i - 1]) ++len;
				else {
					ans += len / 2;
					len = 1;
				}
			ans += len / 2;
			write(ans * k + l / 2 + ((int) s.size() - r) / 2 + 
			((int) s.size() - r + l) / 2 * (k - 1));
			putchar('\n');
		}
	}
	return 0;
}


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


int main()
{
	int x, y, c[] = {0,1,-1,1,0,1,0,1,1,0,1,0,1};
	cin >> x >> y;
	cout << (c[x] == c[y] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n;
	cin >> n;
	vector<P> p(n);
	for (int i = 0; i < n; i++) {
		ll a, b;
		cin >> a >> b;
		p[i] = P(b, a);
	}
	sort(p.begin(), p.end());
	ll sum  = 0;
	bool ok = true;
	for (int i = 0; i < n; i++) {
		sum += p[i].second;
		if (sum > p[i].first) {
			ok = false;
		}
	}
	dump(ok ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 3456
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())

b = a[:]
max_a = max(a)
b.remove(max_a)
next_max_a = max(b)

for m in a:
    if m == max_a:
        print(next_max_a)
    else:
        print(max_a)


Measured memory_bytes: 15728
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001001;
const int NMAX=8;
const int MOD=1000000007;
const int dbase=80*160;

int main()
{
	ll n,m;
	cin>>n>>m;
	vector<ll> a(n);
	vector<ll> asum(n);
	vector<ll> sum(n+1);
	rep(i,n)cin>>a[i];
	sort(a.begin(),a.end());
	ll l=0;
	ll r=a[n-1]*2+1;
	while (l+1<r){
		ll c=(l+r)/2;
//	int c=30;
		//c以上の手になるひとの数
		ll now=0;
		rep(i,n){
			ll temp=c-a[i];
			ll id=lower_bound(a.begin(),a.end(),temp)-a.begin();
		//	cout<<n-id<<'n'<<c<<'c'<<i<<'i'<<endl;
			now+=n-id;
		}
		if (now<m)r=c;
		else l=c;
	}
//	cout<<r<<endl;
	ll ans=0;

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

	for(ll i=n-1;i>=0;i--){
		sm+=a[i];
		asum[i]=sm;
	}
	ll cnt=0;
	rep(i,n){
	//	if (cnt>=m)break;
	ll temp=l-a[i];
	 ll id=upper_bound(a.begin(),a.end(),temp)-a.begin();
			ans+=a[i]*(n-id);
			ans+=sum[n]-sum[id];
		cnt+=n-id;
	}
//	cout<<l<<'l'<<endl;
//	cout<<cnt<<'c'<<endl;
//	cout<<m<<'m'<<endl;
	ans+=l*(m-cnt);

cout<<ans<<endl;

}


Measured memory_bytes: 2560
import sys

H, W = map(int, input().split())

rows = []
for i in range(H):
    chars = list(input())
    rows.append([1 if c == '#' else 0 for c in chars])


def is_possible(rows):
    for h in range(H):
        for w in range(W):
            if rows[h][w] == 0:
                continue

            pair_candidates = []
            if w - 1 >= 0:
                pair_candidates.append((h, w - 1))
            if w + 1 < W:
                pair_candidates.append((h, w + 1))
            if h - 1 >= 0:
                pair_candidates.append((h - 1, w))
            if h + 1 < H:
                pair_candidates.append((h + 1, w))
            pair_candidates_sum = sum([
                rows[_h][_w] for _h, _w in pair_candidates
            ])

            if pair_candidates_sum == 0:
                return False

    return True


if is_possible(rows):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007



int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	if(a>n||b>n){
		cout << -1 << endl;
		return 0;
	}
	ll c = n;
	deque<ll> dq;
	per(i,1,a+1){
		dq.push_front(i);
	}
	ll index = a+1;
	ll de = 1;
	c-=a;
	while(1){
		ll d1 = c/a;
		if(c%a!=0)d1++;
		if(b<de+d1){
			cout << -1 << endl;
			return 0;
		}
		if(b>de+c){
			cout << -1 << endl;
			return 0;
		}
		if(c>b-de){
			ll mn = min(c-(b-de)+1,a);
			per(i,index,index+mn){
				dq.push_front(i);
			}
			c-=mn;
			index += mn;
			de++;
		}
		else{
			rep(i,index,n+1){
				dq.push_front(i);
			}
			break;			
		}
	}
	vector<ll> ans;
	while(!dq.empty()){
		ans.pb(dq.front());
		dq.pop_front();
	}
	rep(i,0,ans.sz){
		cout << ans[i];
		if(i!=ans.sz-1)cout << " ";
	}
	cout << endl;
	
	return 0;
}





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

int n,t;
int a[100005];
int f[100005];
int p[100005];
int mx,cnt;

int main(){

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

    cin>>n>>t;
    f[0]=1e9;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        f[i]=min(f[i-1],a[i]);
        p[i]=max(a[i]-f[i-1],0);
        if(p[i]>mx){
            mx=p[i];
            cnt=1;
        }else{
            if(p[i]==mx){
                cnt++;
            }
        }
    }
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 1408
N, C, K = map(int, input().split())
T = [int(input()) for _ in range(N)]
T.sort()
fstTime = 0
pasCnt= 0
ans = 1
for i in T:
  if fstTime == 0:
    fstTime = i
#  print(i - fstTime <= K , pasCnt <= C, fstTime, pasCnt)
  if i - fstTime <= K and pasCnt < C:
    pasCnt += 1
  else:
    ans += 1
    fstTime = i
    pasCnt = 1
print(ans)

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

using namespace std;

int n, k;
int stones[100];
bool memo[100001] = {};
bool done[100001] = {};

bool dp(bool player, int rem)
{
    if (done[rem])
    {
        if (memo[rem])
            return player;
        else
            return !player;
    }

    for (int i = 0; i < n; i++)
    {
        if (rem - stones[i] < 0)
        {
            done[rem] = true;
            memo[rem] = false;
            return !player;
        }
        if (player == dp(!player, rem - stones[i]))
        {
            done[rem] = true;
            memo[rem] = true;
            return player;
        }
    }
    done[rem] = true;
    memo[rem] = false;
    return !player;
    
}

int main(void)
{
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &stones[i]);
    }
    if (!dp(0, k))
        printf("First\n");
    else
        printf("Second\n");
}

Measured memory_bytes: 11684
#include<bits/stdc++.h>
#define ll long long
#define p 998244353
using namespace std;
int jc[10000010],njc[10000010],inv[10000010],n,mi[10000010];
int C(int x,int y){
	return 1ll*jc[x]*njc[y]%p*njc[x-y]%p;
}
int main(){
	for(int i=0;i<2;i++)jc[i]=njc[i]=inv[i]=1;
	int n;cin>>n;
	mi[0]=1;mi[1]=2;
	for(int i=2;i<=n;i++){
		jc[i]=1ll*jc[i-1]*i%p;
		inv[i]=1ll*inv[p%i]*(p-p/i)%p;
		njc[i]=1ll*njc[i-1]*inv[i]%p;
		mi[i]=1ll*mi[i-1]*2%p;
	}
	int ans=1;
	for(int i=1;i<=n;i++)ans=1ll*ans*3%p;
	for(int i=n/2+1;i<=n;i++){
		(ans-=2ll*C(n,i)*mi[n-i]%p)%=p;
	}
	cout<<(ans+p)%p;
	return 0;
}


Measured memory_bytes: 156544
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; i++)
static const long long INF = 1000000;
using p = pair<int64_t,int64_t>;

int main(){
    int a,b,c;
    cin >> a>>b>>c;
    if (a  == b and b == c){
        cout << "No" << endl;
    }
    else if(a != b and b != c and c != a){
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long H, long long N, std::vector<long long> A, std::vector<long long> B){
    LL dp[100001];
    REP(i, H+1) {
        dp[i] = INF;
    }

    dp[0] = 0;
    REP(i, H) {
        REP(j, N) {
            int idx = min(H, i+A[j]);
            dp[idx] = min(dp[idx], dp[i] + B[j]);
        }
    }

    cout << dp[H] << endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(H, N, std::move(A), std::move(B));
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;
typedef std::vector<std::vector<int> > Field;
typedef std::vector<std::vector<bool> > Seen;

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

// DFS
bool dfs(const Field& field, Seen& seen, const int ih, const int iw, const int H, const int W) {
    seen[ih][iw] = true;
    if (field[ih][iw] == 0) return false;
    // search oct
    for (int i = 0; i < 8; ++i) {
        const int curh = ih + dx[i];
        const int curw = iw + dy[i];

        // check the boundaries
        if (curh >= H || curh < 0) continue;
        if (curw >= W || curw < 0) continue;

        if (seen[curh][curw]) continue;

        dfs(field, seen, curh, curw, H, W);
    }
    return true;
}

int search(const Field& field, const int H, const int W) {
    Seen seen(H, std::vector<bool>(W, false));
    int cnt = 0;
    for (int ih = 0; ih < H; ++ih) {
        for (int iw = 0; iw < W; ++iw) {
            if (seen[ih][iw]) continue;
            if (field[ih][iw] == 0) continue;
            if (dfs(field, seen, ih, iw, H, W)) ++cnt;
        }
    }
    return cnt;
}

int main() {
    vector<int> res;
    for (;;) {
        int W, H; cin >> W >> H;
        if ( (W == 0 || H == 0) ) break;
        Field field(H, std::vector<int>(W, 0));
        for (int ih = 0; ih < H; ++ih) {
            for (int iw = 0; iw < W; ++iw) {
                cin >> field[ih][iw];
            }
        }
        res.push_back(search(field, H, W));
    }
    for (unsigned int i = 0; i < res.size(); ++i) {
        cout << res[i] << "\n";
    }
    return 0;
}



Measured memory_bytes: 3392
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000

double get_dis(double a,double b){
	return sqrt(pow(a,2)+pow(b,2));
}

int main(){
	
	double time;
	chrono::system_clock::time_point start, end;
	start = chrono::system_clock::now();
	
	int N;
	cin>>N;
	
	vector<pair<double,double>> D;
	
	for(int i=0;i<N;i++){
		double x,y;
		cin>>x>>y;
		if(x==0&&y==0){
			D.emplace_back(0.0,0.0);
		}
		else{
			D.emplace_back(atan2(y,x),get_dis(x,y));
		}
	}
	
	double ans = 0.0;
	sort(D.begin(),D.end());
	
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			int start = i;
			int goal = j;
			if(i>j)goal+=N;
			
			double x = 0.0,y = 0.0;
			
			for(int k=start;k<=goal;k++){
				int A = k%N;
				x += D[A].second * cos(D[A].first);
				y += D[A].second * sin(D[A].first);
			}
			ans = max(ans,get_dis(x,y));
			
		}
	}
			
			
	cout<<fixed<<setprecision(20)<<ans<<endl;
		
		
	
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}



  








int main() {
  int a[3];
  rep (i,3){
    cin >> a[i];
  }
  sort (a,a+3);
  cout << a[0]*a[1]/2 << endl;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a > b) {
		int d = a;
		a = b;
		b = d;
	}
	if (b > c) {
		int d = b;
		b = c;
		c = d;
	}
	if (a > b) {
		int d = a;
		a = b;
		b = d;
	}
	cout << a <<" "<< b<<" " << c << endl;
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MAX   1e9
#define MIN  -1e9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
struct Interval {int start, end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll zeros=0,neg=0;
    ll sum=0,mini=MAX;
    rep(i,n)
    {
        cin>>a[i];
        if(a[i]==0)
            zeros++;
        if(a[i]<0)
            neg++;
        mini=min(mini,abs(a[i]));
        sum+=abs(a[i]);
    }
    if(neg%2==0||zeros>0)
        cout<<sum;
    else
        cout<<sum-2*mini;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;cin>>a>>b>>c;
    int m=max(a,b);
    int n=min(a,b);
    for(int i=n;i<=m;i++){
            if(i==c){
                cout<<"Yes";
                return 0;
            }
    }
    cout<<"No";
    return 0;
}

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

int main() {
  string N;
  cin >>N;
  int a = N.size();
  int sum = 0;
  for(int i = 0;i<a;i++){
    sum+=N.at(i)-'0';}
  if(sum%9==0){
    cout<<"Yes"<<endl;
  }else{cout<<"No"<<endl;
       }
}

Measured memory_bytes: 3756
#include <iostream>
#include <set>

int main(void){
    std::multiset<long> vs1, vs2;
    long Q;
    std::cin >> Q;
    long qi = 0;
    long med = -1;
    long sum_abs = 0;
    long bias = 0;
    for(long ii = 0; ii < Q; ++ii){
        long q;
        std::cin >> q;
        if(q == 1){
            long v, b;
            std::cin >> v >> b;
            qi++;
            bias += b;
            if(qi == 1){
                vs1.insert(v);
                med = v;
            } else if(qi == 2){
                long w = *vs1.begin();
                if(w <= v){
                    vs2.insert(v);
                } else {
                    vs1.clear();
                    vs1.insert(v);
                    vs2.insert(w);
                }
                med = *vs1.begin();
                sum_abs = *vs2.begin() - med;
            } else {
                auto vs1_size = vs1.size(), vs2_size = vs2.size();
                if(*vs1.rbegin() >= v){
                    vs1.insert(v);
                    if(vs1.size()-2 >= vs2.size()){
                        long w = *vs1.rbegin();
                        vs1.erase(--vs1.end());
                        vs2.insert(w);
                    }
                } else {
                    vs2.insert(v);
                    if(vs2.size() > vs1.size()){
                        long w = *vs2.begin();
                        vs2.erase(vs2.begin());
                        vs1.insert(w);
                    }
                }
                long new_med = *vs1.rbegin();
                sum_abs += std::abs(new_med - v);
                sum_abs += std::abs(static_cast<long>((new_med - med) * (vs1_size - vs2_size)));
                med = new_med;
            } // end of insertion
        } else {
            std::cout << med << " " << sum_abs + bias << std::endl;
        }
    }
    return 0;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int H,W;
char a[1000][1000];

ll dp[1001][1001];
void solve(){
	rep(i,H){
		rep(j,W){
			if(i == 0 and j == 0){
				dp[1][1] = 1;
				continue;
			}
			if(a[i][j] == '.')
				dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j]) % MOD;
		}
	}
	cout<<dp[H][W]<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>H>>W;
	rep(i,H)
		rep(j,W) {
			cin>>a[i][j];
		}
		solve();
	return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
	double a, b;
	cin >> a;
	cin >> b;

	if (a == 1 || b == 1)
		if(b == 2 || a == 2)
			cout << "3" << endl;
	if (a == 2 || b == 2)
		if (b == 3 || a == 3)
			cout << "1" << endl;
	if (a == 1 || b == 1)
		if (b == 3 || a == 3)
			cout << "2" << endl;
	return 0;
}


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

struct Point { double x, y; };

void koch(int n, Point a, Point b) {

    if (n == 0) return;

    Point s, t, u;
    double th = M_PI * 60.0 / 180.0; //DegreeToRadian

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n-1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n-1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n-1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n-1, t, b);

}

int main() {

    Point a, b;
    int n;

    cin >> n;

    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    printf("%.8f %.8f\n", a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n", b.x, b.y);

    return 0;

}


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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for(int i = 0;i < n;i++)
#define INF 1000000000

int n, m, x;

int ans = INF;


void dfs(int i, vector<int> c, vector<vector<int>> a, int total, vector<int> check){
    bool ok = true;
    loop(j, m){
        if(check[j] < x) ok = false;
    }
    if(ok) ans = min(ans, total);

    if(i == n) return;

    dfs(i+1, c, a, total, check);

    loop(j, m){
        check[j] += a[i][j];
    }
    total += c[i];
    dfs(i+1, c, a, total, check);

    
}

int main(void){

    cin >> n >> m >> x;

    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> check(m);
    loop(i, n){
        cin >> c[i];
        loop(j, m){
            cin >> a[i][j];
        }
    }

    dfs(0, c, a, 0, check);

    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define pb push_back
#define MOD 1000000007

typedef long long ll;

ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  ll first, second;
  cin >> first >> second;
  vector<ll> yaku_f, yaku_s;
  
  ll count = 1;
  ll c = euclidean_gcd(first, second);
  if(c % 2 == 0) {
    count++;
    while(c % 2 == 0) {
      c = c / 2;
    }
  }
  for(ll i = 3; i*i <= c; i+=2) {
    if(c%i != 0) continue;
    count++;
    while(c % i == 0) {
      c = c / i;
    }
  }
  if(c!=1) count++;

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	
	public static void main (String[] args) {
		
		Main main = new Main();
		
		main.solve();
	}
	
	private void solve () {
		
		Scanner scanner = new Scanner (System.in);
		
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		
		if (B%A==0) {
			System.out.println(A+B);
		} else {
			System.out.println(B-A);
		}
	}
}


Measured memory_bytes: 25300
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, m=0, a=0, r=0, c=0, h=0, count=0;
    string S[100010];

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> S[i];

        if(S[i][0]=='M') {m++; if(m==1)count++;}
        if(S[i][0]=='A') {a++; if(a==1)count++;}
        if(S[i][0]=='R') {r++; if(r==1)count++;}
        if(S[i][0]=='C') {c++; if(c==1)count++;}
        if(S[i][0]=='H') {h++; if(h==1)count++;}
    }

    if(count<3){
        cout << 0 << endl;
    }

    else{
        cout << m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+
                a*r*c+a*r*h+a*c*h+r*c*h << endl;
    }

    return 0;
}

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

int main()
{
	int n;
    cin>>n;
	int p[n];
	rep(i,n) cin>>p[i];

	int ans=0;
	rep(i,n-2){
		int a=p[i],b=p[i+1],c=p[i+2];
		if(a<b && b<c) ans++;
		else if(a>b && b>c) ans++;
	}
	cout<<ans<<endl;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    
    int permutation[N];
    int input;
    for (int i = 0; i < N; i++)
    {   
        cin >> input;
        permutation[i] = input;
    }
    
    bool swapped = false;
    for (int i = 0; i < N; i++)
    {
        if (permutation[i] != i + 1)
        {
            if (permutation[permutation[i] - 1] == i + 1 && !swapped)
            {
                swapped = true;
                int temp = permutation[i];
                permutation[permutation[i] - 1] = temp;
                permutation[i] = i + 1;
            } else {
                cout << "NO";
                return 0;
            }
        }
    }

    cout << "YES";
}


Measured memory_bytes: 256