akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
//#pragma GCC target ("sse4")
#pragma optimize("fast-math")

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define endl '\n'
#define ull unsigned long long
#define si short int
#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define piii pair<pair<int, int>, int>
#define all(vec) (vec).begin(), (vec).end()
#define rall(vec) (vec).rbegin(), (vec).rend()
#define piiii pair<pair<int, int>, pair<int, int>>

void solve() {
    string s;
    cin>>s;
    vector<int> pref(2019, 0);
    pref[0]=0;
    int n=s.size();
    ll ans=0;
    for(int i=0;i<n;i++){
        vector<int> pref2(2019, 0);
        for(int j=0;j<2019;j++){
            if((j*10+s[i]-'0')%2019==0){
                ans+=pref[j];
            }
        }
        for(int j=0;j<2019;j++){
            pref2[(j*10+s[i]-'0')%2019]+=pref[j];
        }
        pref2[s[i]-'0']++;
        swap(pref2, pref);
    }
    cout<<ans;
}

void testcases(int n) {
    n = 1 - n;
    if (!n) cin >> n;
    for (int i = 0; i < n; i++) {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "r", stdin);
    //f=fopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w");
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w", stdout);

    unsigned int beg_time = clock();
    testcases(0);
    // 0 - no t, 1 - with t

    unsigned int end_time = clock();
    //cout << endl << endl << end_time - beg_time;
    return 0;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
using namespace std;
#define     bolt     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     F        first
#define     S        second
#define     pb       push_back
#define     ll       long long
#define     inf      3e5
#define     pi       3.141592
int main()
{
   ll n;
   cin>>n;
   map <ll,ll> mp;
   for (ll i=0;i<n-1;i++)
   {
      ll a;
      cin>>a;
      mp[a]++;
   }
   for (ll i=1;i<=n;i++)
   {
      cout<<mp[i]<<endl;
   }
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }

  z->parent = y;

  if(y==NIL){
    root =z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }

}

void inorder(Node u){
  
  if(u->left!=NIL){
    inorder(u->left);
  }

  printf(" %d", u->key);

  if(u->right!=NIL){
    inorder(u->right);
  }
  
}
void preorder(Node u){

  printf(" %d", u->key);
  
  if(u->left!=NIL){
    preorder(u->left);
  }

  if(u->right!=NIL){
    preorder(u->right);
  }
  
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25172
#include <bits/stdc++.h>
#pragma gcc optimize("Ofast")
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int h, w, c, ans = 0;

const int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int grid[8][8];

template<class T>
struct Queue {
    T qs[64];
    int head = 0, tail = 0;
    const inline bool empty() const { return head == tail; }
    T front() { return qs[head]; }
    inline void push(T p) { qs[tail++] = p; }
    inline void pop() { head++; }
};

void dfs(int dep) {
	int gridbackup[8][8];
	int mask[8][8];

	/*rep(i, 0, h) {
		rep(j, 0, 5 - dep) printf(" ");
		rep(j, 0, w) printf("%d ", grid[i][j]);
		printf("\n");
	}*/
	rep(i, 0, h) rep(j, 0, w) gridbackup[i][j] = grid[i][j], mask[i][j] = 0;
	
	// bfs generate mask
	mask[0][0] = 1;
	Queue<pair<int, int>> q;
	q.push({0, 0});
	while (!q.empty()) {
		int i, j; tie(i, j) = q.front(); q.pop();
		for (int d = 0; d < 4; d++) {
			int ni = i + dir[d][0], nj = j + dir[d][1];
			if (ni >= 0 && ni < h && nj >= 0 && nj < w && !mask[ni][nj] && grid[ni][nj] == grid[0][0]) {
				mask[ni][nj] = 1;
				q.push({ni, nj});
			} 
		}
	}

	if (dep == 0) {
		int cnt = 0;
		rep(i, 0, h) rep(j, 0, w) if (mask[i][j] == 1 && grid[0][0] == c) cnt++;
		
		/*if (cnt > ans) {
			rep(i, 0, h) {
				rep(j, 0, w) printf("%d(%d) ", grid[i][j], mask[i][j]);
				printf("\n");
			}
		}*/
		ans = max(ans, cnt);
		return;
	}

	for (int cc = 1; cc <= 6; cc++) {
	    if (cc == grid[0][0]) continue;
		rep(i, 0, h) rep(j, 0, w) grid[i][j] = mask[i][j] == 1 ? cc : grid[i][j];
		dfs(dep - 1);

		// restore
		rep(i, 0, h) rep(j, 0, w) grid[i][j] = gridbackup[i][j];
	}
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
	for (;;) {
		cin >> h >> w >> c;
		if (!h && !w && !c) break;

		rep(i, 0, h) rep(j, 0, w) cin >> grid[i][j];

        ans = 0;
        dfs(5);
		cout << ans << endl;
	}
}




Measured memory_bytes: 3128
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int res = 0;
	for (char c : s)
		if (c == '2')
			res++;
	cout << res << endl;
}

Measured memory_bytes: 256
f i = do
  ln_i <- getLine
  let x:y:[] = map (read::String->Int) (words ln_i)
  if (x == 0 && y == 0)
    then return () else do
      putStrLn $ show (min x y) ++ " " ++ show (max x y)
      f $ i+1
main = f 1


Measured memory_bytes: 4140
def impossible?(n, k, x)
  until n == 0
    n -= 1
    k -= x
    break if k < 0
    x >>= 1
    break if x == 0
  end
  k < 0
end
n, k = gets.split.map(&:to_i)
p ((1..k).bsearch {|x| impossible?(n, k, x) } || k + 1) - 1


Measured memory_bytes: 6868
local mod = 1000000007
local function badd(x, y) return (x + y) % mod end
local function bmul(x, y) return (x * y) % mod end
local n = io.read("*n")
local sum = 0
local ret = 0
for i = 1, n do
  local a = io.read("*n")
  ret = badd(ret, bmul(a, sum))
  sum = badd(sum, a)
end
print(ret)

Measured memory_bytes: 2796
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <vector>
using namespace std;

#define abs(N) ((N>0)?N:-1*N)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

void vdump(vector<int> v){
  for (auto itr = v.begin(); itr != v.end(); ++itr)
  {
    print(*itr);
  }
  println("");
}

int calc(vector<int> v){
  int p = 1;
  int sum = 0;
  for (auto itr = v.end(); itr != v.begin(); --itr)
  {
    sum += *(itr-1) * p;
    p *= -2;
  }
  return sum;
}

int main(int argc, char const *argv[])
{
  long N,p=1,ap,e=0,diff=0,cur;
  vector<int> v;
  cin >> N;

  if(N==0){
    println(0);
    return 0;
  }
  cur = 0;
  diff = N-cur;
  while(N!=cur)
  {
    int d;
    diff = N - cur;
    d = (abs(diff)%abs(p*2)==0) ? 0: 1;
    // printf("%d,%d,%d,%d,%d\n",N,cur,diff,p,d);
    cur += d*p;
    v.insert(v.begin(),d);
    // vdump(v);
    p *= -2;
    e++;
  }
  vdump(v);

  return 0;
}


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

namespace agc011_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(x);
            long[] goukei = new long[n];
            long sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum += x[i];
                goukei[i] = sum;
            }
            Array.Reverse(x);
            Array.Reverse(goukei);
            int ret = 1;
            bool flag = true;
            for (int i = 1; i < n && flag; i++)
            {
                if (x[i - 1] > goukei[i] * 2)
                {
                    flag = false;
                }
                else
                {
                    ret++;
                }
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 28892
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int a,sum=0;

		a = sc.nextInt();
		int[] b = new int[a];
		
		for(int i=0;i<a;i++)
		{
			b[i] = sc.nextInt();
		}
		int max = b[0];
		for(int i=0;i<a;i++)
		{
			if(b[i]>=max)
				sum++;
			if(b[i]>max)
				max=b[i];
		}
		
		System.out.println(sum);

	}
}

Measured memory_bytes: 23380
#include <iostream>
#include <stdio.h>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define N 4
#define M 2
typedef pair<int,vector<int> > P;
typedef pair<P, int> PP;
vector<int> f;
map<vector<int> , int> m;

int find_zero(vector<int> v) {
    for(int i=0;i<v.size();i++) {
        if(v[i] == 0) return i;
    }
    printf("error!");
}

int di[]={-1,1,4,-4};
void preset_map() {
    queue<PP> Q;
    set<vector<int> > s;
    vector<int> ans_f;
    for(int i=0;i<N*M;i++) ans_f.push_back(i);
    
    Q.push(PP(P(0,ans_f),0));
    while(Q.size()) {
         PP pp = Q.front(); Q.pop();
         vector<int> v = pp.first.second;
         int cost = pp.first.first;
         int zerop = pp.second;
       if(s.find(v) != s.end()) {
           continue;
       }
       //for(int i=0;i<8;i++) {
       //    printf("%d ", v[i]);
       //}
       //printf("\n cost=%d pat=%u-----------\n", cost, s.size());
       m.insert(pair<vector<int>, int>(v, cost));
       s.insert(v);

       int di2[8][4]= {{-1,-1,1,4},{-1,0,2,5},{-1,1,3,6},{-1,-1,2,7},
           {0,5,-1,-1},{1,4,6,-1},{2,5,7,-1},{3,6,-1,-1}};
       for(int i=0;i<4;i++) {
           vector<int> buf_f = v;

           int pos = di2[zerop][i];
           //if((pos == 4 && zerop == 3) ||
           //   (pos == 3 && zerop == 4)) {
           //    continue;
           //}
           if(0 <= pos && pos <= 7) {
               swap(buf_f[zerop], buf_f[pos]);
               Q.push(PP(P(cost+1,buf_f), pos));
           }
       }
    }
}

main() {
    int d;
    preset_map();
    while(true) {
        f.clear();
        cin>>d;
        if(cin.eof()) break;
        f.push_back(d);
        for(int i=1;i<M*N;i++) {
            cin>>d;
            f.push_back(d);
        }
        cout << m[f] << endl;
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

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

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int main(){
    ull memo[10][1001];
    REP(i, 10){
        REP(j, 1001){
            memo[i][j] = 0;
        }
    }
    memo[0][0] = 1;

    REP(i, 101){// iをいれたい
        for(int j=9;j>=1;j--){
            REP(k, 1001){
                if(k-i >= 0){
                    memo[j][k] += memo[j-1][k-i];
                }
            }
        }
    }

    int N, S;
    while(std::cin >> N >> S, N){
        std::cout << memo[N][S] << std::endl;
    }
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main() {
  	string s,t;
  	cin >> s;
  	cin >> t;
  bool flag = false;
  	for(int i=0;i<s.size();i++){
      if(s[i]==t[i]){
        flag = true;
      }else{
        flag = false;
        break;
    }
    }
  if(flag == true){
  	 cout << "Yes" << endl;
  }else if(flag == false){
  cout << "No" << endl;
  }
  
	return 0;
}


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

#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int main(){
    string s;
    int n, k;

    cin >> s >> k;
    n = s.size();

    //dp[i][j][l] :上からi桁めでj個０でない桁がある個数(l=0 ちょうどn l=1 nより小さい)
    ll dp[120][5][2] = {};
    dp[0][0][0] = 1;

    rep(i, n){
        rep(j, k+1){
            //前の桁の引継ぎ
            dp[i+1][j][1] += dp[i][j][1];
            //既にnより小さいなら１〜９まで全て選べる
            dp[i+1][j+1][1] += dp[i][j][1]*9;
            //制約ちょうどの場合
            if(s[i] != '0'){
                //現在の桁を０にすればそのまま
                dp[i+1][j][1] += dp[i][j][0];
                //i桁の数-1個使うなら次の桁からnより小さくできる
                dp[i+1][j+1][1] += dp[i][j][0]*(s[i]-'1');
                //ギリギリで攻めて行く
                dp[i+1][j+1][0] += dp[i][j][0];
            } 
            else {
                dp[i+1][j][0] += dp[i][j][0];
            }
        }
    }

    cout << dp[n][k][0] + dp[n][k][1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using namespace std;
int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}
int main(){
    ll a,b;
    cin>>a>>b;
    ll x=gcd(a,b);
    set<ll> st;
    ll ans=0;
    for(ll i=1;i<=sqrt(x);i++){
        if(x%i==0){
            st.insert(i);
            st.insert(x/i);
        }
    }
    vector<bool> s(st.size(),true);
     for(auto itr = st.begin(); itr != st.end(); ++itr) {
         if(s[distance(st.begin(),itr)])
         ans++;
         else continue;
         for(auto itr2 = next(itr,1);itr2!=st.end();itr2++){
             if(s[distance(st.begin(),itr)]&&gcd(*itr,*itr2)!=1)
             s[distance(st.begin(),itr2)]=false;
         }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

 long long modpow(long long n, long long k,long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
    string s;cin >> s;
    cout << s;
    if(s[s.size()-1]=='s') cout << "es";
    else cout << 's';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    solve();
    return 0;
}

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

int main(void){

	int n;
	double x1,y1,x2,y2,x3,y3,x4,y4;
	cin>>n;
	for (int i=0; i<n; i++){
		cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
		if(abs((y1-y2)*(x3-x4)-(y3-y4)*(x1-x2))<1e-10) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}

	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
    char a[500],stack[500],t;
    int top=0;
    cin>>a;
    for(int i=0;i<strlen(a);i++)
    {
        if(a[i]=='F'&&top==0)   continue;
        else if(a[i]=='C')
        {      
        stack[top++]=a[i];
        }
        else
        { 
            if(a[i]=='F')
            {
            t=stack[--top];
            break;
            }
        }
    }
    if(t=='C')
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    
}

Measured memory_bytes: 256
while True:
   H, W = map(int, raw_input().split())
 
   if (H == 0 and W == 0): 
    break
   for i in range(H):
    if(i==0):
     print "#"*W
    elif(i==H-1):
     print "#"*W
    else:
     print ("#"+"."*(W-2)+"#")

   print ""

Measured memory_bytes: 6436
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    int sum = 0;
    long long ans = 0;
    map<int, int> cnt;
    ++ cnt[0];
    for(int i=0; i<n; ++i){
        sum += a[i];
        sum %= m;
        ans += cnt[sum];
        ++ cnt[sum];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <climits>
#include <cmath>
using namespace std;

bool f[101][10];
int p[101][11];

int main(){
	int n;
	int max = INT_MIN;
	cin >> n;
	for(int i=0; i< n; i++){
		for(int j=0; j< 10; j++){
			cin >> f[i][j];
		}
	}
	for(int i=0; i< n; i++){
		for(int j=0; j< 11; j++){
			cin >> p[i][j];
		}
	}
	for(int i=1; i< 1 << 10; i++){
		int tmp = 0;
		for(int k=0; k< n; k++){
			int count = 0;
			for(int j=0; j< 10; j++){
				if(i & 1 << j && f[k][j]){
					count++;
				}
			}
			tmp += p[k][count];
		}
		if(tmp > max) max = tmp;
	}
	cout << max;
	return 0;
}


Measured memory_bytes: 256
//Some Sums

#include<bits/stdc++.h>
using namespace std;

int i_sum (int i){
    int n=0;
    while(i>0){
    n += i%10;
    i /= 10;
    }
    return n;
}

int main (){
    int N, A, B,Ans=0;
    cin >> N >> A >> B;
    for(int i = 1;i<=N;i++){
        if(i_sum(i)>=A && i_sum(i)<=B)Ans+=i;
    }
    cout << Ans << endl;
    return 0;
}

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

int findSumOfDigits(int n){
  
  int sum = 0;  
  while(n > 0){
    
    sum += n % 10;    
    n /= 10;
    
  }  
  
  return sum;
  
}

int main(){
  
  int n,a,b;
  cin >> n >> a >> b;
  
  int total = 0;
  for(int i = 1; i <= n; i++){
    
    int sum = findSumOfDigits(i);       
    if(sum >= a && sum <= b) total += i;
    
  }
  
  cout << total << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ESP (1e-10)
using namespace std;

typedef struct Point {
	double x; 
	double y;

	Point() { }

	Point(double x, double y) :x(x), y(y) { }

	Point operator+(Point& p) {
		return Point(x + p.x, y + p.y);
	}

	Point operator-(Point& p) {
		return Point(x - p.x, y - p.y);
	}
};

typedef Point Vector;

 struct Line {
	Point p1, p2;
	Line() {}
	Line(const Point& a,const Point& b) : p1(a),p2(b) { }
};

 typedef Line Segment;

double abs(Point p1, Point p2) {
	double norm = (p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y);
	return sqrt(norm);
}

double product(Vector v1, Vector v2) {
	return v1.x*v2.x + v1.y*v2.y;
}

double cross(Vector p1, Vector p2) {
	return p1.x*p2.y - p1.y*p2.x;
}

int ccw(Point p0, Point p1, Point p2) {
	Vector v0 = p1 - p0;
	Vector v1 = p2 - p0;
	if (cross(v0, v1) > ESP) return 1;   //p0,p1,p2??????????¨???????
	if (cross(v0, v1) < -ESP) return -1;   //p0,p1,p2???????¨???????
	if (product(v0, v1) < -ESP) return 2;  //p2,p0,p1????????§????????´??????
	if (abs(p0, p1) < abs(p0, p2)) return -2;  //p0,p1,p2????????§????????´??????
	return 0;   //p2?????????(p0,p1)???
}

bool intersect(Point p0, Point p1, Point p2, Point p3) {
	return (ccw(p0, p1, p2)*ccw(p0, p1, p3) <= 0&&ccw(p2,p3,p0)*ccw(p2,p3,p1)<=0);
	//?????????????????????????????¶
}

bool intersect(Segment s1, Segment s2) {
	return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

double DistanceLP(Line l, Point p) {
	return abs(cross(l.p2 - l.p1, p - l.p1)/abs(l.p1,l.p2));
}

double DistanceSP(Segment s, Point p) {
	if (product(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p, s.p1);
	if (product(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p, s.p2);
	return DistanceLP(s, p);
}

double DistanceSS(Segment s1, Segment s2) {
	if (intersect(s1, s2)) return 0.0;
	return min(min(DistanceSP(s1, s2.p1), DistanceSP(s1,s2.p2)), min(DistanceSP(s2, s1.p1), DistanceSP(s2, s1.p2)));
}

int main() {
	Segment s0,s1;
	int q; 
	cin >> q;
	for (int i = 0;i < q;i++) {
		cin >> s0.p1.x; cin >> s0.p1.y;
		cin >> s0.p2.x; cin >> s0.p2.y;
		cin >> s1.p1.x; cin >> s1.p1.y;
		cin >> s1.p2.x; cin >> s1.p2.y;
		cout << intersect(s0, s1) << endl;
	}
}

Measured memory_bytes: 3196
# -*- coding: utf-8 -*-
from functools import lru_cache

import sys
# sys.setrecursionlimit(10)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


# @mt
def slv(N, A, B, C, D):
    @lru_cache(maxsize=None)
    def f(n):
        if n == 1:
            return D
        if n == 0:
            return 0
        ans = n*D

        i = (n // 2) * 2
        ans = min(ans, f(i//2) + A + D*abs(n-i))
        i = -(-n // 2) * 2
        ans = min(ans, f(i//2) + A + D*abs(n-i))

        i = (n // 3) * 3
        ans = min(ans, f(i//3) + B + D*abs(n-i))
        i = -(-n // 3) * 3
        ans = min(ans, f(i//3) + B + D*abs(n-i))

        i = (n // 5) * 5
        ans = min(ans, f(i//5) + C + D*abs(n-i))
        i = -(-n // 5) * 5
        ans = min(ans, f(i//5) + C + D*abs(n-i))
        return ans

    return f(N)


def main():
    T = read_int()
    for _ in range(T):
        N, A, B, C ,D = read_int_n()
        print(slv(N, A, B, C, D))


if __name__ == '__main__':
    main()


Measured memory_bytes: 111148
N = int(input())
S = []

for _ in range(N):
    S.append(input())

    
ans = sorted(list(set(S[0]))) #unique

for a in ans:
    num = 9999999999
    for s in S:
        if num > s.count(a):
            num = s.count(a)
    print(a * num, end="");

Measured memory_bytes: 3060
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int r = sc.nextInt();
        if(r-l>=2019){System.out.println(0);}
        else{l%=2019;
        r%=2019;
        if(l<r){int ans = 2019;
                for(int i=l;i<r;i++){for(int j=i+1;j<=r;j++)
                {ans = Math.min(ans,(i*j)%2019);}
                                    }
                System.out.println(ans);}
		else{System.out.println(0);}
            }
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;

int main(){
    int a, b;
    cin >>b >> a;
    ll ans = a;
    if (b == 1){
        cout << a << endl;
    }
    else{
        while (b > 1){
            ans *= a-1;
            b--;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const S = arg[1].split("");
    
    if(N % 2 !== 0) {
        console.log("No");
        return;
    }
    
    const front = S.slice(0, Math.floor(N / 2)).join("");
    const back  = S.slice(-Math.floor(N / 2)).join("");
    
    console.log(front === back ? "Yes" : "No");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
from bisect import bisect_left
N,K = map(int,input().split())
X = []; Y = []; info = []
for i in range(N):
    x,y = map(int,input().split())
    X.append(x); Y.append(y); info.append([x,y])
X.sort(); Y.sort()

acc = [[0]*(N+1) for i in range(N+1)]
for x, y in info:
    j = bisect_left(X,x)
    i = bisect_left(Y,y)
    acc[i+1][j+1] += 1

for i in range(N+1):
    for j in range(1,N):
        acc[i][j+1] += acc[i][j]

for j in range(N+1):
    for i in range(1,N):
        acc[i+1][j] += acc[i][j]

ans = float('inf')
for t in range(N-1):
    for b in range(t+1,N):
        for l in range(N-1):
            for r in range(l+1,N):
                num = acc[b+1][r+1] - acc[b+1][l] - acc[t][r+1] + acc[t][l]
                if num < K: continue
                S = (Y[b] - Y[t]) * (X[r] - X[l])
                if S < ans:
                    ans = S

print(ans)

def debug():
    for line in acc:
        print(line)

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

int main(){

    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
        
    int ans=0;
    int dp[n+2];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    int val = INT_MAX;
    for(int i=2;i<n;i++){
        val=INT_MAX;
        for(int j = 1;j<=k;j++){
        
            if((i-j)<0)
                break;
            val=min(dp[i-j]+abs(a[i-j]-a[i]),val);
        }
        dp[i]=val;
    }
    
    cout<<dp[n-1];
}   

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

string s;

int main()
{
	cin >> s;
	bool a = s.size() % 2 == 0;
	bool b = s[0] == s[s.size() - 1];
	if(a ^ b)
	{
		cout << "Second" << endl;
	}
	else
	{
		cout << "First" << endl;
	}
	return 0;
}


Measured memory_bytes: 512
def main():
    n = int(input())
    count = 0
    for i in range(n):
        x, y = map(int, input().split())
        if x == y:
            count += 1
        else:
            count = 0

        if count == 3:
            print('Yes')
            return
    print('No')
if __name__ == "__main__":
    main()


Measured memory_bytes: 9168
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	int N;
	cin >> N;
	vl A(N);
	vl Asum(N+1);
	Asum[0] = 0;
	rep(i, N) {
		cin >> A[i];
		Asum[i + 1] = Asum[i] + A[i];
	}
	int k;
	rep(i, N) {
		if (Asum[i + 1] >= Asum[N] / 2) {
			k = i;
			break;
		}
	}
	ll B1 = Asum[k];
	ll B2 = Asum[k + 1];
	ll ans1 = abs(Asum[N] - 2 * B1);
	ll ans2 = abs(Asum[N] - 2 * B2);
	ll ans = min(ans1, ans2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
def insertion_sort(a, n, g)
	for i in g..n-1
		v = a[i]
		j = i - g
		while j >= 0 && a[j] > v
			a[j + g] = a[j]
			j = j - g
			$cnt+=1
		end
		a[j + g] = v
	end
end

def shell_sort(a, n)
	$cnt = 0

	h = Array.new
	h[0] = 1
	i = 1
	while i<100 && h[i-1]<n
		h[i] = 3 * h[i-1] + 1
		if h[i] > n
			break
		end
		i+=1
	end

	m = i
	g = h[0..i-1].reverse
	for i in 0..m-1
		insertion_sort(a, n, g[i])
	end
	
	puts m, g.join(" "),$cnt,a
end

n = gets.chomp.to_i
a = Array.new
n.times { |i|
	a[i] = gets.chomp.to_i
}

shell_sort(a, n)

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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define RFOR(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[ ";
    for (auto a : v) os << a << " ";
    os << "]";
    return os;
}

int main() {
    char c;
    cin >> c;
    cout << (isupper(c) ? "A" : "a") << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	int c = 0;
	vector<int> v;

	for (int i = 0; i < S.size(); i++) {
		char ch = S[i];
		v.push_back(ch);
		if (v.size() > 1) {
			if (v[v.size() - 1] != v[v.size() - 2]) {
				c += 2;
				v.pop_back();
				v.pop_back();
			}
		}
	}

	cout << c << endl;
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<62);

int main() {
    cin>>A>>B;
    cout<<A * B<<endl;
}

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

int main() {
  int n;
  cin >> n;
  
  int ans = 0;
  for(int i=1; i<=n-1; i++) {
    ans += (n-1)/i;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;
int main()
{
    ll a, b, c, d, e, f, g;
    cin >> a >> b >> c >> d >> e >> f >> g;
    ll ans1 = 0, ans2 = 0, tmp = 0;
    ans1 += b;
    tmp = min({1ll, a, d, e});
    ans1 += tmp * 3;
    ans1 += ((d - tmp) / 2) * 2;
    ans1 += ((e - tmp) / 2) * 2;
    ans1 += ((a - tmp) / 2) * 2;

    ans2 += b;
    tmp = 0;
    ans2 += tmp * 3;
    ans2 += ((d - tmp) / 2) * 2;
    ans2 += ((e - tmp) / 2) * 2;
    ans2 += ((a - tmp) / 2) * 2;

    cout << max(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 256
# AOJ 1172: Chebyshev's Theorem
# Python3 2018.7.14 bal4u

MAX = 250000
SQRT = 500     # sqrt(MAX)

prime = [True]*MAX
def sieve():
	for i in range(2, MAX, 2): prime[i] = False
	for i in range(3, SQRT, 2):
		if prime[i]:
			for j in range(i*i, MAX, i): prime[j] = False
			
sieve()
while True:
	n = int(input())
	if n == 0: break
	ans, m = 0, n << 1
	if n == 1: ans += 1         # for 2
	i = n + 1
	if (i&1) == 0: i += 1       # for odd num only
	while i <= m:
		if prime[i]: ans += 1
		i += 2
	print(ans)



Measured memory_bytes: 7300
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int N; cin >> N;
    vll A(N);
    rep(i,N) cin >> A[i];
    ll sum = 0;
    rep(i,N) sum += A[i];
    ll x = sum - N*(N-1);
    ll l = 0, r = inf_l;
    while (r - l > 1) {
        ll mid = (r+l) / 2;
        auto f = [&](ll y) {
            sum = 0;
            rep(i,A.size()) {
                sum += max((A[i]+x-y+N)/(N+1),(ll)0);
            }
            return sum <= x;
        };
        if (f(mid)) r = mid;
        else l = mid;
    }
    ll ans = 0;
    for (ll i = x - N; i <= x; i++) {
        sum = 0;
        rep(j,A.size()) {
            sum += max((A[j]+i-r+N)/(N+1),(ll)0);
        }
        if (sum == i) {
            ans += i;
            rep(j,A.size()) {
                A[j] = A[j] + i - max((A[j]+i-r+N)/(N+1),(ll)0)*(N+1);
            }
            break;
        }
    }
    sort(all(A));
    while (true) {
        if (A.back() < N) break;
        ans++;
        rep(i,A.size()-1) A[i]++;
        A.back() -= N;
        sort(all(A));
    }
    cout << ans << endl;
}

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

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long ans = -pow(10, 18) - 100;
  
  ans = max(ans, max(a*c, max(a*d, max(b*c, b*d))));
  
  cout << ans << endl;
}

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

#define INF 2e9+1

using namespace std;

int main(void){

    int N, L;
    int min = INF, index, ans = 0;

    cin >> N >> L;

    for(int i = 1;i <= N;i++){
        if(abs(L+i-1) < min){
            min = abs(L+i-1);
            index = i;
        }
    }

    for(int i = 1;i <= N;i++){
        if(index != i) ans += L+i-1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;

int main () {
  string RGB = "RGB";
  long long n;
  string s;

  cin >> n >> s;

  vector<vector<long long>> RGBS(3, vector<long long>(n));

  vector<long long> RGBcount(3);

  for(long long i = 0; i < n; i++) {
    for(long long j = 0; j < 3; j++){
      RGBS[j][i] = RGBcount[j];
      if(s[i] == RGB[j]) RGBcount[j]++;
    }
  }

  long long count = 0;
  for(long long i = 0; i < (n-2); i++) {
    for(long long j = (i+1); j < (n-1); j++) {
      long long diff = j-i;
      long long exclude = j + diff;
      for(long long k = 0; k < 3; k++){
        long long second = (k+1)%3;
        long long third = (k+2)%3;
        if((s[i] == RGB[k] && s[j] == RGB[second]) || (s[i] == RGB[second] && s[j] == RGB[k])) {
          count += (RGBcount[third] - RGBS[third][j+1]) - (((j+1) <= exclude && exclude < n && s[exclude] == RGB[third]) ? 1 : 0);
        }
      }
    }
  }

  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
 
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() {
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll n,m;
    cin>>n>>m;
    ll h[n+1];
    vector<ll> adj[n+1];
    ll good[n+1];

    for (int i = 1; i<=n; ++i)
    {
        cin>>h[i];
        good[i]=-1;
    }

    for (int i = 0; i < m; ++i)
    {
        ll a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    for (int i = 1; i<=n; ++i)
    {
        queue<ll> q;
        q.push(i);
        if(good[i]==-1){
            while(!q.empty()){
                ll u = q.front();
                ll eleu = h[u];
                q.pop();
                if(good[u]==-1){
                    for (auto i = adj[u].begin(); i != adj[u].end(); ++i)
                    {
                        ll elev = h[*i];
                        if(good[*i]==1){
                            good[u]=0;
                            break;
                        }
                        else{
                            if(eleu<=elev){
                                good[u]=0;
                                break;
                            }
                            else{
                                q.push(*i);
                            }
                        }
                    }
                    if(good[u]==-1){
                        good[u]=1;
                    }
                }
            }
        }
    }

    ll ans=0;
    for (int i = 1; i <=n; ++i)
    {
        if(good[i]==1){
            ans++;
        }
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 11016
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cctype>
#include <queue>
#include <complex>
#include <functional>
#include <sstream>
#include <tuple>

using namespace std;

int main()
{
#ifdef IMPETUS
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int n, m, q;
    cin >> n >> m >> q;
    vector<pair<int, int>> t(2 * m);
    vector<pair<pair<int, int>, int>> z(q);
    for (int i = 0; i < m; i++)
    {
    	int l, r;
    	cin >> l >> r;
    	t[i * 2] = make_pair(l, -1);
    	t[i * 2 + 1] = make_pair(r, l);
    }
    for (int i = 0; i < q; i++)
    {
    	cin >> z[i].first.first >> z[i].first.second;
    	z[i].second = i;
    }
    vector<int> result(q);
    sort(t.begin(), t.end());
    sort(z.begin(), z.end());
    int gtc = 0, zc = 0;
    for (int i = 1; i <= n; i++)
    {
    	int cnt = 0;
    	while (gtc < 2 * m && t[gtc].first < i)
    		gtc++;
    	int ltc = gtc;
    	for (int j = i; j <= n; j++)
    	{
	    	while (ltc < 2 * m && t[ltc].first == j)
	    	{
	    		if (t[ltc].second >= i)
	    			cnt++;
	    		ltc++;
	    	}
	    	while (zc < q && z[zc].first.first == i && z[zc].first.second == j)
	    		result[z[zc++].second] = cnt;
    	}
    }
    for (int i = 0; i < q; i++)
    	cout << result[i] << endl;
    return 0;
}

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

using namespace std;


int main()
{
    string s;
    while(cin >> s)
    {
        int len=s.size();
        int flag=1;
        int Tx,t;
        for(int i=0; i<len-1; i++)
        {
            if(s[i]!=s[i+1])
            {
                t=max(i+1,len-i-1);
                if(flag)
                {
                    Tx=t;
                    flag=0;
                }
                Tx=min(t,Tx);
            }
        }
        if(flag)
            printf("%d\n",len);
        else
            printf("%d\n",Tx);
    }
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n,a,b;
  cin>>n;
  if(n==2){
    cin>>a>>b;
    cout<<a+b<<'\n';
  }
  else cout<<"Hello World"<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
using namespace std;
int n,m,cnt;
char s[15][15];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++) {
		scanf("%s",s[i]);
		for(int j=0;j<m;j++){
			if(s[i][j]=='#') cnt++;
		}
	}
	if(cnt==n+m-1) printf("Possible\n");
	else printf("Impossible\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int INF = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

int main() {
    u32 n, m;
    cin >> n >> m;
    vector<string> v1(n), v2(m);
    for (int i = 0; i < n; ++i) {
        cin >> v1[i];
    }
    for (int j = 0; j < m; ++j) {
        cin >> v2[j];
    }
    for (u32 i = 0; i < n-m+1; ++i) {
        for (u32 j = 0; j < n-m+1; ++j) {
            int a = 1;
            for (int k = 0; k < m; ++k) {
                if(v1[i+k].substr(j, m) != v2[k]){
                    a = 0;
                    break;
                }
            }
            if(a){
                cout << "Yes" << "\n";
                return 0;
            }
        }
    }
    cout << "No" << "\n";
    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve
  :: Int
  -> Int
  -> Int
  -> V.Vector (VU.Vector Int)
  -> Int
  -> VU.Vector (Int, Int)
  -> VU.Vector Int
solve h w d aij q lrs = VU.map
  ( \(l, r) ->
    let m        = l `mod` d
        cylinder = cylinders V.! m
    in  cylinder VU.! ((r - m) `div` d) - cylinder VU.! ((l - m) `div` d)
  )
  lrs
 where
  cylinders :: V.Vector (VU.Vector Int)
  cylinders = V.fromList
    [ VU.scanl' (+) 0 $ VU.fromList $ calcs [i, i + d .. h * w - 1]
    | i <- [0 .. d - 1]
    ]

  calcs :: [Int] -> [Int]
  calcs = go []
   where
    go !acc (x:y:zs) =
      let (x1, x2) = coords VU.! x
          (y1, y2) = coords VU.! y
      in  go (abs (y1 - x1) + abs (y2 - x2) : acc) (y : zs)
    go !acc _ = reverse acc

  coords :: VU.Vector (Int, Int)
  coords = V.ifoldl'
    ( \(!vec) (!i) (!aj) -> VU.accumulate
      (\_ (!j) -> (i, j))
      vec
      (VU.map (\(x, y) -> (y, x)) $ VU.indexed aj)
    )
    (VU.replicate (h * w) (-1, -1))
    aij

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (h, w, d) <-
    (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2))
    .   VU.unfoldrN 3 readInt
    <$> B.getLine
  aij <-
    V.replicateM h $ VU.map (\x -> x - 1) . VU.unfoldrN w readInt <$> B.getLine
  q   <- (\vec -> vec VU.! 0) . VU.unfoldrN 1 readInt <$> B.getLine
  lrs <-
    VU.replicateM q
    $   (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
  VU.mapM_ print $ solve h w d aij q lrs


Measured memory_bytes: 47484
#include <iostream>
#include <cstdio>
#define N 4005
using namespace std;

int n, a[N], d[2][N][N];

int abs(int p) {return p > 0 ? p : -p;}

int f(bool p, int q, int r) {
	if (q == n || r == n) return abs(a[q] - a[r]);
	if (d[p][q][r]) return d[p][q][r];
	if (p == 0) return d[p][q][r] = max(f(0, q + 1, r), f(1, q, q + 1));
	else return d[p][q][r] = min(f(0, r + 1, r), f(1, q, r + 1));
}

int main()
{
	int i;
	cin >> n >> a[0] >> a[1];
	n++;
	for (i = 2; i <= n; i++) scanf("%d", &a[i]);
    cout << f(0, 0, 1) << endl;
    return 0;
}

Measured memory_bytes: 64384
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384

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

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

int main(int argc, const char * argv[]) {

    int H, W;
    int CH, CW;
    int DH, DW;
    char S[1000][1000];
    int COST[1000][1000];

    cin >> H >> W;
    cin >> CH >> CW;
    cin >> DH >> DW;

    CH--;CW--;DH--;DW--;

    for(int h=0; h<H; h++){
        string s;
        cin >> s;

        for(int w=0; w<W; w++){
            S[h][w] = s[w];
            COST[h][w] = -1;
        }
    }


    deque<P> que;
    que.push_front(P(CH, CW));
    COST[CH][CW] = 0;

    while(que.size()){

        P p = que.front();
        que.pop_front();

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

            int ny = p.first + dy[i];
            int nx = p.second + dx[i];

            if(ny<0 || ny >= H || nx<0 || nx >= W) continue;
            if(COST[ny][nx] <= COST[p.first][p.second] && COST[ny][nx] > -1) continue;
            if(S[ny][nx] == '.'){
                COST[ny][nx] = COST[p.first][p.second];
                que.push_front(P(ny, nx));
            }
        }

        for(int i=4; i<24; i++){

            int ny = p.first + dy[i];
            int nx = p.second + dx[i];

            if(ny<0 || ny >= H || nx<0 || nx >= W) continue;
            if(COST[ny][nx] > -1) continue;

            if(S[ny][nx] == '.'){
                COST[ny][nx] = COST[p.first][p.second] + 1;
                que.push_back(P(ny, nx));
            }
        }
    }

    cout << COST[DH][DW] << endl;

    return 0;
}

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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {
var inputArray = retreiveLongArray();
			var inputCount = 6;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var AddWater1 = (int)inputArray[0]*100;
			var AddWater2 = (int)inputArray[1]*100;
			var AddSugar1 = (int)inputArray[2];
			var AddSugar2 = (int)inputArray[3];
			var MaxSugar = (int)inputArray[4];
			var MaxMass = (int)inputArray[5];

			var limitCondense = (MaxSugar) / (double)(100 + MaxSugar);

			var massWater1 = 0;
			var waterList = new List<int>();

			//取りうる水の量を調べる
			while (true) {
				var massWater2 = 0;
				if (massWater1> MaxMass) {
					break;
				}
				while (true) {
					var mass = massWater1 + massWater2;
					if (mass> MaxMass) {
						break;
					}
					waterList.Add(mass);
					massWater2 += AddWater2;
				}
				massWater1 += AddWater1;
			}

			var massSugar1 = 0;
			var sugarList = new List<int>();

			//取りうる砂糖の量を調べる
			while (true) {
				var massSugar2 = 0;
				if (massSugar1 > MaxMass/2) {
					break;
				}
				while (true) {
					var mass = massSugar1 + massSugar2;
					if (mass > MaxMass/2) {
						break;
					}
					sugarList.Add(mass);
					massSugar2 += AddSugar2;
				}
				massSugar1 += AddSugar1;
			}

			double maxCondense = 0;
			var itsMass = AddWater1;
			var itsSugar = 0;

			foreach (var water in waterList) {

				foreach (var sugar in sugarList) {
					var mass = water + sugar;

					var condense = sugar / (double)(mass);
					if (mass > MaxMass) {//質量オーバーの場合、対象外
						continue;
					}

					if (condense > limitCondense) {//濃度オーバーの場合、対象外
						continue;
					}
					if (condense > maxCondense) {
						maxCondense = condense;
						itsMass = mass;
						itsSugar = sugar;
					}

				}

			}


			//答えの出力
			var ans = itsMass + " " + itsSugar;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}

Measured memory_bytes: 13396